Result Augmentation
SRToolkit.evaluation.result_augmentation
This module contains the implementations of the ResultAugmenter class. These implementations augment the results dictionary returned by the SRToolkit.evaluate function with additional information, such as the LaTeX representation of the best expression, or RMSE on the test set, ...
RESULT_AUGMENTERS
module-attribute
RESULT_AUGMENTERS: Dict[str, Type[ResultAugmenter]] = {'ExpressionToLatex': ExpressionToLatex, 'RMSE': RMSE, 'BED': BED, 'R2': R2, 'ExpressionSimplifier': ExpressionSimplifier}
A mapping of augmentation names to their corresponding ResultAugmenter classes.
This constant defines the library of available result augmentation classes used across the benchmarking framework.
The dictionary keys are the unique string identifiers for the augmentor found under the 'type' value in the to_dict function. The values are the uninstantiated class objects, all of which inherit from ResultAugmenter.
ExpressionToLatex
Bases: ResultAugmenter
Transforms the expressions inside the results dictionary into LaTeX strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only_best_expression
|
bool
|
If True, only the best expression is transformed. If False, all top expressions are transformed. |
False
|
verbose
|
bool
|
If True, warns the user if LaTeX conversion fails for a given expression. |
False
|
Source code in SRToolkit/evaluation/result_augmentation.py
augment_results
Transforms the expressions inside the results dictionary into LaTeX strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
The dictionary containing the results to augment. |
required |
models
|
List[dict]
|
A list of dictionaries describing the performance of expressions using the base ranking function. Keyword expr contains the expression, error contains the error of the expression. The list is sorted by error. |
required |
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The augmented results dictionary. The results dictionary contains an additional key "best_expr_latex" with the LaTeX representation of the best expression, and similarly keys "expr_latex" for expressions inside the top_models list if only_best_expression is False. |
Source code in SRToolkit/evaluation/result_augmentation.py
to_dict
Creates a dictionary representation of the ExpressionToLatex augmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Unused and ignored |
required |
name
|
str
|
Unused and ignored |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
from_dict
staticmethod
Creates an instance of the ExpressionToLatex augmenter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
required |
augmenter_map
|
Optional[dict]
|
Unused and ignored |
None
|
Returns:
| Type | Description |
|---|---|
ExpressionToLatex
|
An instance of the ExpressionToLatex augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
ExpressionSimplifier
Bases: ResultAugmenter
Simplifies the expressions inside the results dictionary if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only_best_expression
|
bool
|
If True, only the best expression is simplified. If False, all top expressions are simplified. |
False
|
verbose
|
bool
|
If True, warns the user if simplification fails for a given expression. |
False
|
Source code in SRToolkit/evaluation/result_augmentation.py
augment_results
Simplifies the expressions inside the results dictionary if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
The dictionary containing the results to augment. |
required |
models
|
List[dict]
|
A list of dictionaries describing the performance of expressions using the base ranking function. Keyword expr contains the expression, error contains the error of the expression. The list is sorted by error. |
required |
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The augmented results dictionary. The results dictionary contains an additional key "simplified_best_expr" |
dict
|
if simplification was successful for the best expression, and similarly keys "simplified_expr" inside the |
dict
|
top_models list if only_best_expression is False. |
Source code in SRToolkit/evaluation/result_augmentation.py
to_dict
Creates a dictionary representation of the ExpressionSimplifier augmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Unused and ignored |
required |
name
|
str
|
Unused and ignored |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
from_dict
staticmethod
Creates an instance of the ExpressionSimplifier augmenter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
required |
augmenter_map
|
Optional[dict]
|
Unused and ignored |
None
|
Returns: An instance of the ExpressionSimplifier augmenter.
Source code in SRToolkit/evaluation/result_augmentation.py
RMSE
Bases: ResultAugmenter
Computes the RMSE for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models (e.g., evaluator defined with test set data). This evaluator must be initialized with ranking_function = "rmse" |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the evaluator is not initialized with ranking_function = "rmse" or if y in the evaluator is None. |
Source code in SRToolkit/evaluation/result_augmentation.py
augment_results
Computes the RMSE for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
The dictionary containing the results to augment. |
required |
models
|
List[dict]
|
A list of dictionaries describing the performance of expressions using the base ranking function. Keyword expr contains the expression, error contains the error of the expression. The list is sorted by error. |
required |
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The augmented results dictionary. The results dictionary contains an additional key "best_expr_rmse" with the |
dict
|
RMSE of the best expression, and keys "rmse" and "parameters_rmse" for each of the top_models inside the |
dict
|
results["top_models"] list. |
Source code in SRToolkit/evaluation/result_augmentation.py
to_dict
Creates a dictionary representation of the RMSE augmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Used to save the data of the evaluator to disk. |
required |
name
|
str
|
Used to save the data of the evaluator to disk. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
from_dict
staticmethod
Creates an instance of the RMSE augmenter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
required |
augmenter_map
|
Optional[dict]
|
A dictionary mapping augmenter names to their classes. |
None
|
Returns:
| Type | Description |
|---|---|
RMSE
|
An instance of the RMSE augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
BED
Bases: ResultAugmenter
Computes BED for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. This evaluator must be initialized with ranking_function = "bed" |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the evaluator is not initialized with ranking_function = "bed". |
Source code in SRToolkit/evaluation/result_augmentation.py
augment_results
Computes BED for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
The dictionary containing the results to augment. |
required |
models
|
List[dict]
|
A list of dictionaries describing the performance of expressions using the base ranking function. Keyword expr contains the expression, error contains the error of the expression. The list is sorted by error. |
required |
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The augmented results dictionary. The results dictionary contains an additional key "best_expr_bed" with |
dict
|
BED of the best expression, and key "bed" for each of the top_models inside the results["top_models"] list. |
Source code in SRToolkit/evaluation/result_augmentation.py
to_dict
Creates a dictionary representation of the BED augmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Used to save the data of the evaluator to disk. |
required |
name
|
str
|
Used to save the data of the evaluator to disk. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
from_dict
staticmethod
Creates an instance of the BED augmenter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
required |
augmenter_map
|
Optional[dict]
|
A dictionary mapping augmenter names to their classes. |
None
|
Returns:
| Type | Description |
|---|---|
BED
|
An instance of the BED augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
R2
Bases: ResultAugmenter
Computes the R^2 for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models (e.g., evaluator defined with test set data). This evaluator must be initialized with ranking_function = "rmse". If you're also using the RMSE augmenter, they the same one can be used for both. |
required |
Raises:
| Type | Description |
|---|---|
Exception
|
If the evaluator is not initialized with ranking_function = "rmse" or if y in the evaluator is None. |
Source code in SRToolkit/evaluation/result_augmentation.py
augment_results
Computes the R^2 for the top models in the results dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
The dictionary containing the results to augment. |
required |
models
|
List[dict]
|
A list of dictionaries describing the performance of expressions using the base ranking function. Keyword expr contains the expression, error contains the error of the expression. The list is sorted by error. |
required |
evaluator
|
SR_evaluator
|
The evaluator used to evaluate the models. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
The augmented results dictionary. The results dictionary contains an additional key "best_expr_r^2" with the |
dict
|
R^2 of the best expression, and keys "r^2" and "parameters_r^2" for each of the top_models inside the |
dict
|
results["top_models"] list. |
Source code in SRToolkit/evaluation/result_augmentation.py
to_dict
Creates a dictionary representation of the R2 augmenter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_path
|
str
|
Used to save the data of the evaluator to disk. |
required |
name
|
str
|
Used to save the data of the evaluator to disk. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
Source code in SRToolkit/evaluation/result_augmentation.py
from_dict
staticmethod
Creates an instance of the R2 augmenter from a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
A dictionary containing the necessary information to recreate the augmenter. |
required |
augmenter_map
|
Optional[dict]
|
A dictionary mapping augmenter names to their classes. |
None
|
Returns:
| Type | Description |
|---|---|
R2
|
An instance of the R2 augmenter. |