Parameter Estimator Module
SRToolkit.evaluation.parameter_estimator
This module contains the ParameterEstimator class, which is used to estimate the parameters of an expression.
ParameterEstimator
Source code in SRToolkit/evaluation/parameter_estimator.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
__init__(X, y, symbol_library=SymbolLibrary.default_symbols(), **kwargs)
Initializes an instance of the ParameterEstimator class.
Examples:
>>> X = np.array([[1, 2], [8, 4], [5, 4], [7, 9], ])
>>> y = np.array([3, 0, 3, 11])
>>> pe = ParameterEstimator(X, y)
>>> rmse, constants = pe.estimate_parameters(["C", "*", "X_1", "-", "X_0"])
>>> print(rmse < 1e-6)
True
>>> print(1.99 < constants[0] < 2.01)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
The input data to be used in parameter estimation for variables. We assume that X is a 2D array with shape (n_samples, n_features). |
required |
y
|
ndarray
|
The target values to be used in parameter estimation. |
required |
symbol_library
|
SymbolLibrary
|
The symbol library to use. Defaults to SymbolLibrary.default_symbols(). |
default_symbols()
|
Other Parameters:
Name | Type | Description |
---|---|---|
method |
str
|
The method to be used for minimization. Currently, only "L-BFGS-B" is supported/tested. Default is "L-BFGS-B". |
tol |
float
|
The tolerance for termination. Default is 1e-6. |
gtol |
float
|
The tolerance for the gradient norm. Default is 1e-3. |
max_iter |
int
|
The maximum number of iterations. Default is 100. |
bounds |
List[float]
|
A list of two elements, specifying the lower and upper bounds for the constant values. Default is [-5, 5]. |
initialization |
str
|
The method to use for initializing the constant values. Currently, only "random" and "mean" are supported. "random" creates a vector with random values sampled within the bounds. "mean" creates a vector where all values are calculated as (lower_bound + upper_bound)/2. Default is "random". |
max_constants |
int
|
The maximum number of constants allowed in the expression. Default is 8. |
max_expr_length |
int
|
The maximum length of the expression. Default is -1 (no limit). |
Functions:
Name | Description |
---|---|
estimate_parameters |
List[str]): Estimates the parameters of an expression by minimizing the error between the predicted and actual values. |
Source code in SRToolkit/evaluation/parameter_estimator.py
estimate_parameters(expr)
Estimates the parameters of an expression by minimizing the error between the predicted and actual values.
Examples:
>>> X = np.array([[1, 2], [8, 4], [5, 4], [7, 9], ])
>>> y = np.array([3, 0, 3, 11])
>>> pe = ParameterEstimator(X, y)
>>> rmse, constants = pe.estimate_parameters(["C", "*", "X_1", "-", "X_0"])
>>> print(rmse < 1e-6)
True
>>> print(1.99 < constants[0] < 2.01)
True
Parameters:
Name | Type | Description | Default |
---|---|---|---|
expr
|
List[str]
|
A list of strings representing the expression to be evaluated. The expression should include the symbol 'C' for constants whose values need to be estimated. |
required |
Returns:
Type | Description |
---|---|
float
|
the root mean square error (RMSE) of the optimized expression. |
ndarray
|
An array containing the optimized constant values. |
Notes
if the length of the expression exceeds the maximum allowed, NaN and an empty array are returned. If the number of constants in the expression exceeds the maximum allowed, NaN and an empty array are returned. If there are no constants in the expression, the RMSE is calculated directly without optimization.