Fit Constraint¶
How constraints on parameters work¶
Consider the scenario where the aim is to fit a lorenzian function to a
1D dataset but a constraint applied on the peak centre parameter. Assume
the 1D dataset consists of
where he lorentzian fitting parameters here are
- height of peak (at maximum) - centre of peak - half-width at half-maximum
We want to apply a constraint on the x0 parameter, i.e. the centre of
the peak. For example, apply the constraint that
where
.
If more than one constraint is defined, then for each violated constraint a penalty of the type defined above is added to the calculated fitting function.
If the penalty C is not the default value of 1000, then the constraint penalty value will be included whenever the function is converted to a string. For example:
from mantid.simpleapi import *
myFunction = Gaussian(Height=1.0, PeakCentre=3.0, Sigma=1.0)
myFunction.constrain("PeakCentre < 6")
print(myFunction)
myFunction.setConstraintPenaltyFactor("PeakCentre", 10.0)
print(myFunction)
myFunction.constrain('Sigma > 0')
print(myFunction)
will output:
name=Gaussian,Height=1,PeakCentre=3,Sigma=1,constraints=(PeakCentre<6)
name=Gaussian,Height=1,PeakCentre=3,Sigma=1,constraints=(PeakCentre<6,penalty=10)
name=Gaussian,Height=1,PeakCentre=3,Sigma=1,constraints=(PeakCentre<6,penalty=10,0<Sigma)`
Category: Concepts