classic_estimators Package
classic_estimators
Package
Package providing some well-known parametric and non-parametric regression estimators. The interface providedis similar to the deep learning based methods, thus enabling a consistent usage of different estimators within the SDE calibration package.
linear_regressor
Module
- class sde_calibration.classic_estimators.linear_regressor.LinearRegressionEstimator(data, stabilizer=1e-08, feature_transformation_type='polynomial', num_basis_functions=2, logger=None, **preprocessor_arguments)
Bases:
sde_calibration.estimators.RegressionEstimator
Standard linear regression interface including a feature transformation into a different input space.
- Parameters
data (pd.DataFrame) – The time series data that should be used for the estimation. The DataFrame needs to have the fields ‘t’ and ‘X’.
stabilizer (float, optional) –
Regularization parameter in order to stabilize the inversion arising in the exact solution to the linear regression problem.
|default|
1e-08
feature_transformation_type (str, optional) –
Gives the type of feature transformation that should be performed. Possible values are:
polynomial
|default|
'polynomial'
num_basis_functions (int, optional) –
Specifies the number of basis functions that should be used in the feature transformation.
logger (logging.Logger, optional) –
A logger that should be used for logging and/or displaying intermediate resutls.
|default|
None
**preprocessor_arguments –
Keyword arguments that are further passed to the
preprocessor class
.
- Return type
None
- Raises
ValueError – If the type of feature transformation is not valid.
- __call__(x)
Calls the model behind the estimator. Transforms the input according to the scaling provided, predicts using the fitted model and finally applies the inverse transform to the outputs of the fitted model.
- Parameters
x (np.ndarray) – Array of points of prediciton.
- Returns
Array containing the model predictions.
- Return type
np.ndarray
- Raises
NotCompiledError: If the model is not compiled, the estimator does not know whether the drift or diffusion coefficient should be approximated.
- compile(mode='drift')
Method used to compile the model. For every regression estimator. It is crucial to specify whether the drift or diffusion coefficient should be approximated before the estimator can be fit or called.
- Parameters
mode (str, optional) –
A string giving the mode of estimation. Possible options are:
drift
diffusion
|default|
'drift'
- Return type
None
- Raises
ValueError – If the provided string for the mode is invalid.
- fit()
Fits the model to the provided data for the mode that the estimator is compiled in.
- Return type
None
- Raises
NotCompiledError – If the fit function is called before the model is compiled.
- get_num_parameters()
Returns the number of parameters in the model that is used by a certain estimator.
- Returns
Number of parameters.
- Return type
int
local_polynomial_estimator
Module
- class sde_calibration.classic_estimators.local_polynomial_estimator.LocalPolynomialEstimator(data, polynomial_degree=0, bandwidth=None, logger=None, **preprocessor_arguments)
Bases:
sde_calibration.estimators.RegressionEstimator
Interface for a standard non-parametric regression estimator, that is the local polynomial regression.
- Parameters
data (pd.DataFrame) – The time series data that should be used for the estimation. The DataFrame needs to have the fields ‘t’ and ‘X’.
polynomial_degree (int, optional) –
Determines the degree of the local polynomial that should be used for the local approximation. If 0 is provided this is equivalent to the Nadaraya-Watson estimator.
bandwidth (float, optional) –
Bandwidth that should be used for the kernel function in the approximation. If no bandwidth is provided, it is computed using Scott’s rule.
|default|
None
logger (logging.Logger, optional) –
A logger that should be used for logging and/or displaying intermediate resutls.
|default|
None
**preprocessor_arguments –
Keyword arguments that are further passed to the
preprocessor class
.
- Return type
None
See also
For more information on non-parametric regression estimators see e.g. these Notes for Predictive Modeling.
- __call__(x, uncertainty=False, show_progress=True)
Calls the model behind the estimator. Transforms the input according to the scaling provided, predicts by fitting a polynomial model locally and finally applies the inverse transform to the outputs of the fitted model.
- Parameters
- Returns
Array containing the model predictions, the estimated biases, and the estimated standard deviations.
- Return type
tuple (np.ndarray, np.ndarray, np.ndarray)
- Raises
NotCompiledError: If the model is not compiled, the estimator does not know whether the drift or diffusion coefficient should be approximated.
Warning
Note that if the uncertainty parameter is set to True, the runtime will be significantly higher!
- compile(mode='drift')
Method used to compile the model. For every regression estimator. It is crucial to specify whether the drift or diffusion coefficient should be approximated before the estimator can be fit or called.
- Parameters
mode (str, optional) –
A string giving the mode of estimation. Possible options are:
drift
diffusion
|default|
'drift'
- Return type
None
- Raises
ValueError – If the provided string for the mode is invalid.
- fit()
Fits the model to the provided data for the mode that the estimator is compiled in. In this case this means setting up the kernel density estimator, since the whole fitting part is integrated into the prediciton. This is because for every point a polynomial model has to be fit.
- Return type
None
- Raises
NotCompiledError – If the fit function is called before the model is compiled.
- get_num_parameters()
Returns the number of parameters in the model that is used by a certain estimator.
- Returns
Number of parameters.
- Return type
int
- prob(x)
Estimated probability density function at the specified points by using the kernel density estimator.
- Parameters
x (np.ndarray) – Array of points at which the probability density funciton should be approximated.
- Returns
Estimated probability density at the points \(x\).
- Return type
np.ndarray