MilesCranmer commited on
Commit
6decb44
1 Parent(s): cb6939e

Put in optimizer controls

Browse files
Files changed (3) hide show
  1. Project.toml +1 -1
  2. pysr/sr.py +22 -5
  3. setup.py +1 -1
Project.toml CHANGED
@@ -2,5 +2,5 @@
2
  SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
3
 
4
  [compat]
5
- SymbolicRegression = "0.5.12"
6
  julia = "1.5"
 
2
  SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb"
3
 
4
  [compat]
5
+ SymbolicRegression = "0.5.13"
6
  julia = "1.5"
pysr/sr.py CHANGED
@@ -82,7 +82,6 @@ def pysr(X=None, y=None, weights=None,
82
  weightRandomize=1,
83
  weightSimplify=0.01,
84
  perturbationFactor=1.0,
85
- nrestarts=3,
86
  timeout=None,
87
  extra_sympy_mappings={},
88
  equation_file=None,
@@ -108,6 +107,11 @@ def pysr(X=None, y=None, weights=None,
108
  temp_equation_file=False,
109
  output_jax_format=False,
110
  warmupMaxsize=None, #Deprecated
 
 
 
 
 
111
  ):
112
  """Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
113
  Note: most default parameters have been tuned over several example
@@ -224,6 +228,10 @@ def pysr(X=None, y=None, weights=None,
224
 
225
  """
226
  assert warmupMaxsize == None, "warmupMaxsize is deprecated. Use warmupMaxsizeBy and give a fraction of time."
 
 
 
 
227
  if isinstance(X, pd.DataFrame):
228
  variable_names = list(X.columns)
229
  X = np.array(X)
@@ -257,7 +265,7 @@ def pysr(X=None, y=None, weights=None,
257
  X, y = _using_test_input(X, test, y)
258
 
259
  kwargs = dict(X=X, y=y, weights=weights,
260
- alpha=alpha, annealing=annealing, batchSize=batchSize,
261
  batching=batching, binary_operators=binary_operators,
262
  fast_cycle=fast_cycle,
263
  fractionReplaced=fractionReplaced,
@@ -267,7 +275,11 @@ def pysr(X=None, y=None, weights=None,
267
  julia_optimization=julia_optimization, timeout=timeout,
268
  fractionReplacedHof=fractionReplacedHof,
269
  hofMigration=hofMigration, maxdepth=maxdepth,
270
- maxsize=maxsize, migration=migration, nrestarts=nrestarts,
 
 
 
 
271
  parsimony=parsimony, perturbationFactor=perturbationFactor,
272
  populations=populations, procs=procs,
273
  shouldOptimizeConstants=shouldOptimizeConstants,
@@ -420,7 +432,9 @@ weights = readdlm("{_escape_filename(weights_filename)}", ',', Float32, '\\n')[:
420
 
421
  def _make_hyperparams_julia_str(X, alpha, annealing, batchSize, batching, binary_operators, constraints_str,
422
  def_hyperparams, equation_file, fast_cycle, fractionReplacedHof, hofMigration,
423
- maxdepth, maxsize, migration, nrestarts, npop,
 
 
424
  parsimony, perturbationFactor, populations, procs, shouldOptimizeConstants,
425
  unary_operators, useFrequency, use_custom_variable_names,
426
  variable_names, warmupMaxsizeBy, weightAddNode,
@@ -473,7 +487,10 @@ fractionReplacedHof={fractionReplacedHof}f0,
473
  shouldOptimizeConstants={'true' if shouldOptimizeConstants else 'false'},
474
  hofFile="{_escape_filename(equation_file)}",
475
  npopulations={populations:d},
476
- nrestarts={nrestarts:d},
 
 
 
477
  perturbationFactor={perturbationFactor:f}f0,
478
  annealing={"true" if annealing else "false"},
479
  batching={"true" if batching else "false"},
 
82
  weightRandomize=1,
83
  weightSimplify=0.01,
84
  perturbationFactor=1.0,
 
85
  timeout=None,
86
  extra_sympy_mappings={},
87
  equation_file=None,
 
107
  temp_equation_file=False,
108
  output_jax_format=False,
109
  warmupMaxsize=None, #Deprecated
110
+ nrestarts=None,
111
+ optimizer_algorithm="NelderMead",
112
+ optimizer_nrestarts=3,
113
+ optimize_probability=0.1,
114
+ optimizer_iterations=100,
115
  ):
116
  """Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
117
  Note: most default parameters have been tuned over several example
 
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
233
+ assert optimizer_algorithm in ['NelderMead', 'BFGS']
234
+
235
  if isinstance(X, pd.DataFrame):
236
  variable_names = list(X.columns)
237
  X = np.array(X)
 
265
  X, y = _using_test_input(X, test, y)
266
 
267
  kwargs = dict(X=X, y=y, weights=weights,
268
+ alpha=alpha, annealing=annealing, batchSize=batchSize,
269
  batching=batching, binary_operators=binary_operators,
270
  fast_cycle=fast_cycle,
271
  fractionReplaced=fractionReplaced,
 
275
  julia_optimization=julia_optimization, timeout=timeout,
276
  fractionReplacedHof=fractionReplacedHof,
277
  hofMigration=hofMigration, maxdepth=maxdepth,
278
+ maxsize=maxsize, migration=migration,
279
+ optimizer_algorithm=optimizer_algorithm
280
+ optimizer_nrestarts=optimizer_nrestarts
281
+ optimize_probability=optimize_probability
282
+ optimizer_iterations=optimizer_iterations
283
  parsimony=parsimony, perturbationFactor=perturbationFactor,
284
  populations=populations, procs=procs,
285
  shouldOptimizeConstants=shouldOptimizeConstants,
 
432
 
433
  def _make_hyperparams_julia_str(X, alpha, annealing, batchSize, batching, binary_operators, constraints_str,
434
  def_hyperparams, equation_file, fast_cycle, fractionReplacedHof, hofMigration,
435
+ maxdepth, maxsize, migration,
436
+ optimizer_algorithm, optimizer_nrestarts,
437
+ optimize_probability, optimizer_iterations, npop,
438
  parsimony, perturbationFactor, populations, procs, shouldOptimizeConstants,
439
  unary_operators, useFrequency, use_custom_variable_names,
440
  variable_names, warmupMaxsizeBy, weightAddNode,
 
487
  shouldOptimizeConstants={'true' if shouldOptimizeConstants else 'false'},
488
  hofFile="{_escape_filename(equation_file)}",
489
  npopulations={populations:d},
490
+ optimizer_algorithm={optimizer_algorithm},
491
+ optimizer_nrestarts={optimizer_nrestarts:d},
492
+ optimize_probability={optimize_probability:f}f0,
493
+ optimizer_iterations={optimizer_iterations:d},
494
  perturbationFactor={perturbationFactor:f}f0,
495
  annealing={"true" if annealing else "false"},
496
  batching={"true" if batching else "false"},
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",
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-1",
9
  author="Miles Cranmer",
10
  author_email="[email protected]",
11
  description="Simple and efficient symbolic regression",