Skip to content

Bug/missing exception handling: sampling returns nan equations #36

@lfrommelt

Description

@lfrommelt

To replicate:

import equation_tree
from equation_tree.prior import priors_from_space, structure_prior_from_max_depth, structure_prior_from_depth
import numpy as np

max_vars =  2

prior={'structures': {'[0, 1, 2, 3]': 0.25, 
                '[0, 1, 2, 2]': 0.25, 
                '[0, 1, 2, 1]': 0.25, 
                '[0, 1, 1, 2]': 0.25}, 
 'functions': {'squared': 1.0}, 
 'operators': {'+': 0.25, 
               '-': 0.25, 
               '/': 0.25, 
               '*': 0.25}, 
 'features': {'constants': 0.3, 
              'variables': 0.7}}

np.random.seed(864)
equation = equation_tree.sample(
            n=1, prior=prior, max_num_variables=max_vars
        )

print(equation)

np.random.seed(556)
equation = equation_tree.sample(
            n=1, prior=prior, max_num_variables=max_vars
        )

print(equation)

will output:

Processing: 100%|█████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00, 45.17iteration/s]

[(c_1 + x_1)**2]

Processing: 100%|█████████████████████████████████████████████████████████████████| 1/1 [00:31<00:00, 31.80s/iteration]

[None]

So it seems the prior in general is not inconsistent, but a sampled structure + other spaces might be (not "enough leaves", maybe?). The much longer time that the failed run takes, makes it seem that some loop runs for a defined amount of iterations and, if not sucessfull, returns nan instead of raising an exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions