Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
3f4ce91
1
Parent(s):
d6b0684
Add functionality to save hall of fame to file
Browse files
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
.dataset.jl
|
2 |
.hyperparams.jl
|
|
|
|
1 |
.dataset.jl
|
2 |
.hyperparams.jl
|
3 |
+
*.csv
|
README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
# Eureqa.jl
|
2 |
|
3 |
-
Symbolic regression built on
|
4 |
Uses regularized evolution and simulated annealing.
|
5 |
|
6 |
## Running:
|
|
|
1 |
# Eureqa.jl
|
2 |
|
3 |
+
Symbolic regression built on Julia, and interfaced by Python.
|
4 |
Uses regularized evolution and simulated annealing.
|
5 |
|
6 |
## Running:
|
eureqa.jl
CHANGED
@@ -592,21 +592,25 @@ function fullRun(niterations::Integer;
|
|
592 |
end
|
593 |
|
594 |
dominating = PopMember[]
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
|
|
|
|
|
|
|
|
606 |
end
|
607 |
end
|
|
|
608 |
end
|
609 |
-
debug(verbosity, "")
|
610 |
|
611 |
# Migration
|
612 |
if migration
|
|
|
592 |
end
|
593 |
|
594 |
dominating = PopMember[]
|
595 |
+
open(hofFile, "w") do io
|
596 |
+
debug(verbosity, "Hall of Fame:")
|
597 |
+
debug(verbosity, "-----------------------------------------")
|
598 |
+
debug(verbosity, "Complexity \t MSE \t Equation")
|
599 |
+
println(io,"Complexity|MSE|Equation")
|
600 |
+
for size=1:maxsize
|
601 |
+
if hallOfFame.exists[size]
|
602 |
+
member = hallOfFame.members[size]
|
603 |
+
numberSmallerAndBetter = sum([member.score > hallOfFame.members[i].score for i=1:(size-1)])
|
604 |
+
betterThanAllSmaller = (numberSmallerAndBetter == 0)
|
605 |
+
if betterThanAllSmaller
|
606 |
+
debug(verbosity, "$size \t $(member.score-parsimony*size) \t $(stringTree(member.tree))")
|
607 |
+
println(io, "$size|$(member.score-parsimony*size)|$(stringTree(member.tree))")
|
608 |
+
push!(dominating, member)
|
609 |
+
end
|
610 |
end
|
611 |
end
|
612 |
+
debug(verbosity, "")
|
613 |
end
|
|
|
614 |
|
615 |
# Migration
|
616 |
if migration
|
eureqa.py
CHANGED
@@ -11,7 +11,7 @@ def eureqa(threads=4, parsimony=1e-3, alpha=10,
|
|
11 |
unary_operators=["cos", "exp", "sin"],
|
12 |
niterations=20, npop=100, annealing=True,
|
13 |
ncyclesperiteration=5000, fractionReplaced=0.1,
|
14 |
-
topn=10
|
15 |
):
|
16 |
|
17 |
def_hyperparams = f"""
|
@@ -42,6 +42,8 @@ def eureqa(threads=4, parsimony=1e-3, alpha=10,
|
|
42 |
const fractionReplacedHof = {fractionReplacedHof}f0
|
43 |
# Optimize constants
|
44 |
const shouldOptimizeConstants = {'true' if shouldOptimizeConstants else 'false'}
|
|
|
|
|
45 |
##################
|
46 |
"""
|
47 |
|
@@ -64,7 +66,7 @@ def eureqa(threads=4, parsimony=1e-3, alpha=10,
|
|
64 |
'julia -O3',
|
65 |
f'--threads {threads}',
|
66 |
'-e',
|
67 |
-
f'\'include("
|
68 |
])
|
69 |
import os
|
70 |
os.system(command)
|
@@ -87,6 +89,7 @@ if __name__ == "__main__":
|
|
87 |
parser.add_argument("--hofMigration", type=bool, default=True, help="Whether to have hall of fame migration")
|
88 |
parser.add_argument("--shouldOptimizeConstants", type=bool, default=True, help="Whether to use classical optimization on constants before every migration (doesn't impact performance that much)")
|
89 |
parser.add_argument("--annealing", type=bool, default=True, help="Whether to use simulated annealing")
|
|
|
90 |
|
91 |
parser.add_argument(
|
92 |
"--binary-operators", type=str, nargs="+", default=["plus", "mul"],
|
|
|
11 |
unary_operators=["cos", "exp", "sin"],
|
12 |
niterations=20, npop=100, annealing=True,
|
13 |
ncyclesperiteration=5000, fractionReplaced=0.1,
|
14 |
+
topn=10, equation_file='hall_of_fame.csv'
|
15 |
):
|
16 |
|
17 |
def_hyperparams = f"""
|
|
|
42 |
const fractionReplacedHof = {fractionReplacedHof}f0
|
43 |
# Optimize constants
|
44 |
const shouldOptimizeConstants = {'true' if shouldOptimizeConstants else 'false'}
|
45 |
+
# File to put operators
|
46 |
+
const hofFile = "{equation_file}"
|
47 |
##################
|
48 |
"""
|
49 |
|
|
|
66 |
'julia -O3',
|
67 |
f'--threads {threads}',
|
68 |
'-e',
|
69 |
+
f'\'include("eureqa.jl"); fullRun({niterations:d}, npop={npop:d}, annealing={"true" if annealing else "false"}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, 1e9), topn={topn:d})\''
|
70 |
])
|
71 |
import os
|
72 |
os.system(command)
|
|
|
89 |
parser.add_argument("--hofMigration", type=bool, default=True, help="Whether to have hall of fame migration")
|
90 |
parser.add_argument("--shouldOptimizeConstants", type=bool, default=True, help="Whether to use classical optimization on constants before every migration (doesn't impact performance that much)")
|
91 |
parser.add_argument("--annealing", type=bool, default=True, help="Whether to use simulated annealing")
|
92 |
+
parser.add_argument("--equation_file", type=str, default='hall_of_fame.csv', help="File to dump best equations to")
|
93 |
|
94 |
parser.add_argument(
|
95 |
"--binary-operators", type=str, nargs="+", default=["plus", "mul"],
|