Spaces:
Running
Running
MilesCranmer
commited on
Commit
•
333f394
1
Parent(s):
7b7f087
Full docstring
Browse files
eureqa.py
CHANGED
@@ -51,54 +51,58 @@ def eureqa(X=None, y=None, threads=4,
|
|
51 |
test='simple1',
|
52 |
maxsize=20,
|
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 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
|
|
|
|
|
|
101 |
"""
|
|
|
102 |
rand_string = f'{"".join([str(np.random.rand())[2] for i in range(20)])}'
|
103 |
|
104 |
if isinstance(binary_operators, str): binary_operators = [binary_operators]
|
|
|
51 |
test='simple1',
|
52 |
maxsize=20,
|
53 |
):
|
54 |
+
"""Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
|
55 |
+
|
56 |
+
Note: most default parameters have been tuned over several example
|
57 |
+
equations, but you should adjust `threads`, `niterations`,
|
58 |
+
`binary_operators`, `unary_operators` to your requirements.
|
59 |
+
|
60 |
+
:X: np.ndarray, 2D. Rows are examples, columns are features.
|
61 |
+
:y: np.ndarray, 1D. Rows are examples.
|
62 |
+
:threads: Number of threads (=number of populations running).
|
63 |
+
You can have more threads than cores - it actually makes it more
|
64 |
+
efficient.
|
65 |
+
:niterations: Number of iterations of the algorithm to run. The best
|
66 |
+
equations are printed, and migrate between populations, at the
|
67 |
+
end of each.
|
68 |
+
:ncyclesperiteration: Number of total mutations to run, per 10
|
69 |
+
samples of the population, per iteration.
|
70 |
+
:binary_operators: List of strings giving the binary operators
|
71 |
+
in Julia's Base, or in `operator.jl`.
|
72 |
+
:unary_operators: Same but for operators taking a single `Float32`.
|
73 |
+
:alpha: Initial temperature.
|
74 |
+
:annealing: Whether to use annealing. You should (and it is default).
|
75 |
+
:fractionReplaced: How much of population to replace with migrating
|
76 |
+
equations from other populations.
|
77 |
+
:fractionReplacedHof: How much of population to replace with migrating
|
78 |
+
equations from hall of fame.
|
79 |
+
:npop: Number of individuals in each population
|
80 |
+
:parsimony: Multiplicative factor for how much to punish complexity.
|
81 |
+
:migration: Whether to migrate.
|
82 |
+
:hofMigration: Whether to have the hall of fame migrate.
|
83 |
+
:shouldOptimizeConstants: Whether to numerically optimize
|
84 |
+
constants (Nelder-Mead/Newton) at the end of each iteration.
|
85 |
+
:topn: How many top individuals migrate from each population.
|
86 |
+
:weightAddNode: Relative likelihood for mutation to add a node
|
87 |
+
:weightDeleteNode: Relative likelihood for mutation to delete a node
|
88 |
+
:weightDoNothing: Relative likelihood for mutation to leave the individual
|
89 |
+
:weightMutateConstant: Relative likelihood for mutation to change
|
90 |
+
the constant slightly in a random direction.
|
91 |
+
:weightMutateOperator: Relative likelihood for mutation to swap
|
92 |
+
an operator.
|
93 |
+
:weightRandomize: Relative likelihood for mutation to completely
|
94 |
+
delete and then randomly generate the equation
|
95 |
+
:weightSimplify: Relative likelihood for mutation to simplify
|
96 |
+
constant parts by evaluation
|
97 |
+
:timeout: Time in seconds to timeout search
|
98 |
+
:equation_file: Where to save the files (.csv separated by |)
|
99 |
+
:test: What test to run, if X,y not passed.
|
100 |
+
:maxsize: Max size of an equation.
|
101 |
+
:returns: pd.DataFrame, giving complexity, MSE, and equations
|
102 |
+
(as strings).
|
103 |
+
|
104 |
"""
|
105 |
+
|
106 |
rand_string = f'{"".join([str(np.random.rand())[2] for i in range(20)])}'
|
107 |
|
108 |
if isinstance(binary_operators, str): binary_operators = [binary_operators]
|