forked from MilesCranmer/SymbolicRegression.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.jl
95 lines (83 loc) · 2.44 KB
/
example.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# export JULIA_NUM_THREADS=4
# export JULIA_DEBUG=loading
# julia --project=. example.jl
# julia example.jl
using SymbolicRegressionGPU
using LoopVectorization
function main()
X = randn(Float32, 5, 100)
# X = randn(Float64, 5, 101) # test for Float64, passed
# X = randn(Float64, 5, 10100) # test for PSRN downsampling, passed
# y = 2 * cos.(X[4, :]) + X[1, :] .^ 2 .- 2
y = 2 * cos.(X[4, :]) .^ 3 + X[1, :] .^ 2 .- 2 # harder problem
options = SymbolicRegressionGPU.Options(;
timeout_in_seconds=60,
binary_operators=[+, *, /, -],
unary_operators=[sin, cos, exp, log, sqrt],
# population_size=100,
# populations=15,
batching=true,
batch_size=100,
adaptive_parsimony_scaling=1_000.0,
parsimony=0.0,
maxsize=30,
maxdepth=20,
turbo=true,
# should_optimize_constants=false,
# optimizer_iterations=4,
# optimizer_f_calls_limit=1000,
# optimizer_probability=0.02,
# complexity_of_constants=3,
early_stop_condition=(l, c) -> (l < 1e-6 && c <= 5) || (l < 1e-10 && c <= 10),
constraints = [
sin => 9,
cos => 9,
exp => 9,
log => 9,
sqrt => 9
],
nested_constraints = [
sin => [
sin => 0,
cos => 0,
exp => 1,
log => 1,
sqrt => 1
],
cos => [
sin => 0,
cos => 0,
exp => 1,
log => 1,
sqrt => 1
],
exp => [
exp => 0,
log => 0
],
log => [
exp => 0,
log => 0
],
sqrt => [
sqrt => 0
]
]
)
hall_of_fame = equation_search(X, y;
options=options,
parallelism=:multithreading,
niterations=300)
dominating = calculate_pareto_frontier(hall_of_fame)
trees = [member.tree for member in dominating]
tree = trees[end]
output, did_succeed = eval_tree_array(tree, X, options)
println("Complexity\tMSE\tEquation")
for member in dominating
complexity = compute_complexity(member, options)
loss = member.loss
string = string_tree(member.tree, options)
println("$(complexity)\t$(loss)\t$(string)")
end
end
@time main()