From eb6195b7865afadb499a1118fe73b88e8b5e25af Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Wed, 13 Dec 2023 03:06:58 -0600 Subject: [PATCH 1/4] Document `max` and `min` --- docs/operators.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/operators.md b/docs/operators.md index 012f9ff9b..05ff0e960 100644 --- a/docs/operators.md +++ b/docs/operators.md @@ -14,6 +14,9 @@ A selection of these and other valid operators are stated below. - `*` - `/` - `^` +- `max` +- `min` +- `mod` - `cond` - Equal to `(x, y) -> x > 0 ? y : 0` - `greater` @@ -22,7 +25,6 @@ A selection of these and other valid operators are stated below. - Equal to `(x, y) -> (x > 0 || y > 0) ? 1 : 0` - `logical_and` - Equal to `(x, y) -> (x > 0 && y > 0) ? 1 : 0` -- `mod` **Unary** From 3b15555163bb952e457c73258f197a22703f48df Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Wed, 13 Dec 2023 03:07:57 -0600 Subject: [PATCH 2/4] Update operators.md --- docs/operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/operators.md b/docs/operators.md index 05ff0e960..a469d21bb 100644 --- a/docs/operators.md +++ b/docs/operators.md @@ -62,7 +62,7 @@ A selection of these and other valid operators are stated below. ## Custom Instead of passing a predefined operator as a string, -you can define with by passing it to the `pysr` function, with, e.g., +you can just define a custom function as Julia code. For example: ```python PySRRegressor( From 21fb25d814b9f7f64a39bbca1c3d4cbb5363542e Mon Sep 17 00:00:00 2001 From: MilesCranmer Date: Thu, 14 Dec 2023 12:00:24 -0600 Subject: [PATCH 3/4] Add more piecewise operators --- pysr/export_sympy.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pysr/export_sympy.py b/pysr/export_sympy.py index 3ea0baf06..f99a54a00 100644 --- a/pysr/export_sympy.py +++ b/pysr/export_sympy.py @@ -47,10 +47,13 @@ "ceil": sympy.ceiling, "sign": sympy.sign, "gamma": sympy.gamma, + "round": lambda x: sympy.ceiling(x - 0.5), "max": lambda x, y: sympy.Piecewise((y, x < y), (x, True)), "min": lambda x, y: sympy.Piecewise((x, x < y), (y, True)), - "round": lambda x: sympy.ceiling(x - 0.5), - "cond": lambda x, y: sympy.Heaviside(x, H0=0) * y, + "cond": lambda x, y: sympy.Piecewise((y, x > 0), (0.0, True)), + "logical_or": lambda x, y: sympy.Piecewise((1.0, (x > 0) | (y > 0)), (0.0, True)), + "logical_and": lambda x, y: sympy.Piecewise((1.0, (x > 0) & (y > 0)), (0.0, True)), + "relu": lambda x: sympy.Piecewise((0.0, x < 0), (x, True)), } From 6ff4b77fc26d89d8954bdfe07ad4cba897b50c34 Mon Sep 17 00:00:00 2001 From: Miles Cranmer Date: Thu, 14 Dec 2023 12:45:37 -0600 Subject: [PATCH 4/4] Bump version with more sympy mappings --- pysr/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pysr/version.py b/pysr/version.py index 8a8995f2f..b127c680f 100644 --- a/pysr/version.py +++ b/pysr/version.py @@ -1,2 +1,2 @@ -__version__ = "0.16.4" +__version__ = "0.16.5" __symbolic_regression_jl_version__ = "0.22.5"