MilesCranmer commited on
Commit
436d629
1 Parent(s): 7f2ee62

Fix mutable default arguments

Browse files
Files changed (2) hide show
  1. pysr/sr.py +18 -6
  2. setup.py +1 -1
pysr/sr.py CHANGED
@@ -56,8 +56,8 @@ sympy_mappings = {
56
  }
57
 
58
  def pysr(X=None, y=None, weights=None,
59
- binary_operators=["plus", "mult"],
60
- unary_operators=["cos", "exp", "sin"],
61
  procs=4,
62
  loss='L2DistLoss()',
63
  populations=None,
@@ -83,7 +83,7 @@ def pysr(X=None, y=None, weights=None,
83
  weightSimplify=0.01,
84
  perturbationFactor=1.0,
85
  timeout=None,
86
- extra_sympy_mappings={},
87
  equation_file=None,
88
  test='simple1',
89
  verbosity=1e9,
@@ -91,12 +91,12 @@ def pysr(X=None, y=None, weights=None,
91
  maxsize=20,
92
  fast_cycle=False,
93
  maxdepth=None,
94
- variable_names=[],
95
  batching=False,
96
  batchSize=50,
97
  select_k_features=None,
98
  warmupMaxsizeBy=0.0,
99
- constraints={},
100
  useFrequency=False,
101
  tempdir=None,
102
  delete_tempfiles=True,
@@ -125,8 +125,9 @@ def pysr(X=None, y=None, weights=None,
125
  :param weights: np.ndarray, 1D array. Each row is how to weight the
126
  mean-square-error loss on weights.
127
  :param binary_operators: list, List of strings giving the binary operators
128
- in Julia's Base.
129
  :param unary_operators: list, Same but for operators taking a single scalar.
 
130
  :param procs: int, Number of processes (=number of populations running).
131
  :param loss: str, String of Julia code specifying the loss function.
132
  Can either be a loss from LossFunctions.jl, or your own
@@ -227,6 +228,17 @@ def pysr(X=None, y=None, weights=None,
227
  (as strings).
228
 
229
  """
 
 
 
 
 
 
 
 
 
 
 
230
  assert warmupMaxsize == None, "warmupMaxsize is deprecated. Use warmupMaxsizeBy and give a fraction of time."
231
  if nrestarts != None:
232
  optimizer_nrestarts = nrestarts
 
56
  }
57
 
58
  def pysr(X=None, y=None, weights=None,
59
+ binary_operators=None,
60
+ unary_operators=None,
61
  procs=4,
62
  loss='L2DistLoss()',
63
  populations=None,
 
83
  weightSimplify=0.01,
84
  perturbationFactor=1.0,
85
  timeout=None,
86
+ extra_sympy_mappings=None,
87
  equation_file=None,
88
  test='simple1',
89
  verbosity=1e9,
 
91
  maxsize=20,
92
  fast_cycle=False,
93
  maxdepth=None,
94
+ variable_names=None,
95
  batching=False,
96
  batchSize=50,
97
  select_k_features=None,
98
  warmupMaxsizeBy=0.0,
99
+ constraints=None,
100
  useFrequency=False,
101
  tempdir=None,
102
  delete_tempfiles=True,
 
125
  :param weights: np.ndarray, 1D array. Each row is how to weight the
126
  mean-square-error loss on weights.
127
  :param binary_operators: list, List of strings giving the binary operators
128
+ in Julia's Base. Default is ["plus", "mult"].
129
  :param unary_operators: list, Same but for operators taking a single scalar.
130
+ Default is ["cos", "exp", "sin"].
131
  :param procs: int, Number of processes (=number of populations running).
132
  :param loss: str, String of Julia code specifying the loss function.
133
  Can either be a loss from LossFunctions.jl, or your own
 
228
  (as strings).
229
 
230
  """
231
+ if binary_operators is None:
232
+ binary_operators = ["plus", "mult"]
233
+ if unary_operators is None:
234
+ unary_operators = ["cos", "exp", "sin"]
235
+ if extra_sympy_mappings is None:
236
+ extra_sympy_mappings = {}
237
+ if variable_names is None:
238
+ variable_names = []
239
+ if constraints is None:
240
+ constraints = {}
241
+
242
  assert warmupMaxsize == None, "warmupMaxsize is deprecated. Use warmupMaxsizeBy and give a fraction of time."
243
  if nrestarts != None:
244
  optimizer_nrestarts = nrestarts
setup.py CHANGED
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
 
6
  setuptools.setup(
7
  name="pysr", # Replace with your own username
8
- version="0.5.13-1",
9
  author="Miles Cranmer",
10
  author_email="[email protected]",
11
  description="Simple and efficient symbolic regression",
 
5
 
6
  setuptools.setup(
7
  name="pysr", # Replace with your own username
8
+ version="0.5.13-2",
9
  author="Miles Cranmer",
10
  author_email="[email protected]",
11
  description="Simple and efficient symbolic regression",