ParametricModel#

class relife.base.ParametricModel(*params)[source]#

Base class for ReLife models with parameters.

The class stores parameters in a tree structure, exposes them as a flat vector with get_params and set_params, and tracks fitting results.

Examples

>>> class ModelA(ParametricModel):
...     def __init__(self, a, b):
...         super().__init__(a, b)
>>> class ModelB(ParametricModel):
...     def __init__(self, baseline : ModelA):
...         super().__init__()
...         self.baseline = baseline
>>> model_a = ModelA(1, 2)
>>> model_b = ModelB(model_a)
>>> model_b.get_params()
array([1, 2])

Methods

get_params

Get the parameters of this model.

is_fitted

Whether fitting results are set.

is_parametrized

Whether at least one parameter value is set.

set_params

Set the parameters of this model.

get_params()[source]#

Get the parameters of this model.

Returns:
out1darray of floats

Model parameters.

Notes

If parameter values are not set, they default to np.nan values.

is_fitted()[source]#

Whether fitting results are set.

is_parametrized()[source]#

Whether at least one parameter value is set.

set_params(new_params)[source]#

Set the parameters of this model.

Parameters:
new_params1d array-like of floats

Model parameters.

Notes

set_params definition expects an array-like of floats. At runtime, complex parameters might be setted temporarily to approximate fitted parameters covariance. This is contradictory to the given typing. At the moment, we don’t see a better solution and we believe that this is actually a limitation of what can be expressed in the static typesystem.