bumps_interface.fitproblem - Bumps FitProblem definition for reflectivity models¶
A dataclass which wraps bumps's FitProblem with a list of Experiment models. |
- class refl1d.bumps_interface.fitproblem.FitProblem(models: Fitness | List[Fitness], weights=None, name=None, constraints=None, penalty_nllf='inf', freevars=None, soft_limit: float | None = None, auto_tag=False)[source]¶
Bases:
FitProblem
A dataclass which wraps bumps’s FitProblem with a list of Experiment models.
Mainly used to provide a more descriptive __doc__ string, and to allow IDEs to provide better type hints.
- chisq_str()[source]¶
Return a string representing the chisq equivalent of the nllf.
If the model has strictly gaussian independent uncertainties then the negative log likelihood function will return 0.5*sum(residuals**2), which is 1/2*chisq. Since we are printing normalized chisq, we multiply the model nllf by 2/DOF before displaying the value. This is different from the problem nllf function, which includes the cost of the prior parameters and the cost of the penalty constraints in the total nllf. The constraint value is displayed separately.
- constraints: util.Optional[util.Sequence[parameter.Constraint]]¶
- property dof¶
- property fitness¶
- freevars: util.Optional[parameter.FreeVariables]¶
- property has_residuals¶
True if all underlying fitness functions define residuals.
- model_reset()[source]¶
Prepare for the fit.
This sets the parameters and the bounds properties that the solver is expecting from the fittable object. We also compute the degrees of freedom so that we can return a normalized fit likelihood.
If the set of fit parameters changes, then model_reset must be called.
- property models¶
Iterate over models, with free parameters set from model values
- name: util.Optional[str]¶
- nllf(pvec=None) float [source]¶
compute the cost function for a new parameter set p.
this is not simply the sum-squared residuals, but instead is the negative log likelihood of seeing the data given the model parameters plus the negative log likelihood of seeing the model parameters. the value is used for a likelihood ratio test so normalization constants can be ignored. there is an additional penalty value provided by the model which can be used to implement inequality constraints. any penalty should be large enough that it is effectively excluded from the parameter space returned from uncertainty analysis.
the model is not actually calculated if any of the parameters are out of bounds, or any of the constraints are not satisfied, but instead are assigned a value of penalty_nllf. this will prevent expensive models from spending time computing values in the unfeasible region.
- parameter_nllf() Tuple[float, List[str]] [source]¶
Returns negative log likelihood of seeing parameters p.
- penalty_nllf: util.Union[float, util.Literal['inf']]¶
- randomize(n=None)[source]¶
Generates a random model.
randomize() sets the model to a random value.
randomize(n) returns a population of n random models.
For indefinite bounds, the random population distribution is centered on initial value of the parameter, or 1. if the initial parameter is not finite.
- setp(pvec)[source]¶
Set a new value for the parameters into the model. If the model is valid, calls model_update to signal that the model should be recalculated.
Returns True if the value is valid and the parameters were set, otherwise returns False.
- weights: util.Union[util.List[float], util.Literal[None]]¶