Spaces:
Sleeping
Sleeping
MilesCranmer
commited on
Commit
•
17d8a3e
1
Parent(s):
ccdbeb5
Allow for different mult complexity on each side
Browse files- julia/sr.jl +1 -1
- pysr/sr.py +8 -2
julia/sr.jl
CHANGED
@@ -548,7 +548,7 @@ function combineOperators(tree::Node)::Node
|
|
548 |
top_level_constant = tree.degree == 2 && (tree.l.constant || tree.r.constant)
|
549 |
if tree.degree == 2 && (binops[tree.op] === mult || binops[tree.op] === plus) && top_level_constant
|
550 |
op = tree.op
|
551 |
-
# Put the constant in r
|
552 |
if tree.l.constant
|
553 |
tmp = tree.r
|
554 |
tree.r = tree.l
|
|
|
548 |
top_level_constant = tree.degree == 2 && (tree.l.constant || tree.r.constant)
|
549 |
if tree.degree == 2 && (binops[tree.op] === mult || binops[tree.op] === plus) && top_level_constant
|
550 |
op = tree.op
|
551 |
+
# Put the constant in r. Need to assume var in left for simplification assumption.
|
552 |
if tree.l.constant
|
553 |
tmp = tree.r
|
554 |
tree.r = tree.l
|
pysr/sr.py
CHANGED
@@ -259,9 +259,15 @@ def pysr(X=None, y=None, weights=None,
|
|
259 |
for op in binary_operators:
|
260 |
if op not in constraints:
|
261 |
constraints[op] = (-1, -1)
|
262 |
-
if op in ['
|
263 |
if constraints[op][0] != constraints[op][1]:
|
264 |
-
raise NotImplementedError("You need equal constraints on both sides for
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
|
266 |
constraints_str = "const una_constraints = ["
|
267 |
first = True
|
|
|
259 |
for op in binary_operators:
|
260 |
if op not in constraints:
|
261 |
constraints[op] = (-1, -1)
|
262 |
+
if op in ['plus', 'sub']:
|
263 |
if constraints[op][0] != constraints[op][1]:
|
264 |
+
raise NotImplementedError("You need equal constraints on both sides for - and *, due to simplification strategies.")
|
265 |
+
elif op == 'mult':
|
266 |
+
# Make sure the complex expression is in the left side.
|
267 |
+
if constraints[op][0] == -1:
|
268 |
+
continue
|
269 |
+
elif constraints[op][1] == -1 or constraints[op][0] < constraints[op][1]:
|
270 |
+
constraints[op][0], constraints[op][1] = constraints[op][1], constraints[op][0]
|
271 |
|
272 |
constraints_str = "const una_constraints = ["
|
273 |
first = True
|