Skip to content

Commit be387a7

Browse files
Updated symbolic example to modern pysr+sympy
1 parent 467d95f commit be387a7

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

examples/symbolic_regression.ipynb

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@
7474
"import optax # https://github.com/deepmind/optax\n",
7575
"import pysr # https://github.com/MilesCranmer/PySR\n",
7676
"import sympy\n",
77-
"import sympy2jax # https://github.com/google/sympy2jax\n",
78-
"\n",
79-
"\n",
80-
"# Note that PySR, which we use for symbolic regression, uses Julia as a backend.\n",
81-
"# You'll need to install a recent version of Julia if you don't have one.\n",
82-
"# (And can get funny errors if you have a too-old version of Julia already.)\n",
83-
"# You may also need to restart Python after running `pysr.install()` the first time.\n",
84-
"pysr.install(quiet=True)"
77+
"import sympy2jax # https://github.com/google/sympy2jax"
8578
]
8679
},
8780
{
@@ -112,7 +105,7 @@
112105
"def quantise(expr, quantise_to):\n",
113106
" if isinstance(expr, sympy.Float):\n",
114107
" return expr.func(round(float(expr) / quantise_to) * quantise_to)\n",
115-
" elif isinstance(expr, sympy.Symbol):\n",
108+
" elif isinstance(expr, (sympy.Symbol, sympy.Integer)):\n",
116109
" return expr\n",
117110
" else:\n",
118111
" return expr.func(*[quantise(arg, quantise_to) for arg in expr.args])"
@@ -174,7 +167,7 @@
174167
" with tempfile.TemporaryDirectory() as tempdir:\n",
175168
" symbolic_regressor = pysr.PySRRegressor(\n",
176169
" niterations=symbolic_migration_steps,\n",
177-
" ncyclesperiteration=symbolic_mutation_steps,\n",
170+
" ncycles_per_iteration=symbolic_mutation_steps,\n",
178171
" populations=symbolic_num_populations,\n",
179172
" population_size=symbolic_population_size,\n",
180173
" optimizer_iterations=symbolic_descent_steps,\n",

0 commit comments

Comments
 (0)