Spaces:
Running
Running
MilesCranmer
commited on
Commit
β’
009c407
1
Parent(s):
7ef6388
Rename package to pysr
Browse files- README.md +7 -5
- hyperparamopt.py +2 -2
- eureqa.jl β src/sr.jl +0 -0
- eureqa.py β src/sr.py +3 -3
README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
#
|
2 |
|
3 |
**Symbolic regression built on Julia, and interfaced by Python.
|
4 |
Uses regularized evolution and simulated annealing.**
|
@@ -33,14 +33,14 @@ For python, you need to have Python 3, numpy, and pandas installed.
|
|
33 |
|
34 |
```python
|
35 |
import numpy as np
|
36 |
-
from
|
37 |
|
38 |
# Dataset
|
39 |
X = 2*np.random.randn(100, 5)
|
40 |
y = 2*np.cos(X[:, 3]) + X[:, 0]**2 - 2
|
41 |
|
42 |
# Learn equations
|
43 |
-
equations =
|
44 |
|
45 |
...
|
46 |
|
@@ -75,10 +75,10 @@ You can add more operators in `operators.jl`, or use default
|
|
75 |
Julia ones. Make sure all operators are defined for scalar `Float32`.
|
76 |
Then just specify the operator names in your call, as above.
|
77 |
You can also change the dataset learned on by passing in `X` and `y` as
|
78 |
-
numpy arrays to `
|
79 |
|
80 |
```python
|
81 |
-
|
82 |
ncyclesperiteration=int(default_ncyclesperiteration),
|
83 |
binary_operators=["plus", "mult"], unary_operators=["cos", "exp", "sin"],
|
84 |
alpha=default_alpha, annealing=True, fractionReplaced=default_fractionReplaced,
|
@@ -147,6 +147,8 @@ pd.DataFrame, Results dataframe, giving complexity, MSE, and equations
|
|
147 |
|
148 |
# TODO
|
149 |
|
|
|
|
|
150 |
- [ ] Calculate feature importances of future mutations, by looking at correlation between residual of model, and the features.
|
151 |
- Store feature importances of future, and periodically update it.
|
152 |
- [ ] Implement more parts of the original Eureqa algorithms: https://www.creativemachineslab.com/eureqa.html
|
|
|
1 |
+
# PySR.jl
|
2 |
|
3 |
**Symbolic regression built on Julia, and interfaced by Python.
|
4 |
Uses regularized evolution and simulated annealing.**
|
|
|
33 |
|
34 |
```python
|
35 |
import numpy as np
|
36 |
+
from pysr import pysr
|
37 |
|
38 |
# Dataset
|
39 |
X = 2*np.random.randn(100, 5)
|
40 |
y = 2*np.cos(X[:, 3]) + X[:, 0]**2 - 2
|
41 |
|
42 |
# Learn equations
|
43 |
+
equations = pysr(X, y, niterations=5)
|
44 |
|
45 |
...
|
46 |
|
|
|
75 |
Julia ones. Make sure all operators are defined for scalar `Float32`.
|
76 |
Then just specify the operator names in your call, as above.
|
77 |
You can also change the dataset learned on by passing in `X` and `y` as
|
78 |
+
numpy arrays to `pysr(...)`.
|
79 |
|
80 |
```python
|
81 |
+
pysr(X=None, y=None, threads=4, niterations=20,
|
82 |
ncyclesperiteration=int(default_ncyclesperiteration),
|
83 |
binary_operators=["plus", "mult"], unary_operators=["cos", "exp", "sin"],
|
84 |
alpha=default_alpha, annealing=True, fractionReplaced=default_fractionReplaced,
|
|
|
147 |
|
148 |
# TODO
|
149 |
|
150 |
+
- [ ] Rename package to avoid trademark issues
|
151 |
+
- PySR?
|
152 |
- [ ] Calculate feature importances of future mutations, by looking at correlation between residual of model, and the features.
|
153 |
- Store feature importances of future, and periodically update it.
|
154 |
- [ ] Implement more parts of the original Eureqa algorithms: https://www.creativemachineslab.com/eureqa.html
|
hyperparamopt.py
CHANGED
@@ -4,7 +4,7 @@ import numpy as np
|
|
4 |
import pickle as pkl
|
5 |
import hyperopt
|
6 |
from hyperopt import hp, fmin, tpe, Trials
|
7 |
-
import
|
8 |
import time
|
9 |
|
10 |
import contextlib
|
@@ -77,7 +77,7 @@ def run_trial(args):
|
|
77 |
print(f"Starting test {i}")
|
78 |
for j in range(ntrials):
|
79 |
print(f"Starting trial {j}")
|
80 |
-
trial =
|
81 |
test=f"simple{i}",
|
82 |
threads=4,
|
83 |
binary_operators=["plus", "mult", "pow", "div"],
|
|
|
4 |
import pickle as pkl
|
5 |
import hyperopt
|
6 |
from hyperopt import hp, fmin, tpe, Trials
|
7 |
+
import pysr
|
8 |
import time
|
9 |
|
10 |
import contextlib
|
|
|
77 |
print(f"Starting test {i}")
|
78 |
for j in range(ntrials):
|
79 |
print(f"Starting trial {j}")
|
80 |
+
trial = pysr.pysr(
|
81 |
test=f"simple{i}",
|
82 |
threads=4,
|
83 |
binary_operators=["plus", "mult", "pow", "div"],
|
eureqa.jl β src/sr.jl
RENAMED
File without changes
|
eureqa.py β src/sr.py
RENAMED
@@ -23,7 +23,7 @@ default_topn = 10
|
|
23 |
default_parsimony = 1e-4
|
24 |
default_perturbationFactor = 1.0
|
25 |
|
26 |
-
def
|
27 |
niterations=100,
|
28 |
ncyclesperiteration=300,
|
29 |
binary_operators=["plus", "mult"],
|
@@ -178,7 +178,7 @@ const y = convert(Array{Float32, 1}, """f"{y_str})""""
|
|
178 |
'julia -O3',
|
179 |
'--threads auto',
|
180 |
'-e',
|
181 |
-
f'\'include(".hyperparams_{rand_string}.jl"); include(".dataset_{rand_string}.jl"); include("
|
182 |
]
|
183 |
if timeout is not None:
|
184 |
command = [f'timeout {timeout}'] + command
|
@@ -232,4 +232,4 @@ if __name__ == "__main__":
|
|
232 |
help="Unary operators. Make sure they are defined in operators.jl")
|
233 |
args = vars(parser.parse_args()) #dict
|
234 |
|
235 |
-
|
|
|
23 |
default_parsimony = 1e-4
|
24 |
default_perturbationFactor = 1.0
|
25 |
|
26 |
+
def pysr(X=None, y=None, threads=4,
|
27 |
niterations=100,
|
28 |
ncyclesperiteration=300,
|
29 |
binary_operators=["plus", "mult"],
|
|
|
178 |
'julia -O3',
|
179 |
'--threads auto',
|
180 |
'-e',
|
181 |
+
f'\'include(".hyperparams_{rand_string}.jl"); include(".dataset_{rand_string}.jl"); include("sr.jl"); fullRun({niterations:d}, npop={npop:d}, ncyclesperiteration={ncyclesperiteration:d}, fractionReplaced={fractionReplaced:f}f0, verbosity=round(Int32, {verbosity:f}), topn={topn:d})\'',
|
182 |
]
|
183 |
if timeout is not None:
|
184 |
command = [f'timeout {timeout}'] + command
|
|
|
232 |
help="Unary operators. Make sure they are defined in operators.jl")
|
233 |
args = vars(parser.parse_args()) #dict
|
234 |
|
235 |
+
pysr(**args)
|