Parameter Estimator
SRToolkit.evaluation.parameter_estimator
Constant parameter estimation for symbolic regression expressions using numerical optimization.
ParameterEstimator
ParameterEstimator(X: ndarray, y: ndarray, symbol_library: SymbolLibrary = SymbolLibrary.default_symbols(), seed: Optional[int] = None, **kwargs: Unpack[EstimationSettings])
Fits free constants in symbolic expressions by minimizing RMSE against target 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 |
|---|---|---|---|
X
|
ndarray
|
Input data of shape |
required |
y
|
ndarray
|
Target values of shape |
required |
symbol_library
|
SymbolLibrary
|
Symbol library defining the token vocabulary. Defaults to SymbolLibrary.default_symbols. |
default_symbols()
|
seed
|
Optional[int]
|
Random seed for reproducible constant initialization. Default |
None
|
**kwargs
|
Unpack[EstimationSettings]
|
Optional estimation settings from
EstimationSettings.
Supported keys: |
{}
|
Attributes:
| Name | Type | Description |
|---|---|---|
symbol_library |
The symbol library used. |
|
X |
Input data. |
|
y |
Target values. |
|
seed |
Random seed. |
|
estimation_settings |
Active settings dict, merged from defaults and |
Source code in SRToolkit/evaluation/parameter_estimator.py
estimate_parameters
Fit free constants in expr by minimizing RMSE against the target values.
Expressions that exceed max_constants or max_expr_length immediately
return (NaN, []). Expressions with no free constants are evaluated directly
without running the optimizer.
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
>>> # Constant-free expressions are evaluated directly
>>> rmse, constants = pe.estimate_parameters(["X_1", "-", "X_0"])
>>> constants.size
0
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
Union[List[str], Node]
|
Expression as a token list in infix notation or a Node tree. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[float, ndarray]
|
A 2-tuple |