Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: More constant symplification? #381

Closed
Moelf opened this issue Dec 8, 2024 · 6 comments
Closed

[Feature]: More constant symplification? #381

Moelf opened this issue Dec 8, 2024 · 6 comments

Comments

@Moelf
Copy link

Moelf commented Dec 8, 2024

Feature Request

atlas_template = TemplateStructure{(:b, :e)}(
     ((; b, e), (x,)) -> b(x)^e(log(x))
)

sr_model2 = SRRegressor(
    niterations=150,
    binary_operators=[+, -, *, ^],
    unary_operators=[log],
    should_optimize_constants=true,
    seed=nothing,
    nested_constraints = [log => [log => 0, (^) => 0]],
    expression_type=TemplateExpression,
    expression_options=(; structure=atlas_template),
    loss_function = chi2_sr
)

sr_mach2 = machine(sr_model2, X, ys)

fit!(sr_mach2)

image

log(162.43) shouldn't use log at all (this increase the complexity of the expression unnecessarily)

@MilesCranmer
Copy link
Owner

You likely just need to set should_simplify=true. By default this is set to false if you are using nested_constraints as simplification might result in an expression that violates constraints. I think here though it's fine.

@MilesCranmer
Copy link
Owner

But in general there will be some points when the expression has redundancies like this. The genetic algorithm should eventually simplify it based on a lower complexity.

@MilesCranmer
Copy link
Owner

Also - we don't want to necessarily force simplified expressions. This is because mutations are single-step, so to get to log(x + const), the genetic algorithm might prefer to go from const to log(const) to log(x + const), rather than x to log(x) to log(x + const) which might hit a NaN. If we force simplification at every step, the log(const) expression wouldn't be possible.

@Moelf
Copy link
Author

Moelf commented Dec 8, 2024

It is already set to true

@MilesCranmer
Copy link
Owner

Oh in the code you sent, it isn't set at all:

julia> print(sr_model2.should_simplify)
nothing

It will be set to false during the search based on the other parameters set.

Maybe you meant should_simplify instead of should_optimize_constants?

@MilesCranmer
Copy link
Owner

(Is this ok to close? Or any issues with it?)

@Moelf Moelf closed this as completed Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants