Skip to content

ProGED

SRToolkit.approaches.ProGED

This module contains the ProGED approach - Probabilistic grammar-based equation discovery.

ProGED

ProGED(grammar: Union[str, SymbolLibrary], verbose: bool = False)

Bases: SR_approach

A slimmed down version of the ProGED approach. You can find the full version of the approach at https://github.com/brencej/ProGED and the paper presenting the approach at https://www.sciencedirect.com/science/article/pii/S0950705121003403.

The approach randomly samples expressions from a probabilistic grammar and evaluates them on the dataset.

Parameters:

Name Type Description Default
grammar Union[str, SymbolLibrary]

The grammar to use for sampling expressions. Can be either a string or a SymbolLibrary object. Using a string let's you define a custom grammar.

required
verbose bool

If True, prints the expression and its error if the expression is better than the current best.

False
Source code in SRToolkit/approaches/ProGED.py
def __init__(self, grammar: Union[str, SymbolLibrary], verbose: bool = False):
    super().__init__("ProGED")
    self.grammar = grammar
    self.verbose = verbose

search

search(sr_evaluator: SR_evaluator, seed: Optional[int] = None)

Samples expressions from the grammar using the Monte Carlo approach and evaluates them on the dataset.

Parameters:

Name Type Description Default
sr_evaluator SR_evaluator

The evaluator used for scoring expressions.

required
seed Optional[int]

The seed used for random number generation.

None
Source code in SRToolkit/approaches/ProGED.py
def search(self, sr_evaluator: SR_evaluator, seed: Optional[int] = None):
    """
    Samples expressions from the grammar using the Monte Carlo approach and evaluates them on the dataset.

    Args:
        sr_evaluator: The evaluator used for scoring expressions.
        seed: The seed used for random number generation.
    """
    # TODO: Take care of seeding for the generate_n_expressions function
    min_error = float("inf")
    while sr_evaluator.total_evaluations < sr_evaluator.max_evaluations and min_error > sr_evaluator.success_threshold:
        expr = generate_n_expressions(self.grammar, 1, verbose=False)[0]
        error = sr_evaluator.evaluate_expr(expr)
        if error < min_error:
            min_error = error
            if self.verbose:
                print(f"New best expression {''.join(expr)} with error {min_error} after {sr_evaluator.total_evaluations} evaluations.")
        min_error = min(min_error, error)

clone

clone()

Clones the ProGED approach.

Returns:

Type Description

The approach is stateless, so this method only returns the object itself.

Source code in SRToolkit/approaches/ProGED.py
def clone(self):
    """
    Clones the ProGED approach.

    Returns:
        The approach is stateless, so this method only returns the object itself.
    """
    return self