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

should_simplify when using Template Expression #419

Open
Moelf opened this issue Feb 15, 2025 · 0 comments
Open

should_simplify when using Template Expression #419

Moelf opened this issue Feb 15, 2025 · 0 comments

Comments

@Moelf
Copy link

Moelf commented Feb 15, 2025

I think conceptually it should be possible to do should_simplify inside each component of the Template Expression, maybe I should open an issue to track that?

Originally posted by @Moelf in #381

Currently, the option should_simplify seems to have no effect when using Template Expression, which results in HoF containing:

using SymbolicRegression, Distributions, Random, MLJ

toy_range = 20:300

toy_fun(x) = (12*x^2 + 2*x) ^ (0.1*log(x))

Random.seed!(87462)
X = (; xs = float.(toy_range))
true_ys = toy_fun.(X.xs)
# ys = @. true_ys * ( 1 + randn()/10);


structure = TemplateStructure{(:B, :E)}(
    ((; B, E), (x,)) -> B(x)^E(log(x))
)

model2 = SRRegressor(
    binary_operators=[+, *],
    expression_spec=TemplateExpressionSpec(; structure),
    should_simplify=true,
    should_optimize_constants=true,
    niterations=200
)
sr_mach2 = machine(model2, X, true_ys)

fit!(sr_mach2)

Below, in Complexity 12, B = ((#1 * 0.0062979) + #1) + 0.047125 should be simplified furthuer

Complexity  Loss       Score      Equation
2           6.628e+04  1.802e+01  ╭ B = #1
                                  ╰ E = 1.3458
4           2.277e+02  2.837e+00  ╭ B = #1 * 0.091314
                                  ╰ E = 2.3902
6           3.800e-04  6.652e+00  ╭ B = #1 * 3.4747
                                  ╰ E = #1 * 0.19992
8           2.626e-07  3.639e+00  ╭ B = #1 + 0.059995
                                  ╰ E = (#1 * 0.19999) + 0.24853
12          1.542e-08  7.088e-01  ╭ B = ((#1 * 0.0062979) + #1) + 0.047125
                                  ╰ E = (#1 * 0.20003) + 0.2468
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

1 participant