edges.modeling.core

Core classes for linear modelling.

class edges.modeling.core.FixedLinearModel(*, model: Model, x, init_basis=None)[source]

A base class for a linear model fixed at a certain set of co-ordinates.

Using this class caches the basis functions at the particular coordinates, and thus speeds up the fitting of multiple sets of data at those co-ordinates.

Parameters:
  • model (edges.modeling.core.Model) – The linear model to evaluate at the co-ordinates

  • x (numpy.ndarray) – A set of co-ordinates at which to evaluate the model.

  • init_basis – If the basis functions of the model, evaluated at x, are known already, they can be input directly to save computation time.

at_x(x: ndarray) Self[source]

Return a new FixedLinearModel at given co-ordinates.

property basis: ndarray[source]

The (cached) basis functions at default_x.

Shape (n_terms, x).

fit(ydata: ndarray, weights: ndarray | float = 1.0, xdata: ndarray | None = None, **kwargs) ModelFit[source]

Create a linear-regression fit object.

Parameters:
  • ydata – The data to fit.

  • weights – The weights to apply to the data.

  • xdata – The co-ordinates at which to fit the data. If not given, use self.x.

Returns:

fit – The ModelFit object.

Other Parameters:
  • All other parameters used to construct the :class:`ModelFit` object. Includes

  • ``method`` to specify the lstsq solving method.

classmethod from_file(path: str | Path | Group)

Load an HDF5 file as a given type.

property n_terms

The number of terms/parameters in the model.

property parameters: ndarray | None

The parameters of the model, if set.

classmethod to_yaml(dumper, data)[source]

Method to convert to YAML format.

with_nterms(n_terms: int, parameters: Sequence | None = None) Self[source]

Return a new FixedLinearModel with given nterms and parameters.

with_params(parameters: Sequence) Self[source]

Return a new FixedLinearModel with givne parameters.

write(path: str | Path | Group)

Write an attrs class to HDF5.

class edges.modeling.core.Model(*, parameters=None, n_terms=NOTHING, transform: XTransform = IdentityTransform(), xtransform: XTransform | None = NOTHING, basis_scaler: Callable | None = None, data_transform: DataTransform = IdentityTransform())[source]

A base class for a linear model.

at(**kwargs) FixedLinearModel[source]

Get an evaluated linear model.

fit(xdata: ndarray, ydata: ndarray, weights: ndarray | float = 1.0, **kwargs) ModelFit[source]

Create a linear-regression fit object.

classmethod from_file(path: str | Path | Group)

Load an HDF5 file as a given type.

static from_str(model: str, **kwargs) Self[source]

Obtain a Model given a string name.

abstractmethod get_basis_term(indx: int, x: ndarray) ndarray[source]

Define the basis terms for the model.

get_basis_term_transformed(indx: int, x: ndarray, with_scaler: bool = True) ndarray[source]

Get the basis term after coordinate transformation.

get_basis_terms(x: ndarray, with_scaler: bool = True) ndarray[source]

Get a 2D array of all basis terms at x.

with_nterms(n_terms: int | None = None, parameters: Sequence | None = None) Self[source]

Return a new Model with given nterms and parameters.

with_params(parameters: Sequence | None) Self[source]

Get new model with different parameters.

write(path: str | Path | Group)

Write an attrs class to HDF5.

edges.modeling.core.get_mdl(model: str | type[Model]) type[Model][source]

Get a linear model class from a string input.

edges.modeling.core.get_mdl_inst(model: str | Model | type[Model], **kwargs) Model[source]

Get a model instance from given string input.