Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
38f33fd
1
Parent(s):
0d86c93
Add complex number example
Browse files- docs/examples.md +35 -1
docs/examples.md
CHANGED
@@ -284,7 +284,41 @@ You can get the sympy version of the best equation with:
|
|
284 |
model.sympy()
|
285 |
```
|
286 |
|
287 |
-
## 8.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
288 |
|
289 |
For the many other features available in PySR, please
|
290 |
read the [Options section](options.md).
|
|
|
284 |
model.sympy()
|
285 |
```
|
286 |
|
287 |
+
## 8. Complex numbers
|
288 |
+
|
289 |
+
PySR can also search for complex-valued expressions. Simply pass
|
290 |
+
data with a complex datatype (e.g., `np.complex128`),
|
291 |
+
and PySR will automatically search for complex-valued expressions:
|
292 |
+
|
293 |
+
```python
|
294 |
+
import numpy as np
|
295 |
+
|
296 |
+
X = np.random.randn(100, 1) + 1j * np.random.randn(100, 1)
|
297 |
+
y = (1 + 2j) * np.cos(X[:, 0] * (0.5 - 0.2j))
|
298 |
+
|
299 |
+
model = PySRRegressor(
|
300 |
+
binary_operators=["+", "-", "*"], unary_operators=["cos"], niterations=100,
|
301 |
+
)
|
302 |
+
|
303 |
+
model.fit(X, y)
|
304 |
+
```
|
305 |
+
|
306 |
+
You can see that all of the learned constants are now complex numbers.
|
307 |
+
We can get the sympy version of the best equation with:
|
308 |
+
|
309 |
+
```python
|
310 |
+
model.sympy()
|
311 |
+
```
|
312 |
+
|
313 |
+
We can also make predictions normally, by passing complex data:
|
314 |
+
|
315 |
+
```python
|
316 |
+
model.predict(X, -1)
|
317 |
+
```
|
318 |
+
|
319 |
+
to make predictions with the most accurate expression.
|
320 |
+
|
321 |
+
## 9. Additional features
|
322 |
|
323 |
For the many other features available in PySR, please
|
324 |
read the [Options section](options.md).
|