Skip to content

Commit

Permalink
Updated symbolic example to modern pysr+sympy
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-kidger committed Jan 2, 2025
1 parent 467d95f commit be387a7
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions examples/symbolic_regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@
"import optax # https://github.com/deepmind/optax\n",
"import pysr # https://github.com/MilesCranmer/PySR\n",
"import sympy\n",
"import sympy2jax # https://github.com/google/sympy2jax\n",
"\n",
"\n",
"# Note that PySR, which we use for symbolic regression, uses Julia as a backend.\n",
"# You'll need to install a recent version of Julia if you don't have one.\n",
"# (And can get funny errors if you have a too-old version of Julia already.)\n",
"# You may also need to restart Python after running `pysr.install()` the first time.\n",
"pysr.install(quiet=True)"
"import sympy2jax # https://github.com/google/sympy2jax"
]
},
{
Expand Down Expand Up @@ -112,7 +105,7 @@
"def quantise(expr, quantise_to):\n",
" if isinstance(expr, sympy.Float):\n",
" return expr.func(round(float(expr) / quantise_to) * quantise_to)\n",
" elif isinstance(expr, sympy.Symbol):\n",
" elif isinstance(expr, (sympy.Symbol, sympy.Integer)):\n",
" return expr\n",
" else:\n",
" return expr.func(*[quantise(arg, quantise_to) for arg in expr.args])"
Expand Down Expand Up @@ -174,7 +167,7 @@
" with tempfile.TemporaryDirectory() as tempdir:\n",
" symbolic_regressor = pysr.PySRRegressor(\n",
" niterations=symbolic_migration_steps,\n",
" ncyclesperiteration=symbolic_mutation_steps,\n",
" ncycles_per_iteration=symbolic_mutation_steps,\n",
" populations=symbolic_num_populations,\n",
" population_size=symbolic_population_size,\n",
" optimizer_iterations=symbolic_descent_steps,\n",
Expand Down

0 comments on commit be387a7

Please sign in to comment.