MilesCranmer commited on
Commit
b0c942c
1 Parent(s): e68c63f

Fix location of constraint-checking

Browse files
Files changed (1) hide show
  1. pysr/sr.py +11 -11
pysr/sr.py CHANGED
@@ -212,17 +212,6 @@ def pysr(X=None, y=None, weights=None,
212
  if populations is None:
213
  populations = procs
214
 
215
- #arbitrary complexity by default
216
- for op in unary_operators:
217
- if op not in constraints:
218
- constraints[op] = -1
219
- for op in binary_operators:
220
- if op not in constraints:
221
- constraints[op] = (-1, -1)
222
- if op in ['mult', 'plus', 'sub']:
223
- if constraints[op][0] != constraints[op][1]:
224
- raise NotImplementedError("You need equal constraints on both sides for +, -, and *, due to simplification strategies.")
225
-
226
  rand_string = f'{"".join([str(np.random.rand())[2] for i in range(20)])}'
227
 
228
  if isinstance(binary_operators, str): binary_operators = [binary_operators]
@@ -263,6 +252,17 @@ def pysr(X=None, y=None, weights=None,
263
  function_name = op[:first_non_char]
264
  op_list[i] = function_name
265
 
 
 
 
 
 
 
 
 
 
 
 
266
  constraints_str = "const una_constraints = ["
267
  first = True
268
  for op in unary_operators:
 
212
  if populations is None:
213
  populations = procs
214
 
 
 
 
 
 
 
 
 
 
 
 
215
  rand_string = f'{"".join([str(np.random.rand())[2] for i in range(20)])}'
216
 
217
  if isinstance(binary_operators, str): binary_operators = [binary_operators]
 
252
  function_name = op[:first_non_char]
253
  op_list[i] = function_name
254
 
255
+ #arbitrary complexity by default
256
+ for op in unary_operators:
257
+ if op not in constraints:
258
+ constraints[op] = -1
259
+ for op in binary_operators:
260
+ if op not in constraints:
261
+ constraints[op] = (-1, -1)
262
+ if op in ['mult', '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
+
266
  constraints_str = "const una_constraints = ["
267
  first = True
268
  for op in unary_operators: