fitproblem - Interface between models and fitters¶
Fitness |
Manage parameters, data, and theory function evaluation. |
FitProblem |
Return a fit problem instance for the fitness function(s). |
load_problem |
Load a problem definition from a python script file. |
BaseFitProblem |
See FitProblem() |
MultiFitProblem |
Weighted fits for multiple models. |
Interface between the models and the fitters.
Fitness
defines the interface that model evaluators can follow.
These models can be bundled together into a FitProblem()
and sent
to bumps.fitters.FitDriver
for optimization and uncertainty
analysis.
-
class
bumps.fitproblem.
Fitness
[source]¶ Bases:
object
Manage parameters, data, and theory function evaluation.
See Complex models for a detailed explanation.
-
parameters
()[source]¶ Return the parameters in the model.
Model parameters are a hierarchical structure of lists and dictionaries.
-
plot
(view='linear')[source]¶ Plot the model to the current figure. You only get one figure, but you can make it as complex as you want. This will be saved as a png on the server, and composed onto a results web page.
-
residuals
()[source]¶ Return residuals for current theory minus data.
Used for Levenburg-Marquardt, and for plotting.
-
resynth_data
()[source]¶ Generate fake data based on uncertainties in the real data. For Monte Carlo resynth-refit uncertainty analysis. Bootstrapping?
-
-
bumps.fitproblem.
FitProblem
(*args, **kw)[source]¶ Return a fit problem instance for the fitness function(s).
For an individual model:
fitness is aFitness
instance.For a set of models:
models is a sequence of
Fitness
instances.weights is an optional scale factor for each model
freevars is
parameter.FreeVariables
instance defining the per-model parameter assignments. See Free Variables for details.Additional parameters:
name name of the problem
constraints is a function which returns the negative log likelihood of seeing the parameters independent from the fitness function. Use this for example to check for feasible regions of the search space, or to add constraints that cannot be easily calculated per parameter. Ideally, the constraints nllf will increase as you go farther from the feasible region so that the fit will be directed toward feasible values.
soft_limit is the constraints function cutoff, beyond which the penalty_nllf will be used and fitness nllf will not be calculated.
penalty_nllf is the nllf to use for fitness when constraints is greater than soft_limit.
Total nllf is the sum of the parameter nllf, the constraints nllf and the depending on whether constraints is greater than soft_limit, either the fitness nllf or the penalty nllf.
-
bumps.fitproblem.
load_problem
(filename, options=None)[source]¶ Load a problem definition from a python script file.
sys.argv is set to
[file] + options
within the context of the script.The user must define
problem=FitProblem(...)
within the script.Raises ValueError if the script does not define problem.
-
class
bumps.fitproblem.
BaseFitProblem
(fitness, name=None, constraints=<function no_constraints>, penalty_nllf=1000000.0, soft_limit=inf, partial=False)[source]¶ Bases:
object
See
FitProblem()
-
chisq
()[source]¶ Return sum squared residuals normalized by the degrees of freedom.
In the context of a composite fit, the reduced chisq on the individual models only considers the points and the fitted parameters within the individual model.
Note that this does not include cost factors due to constraints on the parameters, such as sample_offset ~ N(0,0.01).
-
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.
-
nllf
(pvec=None)[source]¶ Compute the cost function for a new parameter set p.
Note that this is not simply the sum-squared residuals, but instead is the negative log likelihood of seeing the data given the model plus the negative log likelihood of seeing the model. The individual likelihoods are scaled by 1/max(P) so that normalization constants can be ignored.
The model is not actually calculated if the parameter nllf plus the constraint nllf are bigger than soft_limit, but instead it is assigned a value of penalty_nllf.
-
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.
-
-
class
bumps.fitproblem.
MultiFitProblem
(models, weights=None, name=None, constraints=<function no_constraints>, soft_limit=inf, penalty_nllf=1000000.0, freevars=None)[source]¶ Bases:
bumps.fitproblem.BaseFitProblem
Weighted fits for multiple models.
-
bounds
()¶
-
chisq
()¶ Return sum squared residuals normalized by the degrees of freedom.
In the context of a composite fit, the reduced chisq on the individual models only considers the points and the fitted parameters within the individual model.
Note that this does not include cost factors due to constraints on the parameters, such as sample_offset ~ N(0,0.01).
-
chisq_str
()¶
-
cov
()¶
-
getp
()¶ Returns the current value of the parameter vector.
-
labels
()¶
-
model_reset
()¶ 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.
-
models
¶ Iterate over models, with free parameters set from model values
-
nllf
(pvec=None)¶ Compute the cost function for a new parameter set p.
Note that this is not simply the sum-squared residuals, but instead is the negative log likelihood of seeing the data given the model plus the negative log likelihood of seeing the model. The individual likelihoods are scaled by 1/max(P) so that normalization constants can be ignored.
The model is not actually calculated if the parameter nllf plus the constraint nllf are bigger than soft_limit, but instead it is assigned a value of penalty_nllf.
-
parameter_nllf
()¶ Returns negative log likelihood of seeing parameters p.
-
parameter_residuals
()¶ Returns negative log likelihood of seeing parameters p.
-
randomize
(n=None)¶ 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)¶ 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.
-
stderr
()¶
-
summarize
()¶
-
valid
(pvec)¶
-