Modeller¶
- class lsst.multiprofit.Modeller(logger: Logger | None = None)¶
Bases:
object
Fit lsst.gauss2d.fit Model instances using Python optimizers.
- Parameters:
- logger
logging.Logger
The logger. Defaults to calling
_getlogger
.
- logger
Methods Summary
compute_variances
(model[, use_diag_only, ...])Compute model free parameter variances from the inverse Hessian.
fit_gaussians_linear
(gaussians_linear, ...)Fit normalizations for a Gaussian mixture model.
fit_model
(model[, fitinputs, printout, config])Fit a model with a nonlinear optimizer.
fit_model_linear
(model[, idx_obs, ...])Fit a model's linear parameters (integrals).
make_components_linear
(component_mixture)Make a list of fixed Gaussian components from a ComponentMixture.
Methods Documentation
- static compute_variances(model: ModelD | ModelF, use_diag_only: bool = False, use_svd: bool = False, **kwargs: Any) ndarray ¶
Compute model free parameter variances from the inverse Hessian.
- Parameters:
- model
The model to compute parameter variances for.
- use_diag_only
Whether to use diagonal terms only, i.e. ignore covariance.
- use_svd
Whether to use singular value decomposition to compute the inverse Hessian.
- **kwargs
Additional keyword arguments to pass to model.compute_hessian.
- Returns:
- variances
The free parameter variances.
- static fit_gaussians_linear(gaussians_linear: LinearGaussians, observation: ObservationD, psf_model: PsfModel = None, fit_methods: dict[str, dict[str, Any]] | None = None, plot: bool = False) dict[str, lsst.multiprofit.modeller.FitResult] ¶
Fit normalizations for a Gaussian mixture model.
- Parameters:
- gaussians_linear
The Gaussian components - fixed or otherwise - to fit.
- observation
The observation to fit against.
- psf_model
A PSF model for the observation, if fitting sources.
- fit_methods
A dictionary of fitting methods to employ, keyed by method name, with a value of a dict of options (kwargs) to pass on. Default is “scipy.optimize.nnls”.
- plot
Whether to generate fit residual/diagnostic plots.
- Returns:
- results
Fit results for each method, keyed by the fit method name.
- fit_model(model: ModelD | ModelF, fitinputs: FitInputs | None = None, printout: bool = False, config: ModelFitConfig | None = None, **kwargs: Any) FitResult ¶
Fit a model with a nonlinear optimizer.
- Parameters:
- model
The model to fit.
- fitinputs
An existing FitInputs with jacobian/residual arrays to reuse.
- printout
Whether to print diagnostic information.
- config
Configuration settings for model fitting.
- **kwargs
Keyword arguments to pass to the optimizer.
- Returns:
- result
The results from running the fitter.
Notes
The only supported fitter is scipy.optimize.least_squares.
- classmethod fit_model_linear(model: ModelD | ModelF, idx_obs: int | Sequence[int] | None = None, ratio_min: float = 0, validate: bool = False, limits_interval_min: float = 0.01, limits_interval_max: float = 1.0) tuple[numpy.ndarray, numpy.ndarray] ¶
Fit a model’s linear parameters (integrals).
- Parameters:
- model
The model to fit parameters for.
- idx_obs
An index or sequence of indices of observations to fit. The default is to fit all observations.
- ratio_min
The minimum ratio of the previous value to set any parameter to. This can prevent setting parameters to zero.
- validate
If True, check that the model log-likelihood improves and restore the original parameter values if not.
- limits_interval_min
A value 0<=x<limits_interval_max<=1 specifying the lower bound to clip parameter values to, as a ratio of each parameter’s limits.
- limits_interval_max
A value 0<=limits_interval_min<x<=1 specifying the upper bound to clip parameter values to, as a ratio of each parameter’s limits.
- Returns:
- loglike_init
The initial log likelihood if validate is True, otherwise None.
- loglike_final
The post-fit log likelihood if validate is True, otherwise None.
Notes
The purpose of limits_interval is to slightly offset parameters from the extrema of their limits. This is typically most useful for integral parameters with a minimum of zero, which might otherwise be stuck at zero in a subsequent nonlinear fit.
- static make_components_linear(component_mixture: ComponentMixture) list[lsst.gauss2d.fit._gauss2d_fit.GaussianComponent] ¶
Make a list of fixed Gaussian components from a ComponentMixture.
- Parameters:
- component_mixture
A component mixture to create a component list for.
- Returns:
- gaussians
A list of Gaussians components with fixed parameters and values matching those in the original component mixture.