Replies: 2 comments 5 replies
-
So if you have a function that takes an expression tree like |
Beta Was this translation helpful? Give feedback.
-
Sounds super cool!! Here's a bit more info in the form of an example: julia> using SymbolicRegression, MLJBase
julia> X = randn(100, 5);
julia> y = @. cos(X[:, 1] * 2.1 - 0.5) + 0.2 * X[:, 3] * X[:, 2];
julia> model = SRRegressor(binary_operators=[+, -, *, /], unary_operators=[cos], niterations=100);
julia> mach = machine(model, X, y);
julia> fit!(mach, verbosity=0);
julia> equations = report(mach).equations
8-element Vector{DynamicExpressions.EquationModule.Node{Float64}}:
0.05336346662643239
x₁ * 0.21680232405649386
cos(x₁ * 2.0617285536753673)
cos((x₁ * 2.035173184625832) + -0.5033370794240668)
cos((x₁ * -2.0106626799718876) - -0.4949017834844345) - 0.04205315632795699
cos((0.009450215065161867 / x₁) - (x₁ + (x₁ - 0.5057275123455831)))
cos(-0.499999999947676 - (x₁ * -2.09999999993789)) + (x₃ * (x₂ * 0.19999999996546464))
((((x₃ - cos(0.20000000003991894)) + cos(0.20000000003991894)) * 0.20000000003991894) * x₂) + cos(-0.4999999999840714 - (x₁ * -2.100000000063916))
julia> best = equations[end-1]
cos(-0.499999999947676 - (x₁ * -2.09999999993789)) + (x₃ * (x₂ * 0.19999999996546464))
julia> constants = filter(node -> node.degree == 0 && node.constant, best)
3-element Vector{DynamicExpressions.EquationModule.Node{Float64}}:
-0.499999999947676
-2.09999999993789
0.19999999996546464
julia> foreach(constants) do constant
constant.val *= 2
end
julia> best
cos(-0.999999999895352 - (x₁ * -4.19999999987578)) + (x₃ * (x₂ * 0.3999999999309293)) So you can see we doubled all the values. We can then do julia> best(X', mach.fitresult.options) to evaluate it. Note the A lot of the Base operations on collections are implemented for |
Beta Was this translation helpful? Give feedback.
-
I am trying to reproduce https://docs.kidger.site/diffrax/examples/symbolic_regression/ on the Julia end. Specifically this part
After fitting, is there an API which I can use to extract a function and parameters that can be fine-tuned?
Beta Was this translation helpful? Give feedback.
All reactions