Closed amycxh closed 3 days ago
@amycxh spot the typo!
self.setattr_analysis(
AnalysisDescription(
model=Sinusoid(),
x=self.phase,
y=[self.p],
fitter_args={"sigma": [self.p_err]},
results={"x0": self.phase},#, "a": nd.FloatChannel("a"), "y0": nd.FloatChannel("y0"), "phi": nd.FloatChannel("phi")},
log=True,
)
)
You're not passing the constrained model into the AnalysisDescription
!
FWIW I did write a test case for this, which passes (see below). I'm going to close this on the assumption it's just a typo, but do reopen if you think that's not the case
import numpy as np
from ionics_fits.normal import NormalFitter
from ionics_fits.models.sinusoid import Sinusoid
from ..common import is_close
def test_188(plot_failures):
"""Test that fixing the phase parameter of a Sinusoid model works correctly"""
model = Sinusoid()
model.parameters["phi"].fixed_to = 0.0
model.parameters["x0"].fixed_to = None
params = {
"phi": 0.,
"omega": 2 * np.pi,
"a": 1,
"y0": 0.5,
"x0": 0.25,
}
x = np.linspace(0, 1)
y = model(x, **params)
fit = NormalFitter(x=x, y=y, model=model)
for param in params.keys():
assert is_close(params[param], fit.values[param], 1e-3)
🤦♀️ whoops! Thank you 😅
The following should fix the parameter
phi
to 0 in the fit, and floatx0
instead, butphi
is not fixed.Details
I have a simple experiment to fit to fake sinusoidal data using the
Sinusoid
model. I provide the phase in turns, and want to associate the fitted phase offset with thephase
parameter, so I fixomega=2*np.pi
, fixphi
(in radians) to zero, and floatx0
(in turns).However, whether I set my modelled
phi_offset_turns
to 0, 0.25 or 0.5, I always get a fittedx0 = 0
. On further inspection, printing the other fitted values, it seemsphi
is in fact not fixed to 0 as requested.ionics_fragments.ndscan_extensions.analysis_exp:phase_analysis succeeded: x0=0.0 turns, a=0.500000(6), y0=0.500000(6), phi=-1.6(1) (significance 1.00)
ionics_fragments.ndscan_extensions.analysis_exp:phase_analysis succeeded: x0=0.0 turns, a=0.50(1), y0=0.500(10), phi=-3.14(8) (significance 1.00)
@hartytp suggested this was a quirk of the
PeriodicModelParameter
when thefixed_to
value is on a boundary, but the default range forphi
as define in theSinusoid
model is{-pi,pi}
so 0 is not on the boundary: https://github.com/OxIonics/ionics_fits/blob/48968cf7742fd97009cb48615f6c5961b53c156d/ionics_fits/models/sinusoid.py#L40C1-L44C11Example to reproduce