Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
74541ce
1
Parent(s):
7b75cd8
Add a detailed example to the README
Browse files
README.md
CHANGED
@@ -152,6 +152,83 @@ For examples of these and other features, see the [examples page](https://astroa
|
|
152 |
For a detailed look at more options, see the [options page](https://astroautomata.com/PySR/#/options).
|
153 |
You can also see the full API at [this page](https://astroautomata.com/PySR/#/api).
|
154 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
# Docker
|
157 |
|
|
|
152 |
For a detailed look at more options, see the [options page](https://astroautomata.com/PySR/#/options).
|
153 |
You can also see the full API at [this page](https://astroautomata.com/PySR/#/api).
|
154 |
|
155 |
+
## Detailed Example
|
156 |
+
|
157 |
+
The following code makes use of as many PySR features as possible.
|
158 |
+
Note that in practice you may not want to run with all of these, but
|
159 |
+
it shows the types of things you can do.
|
160 |
+
|
161 |
+
```python
|
162 |
+
model = PySRRegressor(
|
163 |
+
procs=4,
|
164 |
+
populations=8,
|
165 |
+
# ^ 2 populations per core, so one is always running.
|
166 |
+
population_size=50,
|
167 |
+
# ^ Slightly larger populations, for greater diversity.
|
168 |
+
ncyclesperiteration=500,
|
169 |
+
# ^ Generations between migrations.
|
170 |
+
niterations=10000000, # Run forever
|
171 |
+
early_stop_condition=(
|
172 |
+
"stop_if(loss, complexity) = loss < 1e-6 && complexity < 10"
|
173 |
+
# Stop early if we find a good and simple equation
|
174 |
+
),
|
175 |
+
timeout_in_seconds=60 * 60 * 24,
|
176 |
+
# ^ Alternatively, stop after 24 hours have passed.
|
177 |
+
maxsize=50,
|
178 |
+
# ^ Allow greater complexity.
|
179 |
+
maxdepth=10,
|
180 |
+
# ^ But, avoid deep nesting.
|
181 |
+
binary_operators=["*", "+", "-", "/"],
|
182 |
+
unary_operators=["square", "cube", "exp", "cos2(x)=cos(x)^2"],
|
183 |
+
constraints={
|
184 |
+
"/": (-1, 9),
|
185 |
+
"square": 9,
|
186 |
+
"cube": 9,
|
187 |
+
"exp": 9,
|
188 |
+
},
|
189 |
+
# ^ Limit the complexity within each argument.
|
190 |
+
# "inv": (-1, 9) states that the numerator has no constraint,
|
191 |
+
# but the denominator has a max complexity of 9.
|
192 |
+
# "exp": 9 simply states that `exp` can only have
|
193 |
+
# an expression of complexity 9 as input.
|
194 |
+
nested_constraints={
|
195 |
+
"square": {"square": 1, "cube": 1, "exp": 0},
|
196 |
+
"cube": {"square": 1, "cube": 1, "exp": 0},
|
197 |
+
"exp": {"square": 1, "cube": 1, "exp": 0},
|
198 |
+
},
|
199 |
+
# ^ Nesting constraints on operators. For example,
|
200 |
+
# "square(exp(x))" is not allowed, since "square": {"exp": 0}.
|
201 |
+
complexity_of_operators={"/": 2, "exp": 3},
|
202 |
+
# ^ Custom complexity of particular operators.
|
203 |
+
complexity_of_constants=2,
|
204 |
+
# ^ Punish constants more than variables
|
205 |
+
select_k_features=4,
|
206 |
+
# ^ Train on only the 4 most important features
|
207 |
+
progress=True,
|
208 |
+
# ^ Can set to false if printing to a file.
|
209 |
+
weight_randomize=0.1,
|
210 |
+
# ^ Randomize the tree much more frequently
|
211 |
+
cluster_manager=None,
|
212 |
+
# ^ Can be set to, e.g., "slurm", to run a slurm
|
213 |
+
# cluster. Just launch one script from the head node.
|
214 |
+
precision=64,
|
215 |
+
# ^ Higher precision calculations.
|
216 |
+
warm_start=True,
|
217 |
+
# ^ Start from where left off.
|
218 |
+
julia_project=None,
|
219 |
+
# ^ Can set to the path of a folder containing the
|
220 |
+
# "SymbolicRegression.jl" repo, for custom modifications.
|
221 |
+
update=False,
|
222 |
+
# ^ Don't update Julia packages
|
223 |
+
extra_sympy_mappings={"cos2": lambda x: sympy.cos(x)^2},
|
224 |
+
extra_torch_mappings={sympy.cos: torch.cos},
|
225 |
+
# ^ Not needed as cos already defined, but this
|
226 |
+
# is how you define custom torch operators.
|
227 |
+
extra_jax_mappings={sympy.cos: "jnp.cos"},
|
228 |
+
# ^ For JAX, one passes a string.
|
229 |
+
)
|
230 |
+
```
|
231 |
+
|
232 |
|
233 |
# Docker
|
234 |
|