Skip to content

Add test that fixed parameters do not change #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/integration_tests/fitting/test_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,34 @@ def test_2D_non_vectorized(fit_engine, with_errors):
assert result.residual == pytest.approx(
mm(XY.reshape(-1, 2)) - y_calc_ref, abs=1e-2
)

@pytest.mark.parametrize("fit_engine", [None, AvailableMinimizers.LMFit, AvailableMinimizers.Bumps, AvailableMinimizers.DFO])
def test_fixed_parameter_does_not_change(fit_engine):
# WHEN
ref_sin = AbsSin(0.2, np.pi)
sp_sin = AbsSin(0.354, 3.05)

x = np.linspace(0, 5, 200)
y = ref_sin(x)

# Fix the offset, only phase should be optimized
sp_sin.offset.fixed = True
sp_sin.phase.fixed = False

fixed_offset_before = sp_sin.offset.value

# THEN
f = Fitter(sp_sin, sp_sin)
if fit_engine is not None:
try:
f.switch_minimizer(fit_engine)
except AttributeError:
pytest.skip(msg=f"{fit_engine} is not installed")

result = f.fit(x, y)

# EXPECT
# Offset should remain unchanged
assert sp_sin.offset.value == pytest.approx(fixed_offset_before, abs=1e-12)
# Phase should be optimized
assert sp_sin.phase.value != pytest.approx(ref_sin.phase.value, rel=1e-3)
Loading