bumps_interface.fitproblem - Bumps FitProblem definition for reflectivity models

FitProblem

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.

bounds()[source]

Return the bounds for each parameter as a 2 x N array

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]]
constraints_nllf() Tuple[float, List[str]][source]

Return the cost function for all constraints

property dof
property fitness
freevars: util.Optional[parameter.FreeVariables]
getp()[source]

Returns the current value of the parameter vector.

property has_residuals

True if all underlying fitness functions define residuals.

labels() List[str][source]

Return the list of labels, one per fitted parameter.

model_nllf()[source]

Return cost function for all data sets

model_parameters()[source]

Return parameters from all models

model_points()[source]

Return number of points in all models

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.

model_update()[source]

Let all models know they need to be recalculated

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.

parameter_residuals()[source]

Returns negative log likelihood of seeing parameters p.

penalty_nllf: util.Union[float, util.Literal['inf']]
plot(p=None, fignum=1, figfile=None, view=None, model_indices=None)[source]
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.

residuals()[source]
restore_data()[source]

Restore original data after resynthesis.

resynth_data()[source]

Resynthesize data with noise from the uncertainty estimates.

save(basename)[source]
set_active_model(i)[source]

Use free parameters from model i

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.

show()[source]
simulate_data(noise=None)[source]

Simulate data with added noise

summarize()[source]

Return a table of current parameter values with range bars.

to_dict()[source]
valid(pvec)[source]

Return true if the point is in the feasible region

weights: util.Union[util.List[float], util.Literal[None]]