edges.modeling.fitting¶
Fitting routines for models.
- class edges.modeling.fitting.ModelFit(model: FixedLinearModel, ydata: ndarray, weights: ndarray | float = 1.0, method: Literal['lstsq', 'qr', 'alan-qrd'] = 'lstsq')[source]¶
A class representing a fit of model to data.
- Parameters:
model (edges.modeling.core.FixedLinearModel) – The evaluatable model to fit to the data.
ydata (numpy.ndarray) – The values of the measured data.
weights (numpy.ndarray | float) – The weight of the measured data at each point. This corresponds to the variance of the measurement (not the standard deviation). This is appropriate if the weights represent the number of measurements going into each piece of data.
method (Literal[‘lstsq’, ‘qr’, ‘alan-qrd’]) – The method to solve the linear least squares problem. This can be either ‘lstsq’, ‘qr’ or ‘alan-qrd’. The ‘leastsq’ method uses the np.linalg.lstsq function, while the ‘qr’ method uses the np.linalg.solve function after scipy.linalg.qr. The ‘alan-qr’ method is a python-port of the QR decomposition algorithm found in Alan’s C Codebase.
- Raises:
ValueError – If model_type is not str, or a subclass of
Model.
- evaluate(x: ndarray | None = None) ndarray[source]¶
Evaluate the best-fit model.
- Parameters:
x (np.ndarray, optional) – The co-ordinates at which to evaluate the model. By default, use the input data co-ordinates.
- Returns:
y (np.ndarray) – The best-fit model evaluated at
x.
- property fit: FixedLinearModel¶
A model that has parameters set based on the best fit to this data.
- get_sample(size: int | tuple[int] = 1)[source]¶
Generate a random sample from the posterior distribution.
- property hessian¶
The Hessian matrix of the linear parameters.
- property model_parameters¶
The best-fit model parameters.