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