MilesCranmer commited on
Commit
609b9fc
1 Parent(s): e0a69cb

Allow user to put equation file in temp directory

Browse files
Files changed (1) hide show
  1. pysr/sr.py +17 -5
pysr/sr.py CHANGED
@@ -104,7 +104,8 @@ def pysr(X=None, y=None, weights=None,
104
  julia_optimization=3,
105
  julia_project=None,
106
  user_input=True,
107
- update=True
 
108
  ):
109
  """Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
110
  Note: most default parameters have been tuned over several example
@@ -208,6 +209,10 @@ def pysr(X=None, y=None, weights=None,
208
  should be present from the install.
209
  :param user_input: Whether to ask for user input or not for installing (to
210
  be used for automated scripts). Will choose to install when asked.
 
 
 
 
211
  :returns: pd.DataFrame, Results dataframe, giving complexity, MSE, and equations
212
  (as strings).
213
 
@@ -235,9 +240,6 @@ def pysr(X=None, y=None, weights=None,
235
 
236
  if maxdepth is None:
237
  maxdepth = maxsize
238
- if equation_file is None:
239
- date_time = datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")[:-3]
240
- equation_file = 'hall_of_fame_' + date_time + '.csv'
241
  if populations is None:
242
  populations = procs
243
  if isinstance(binary_operators, str):
@@ -250,7 +252,7 @@ def pysr(X=None, y=None, weights=None,
250
  kwargs = dict(X=X, y=y, weights=weights,
251
  alpha=alpha, annealing=annealing, batchSize=batchSize,
252
  batching=batching, binary_operators=binary_operators,
253
- equation_file=equation_file, fast_cycle=fast_cycle,
254
  fractionReplaced=fractionReplaced,
255
  ncyclesperiteration=ncyclesperiteration,
256
  niterations=niterations, npop=npop,
@@ -279,6 +281,16 @@ def pysr(X=None, y=None, weights=None,
279
 
280
  kwargs = {**_set_paths(tempdir), **kwargs}
281
 
 
 
 
 
 
 
 
 
 
 
282
  pkg_directory = kwargs['pkg_directory']
283
  kwargs['need_install'] = False
284
  if not (pkg_directory / 'Manifest.toml').is_file():
 
104
  julia_optimization=3,
105
  julia_project=None,
106
  user_input=True,
107
+ update=True,
108
+ temp_equation_file=False
109
  ):
110
  """Run symbolic regression to fit f(X[i, :]) ~ y[i] for all i.
111
  Note: most default parameters have been tuned over several example
 
209
  should be present from the install.
210
  :param user_input: Whether to ask for user input or not for installing (to
211
  be used for automated scripts). Will choose to install when asked.
212
+ :param update: Whether to automatically update Julia packages.
213
+ :param temp_equation_file: Whether to put the hall of fame file in
214
+ the temp directory. Deletion is then controlled with the
215
+ delete_tempfiles argument.
216
  :returns: pd.DataFrame, Results dataframe, giving complexity, MSE, and equations
217
  (as strings).
218
 
 
240
 
241
  if maxdepth is None:
242
  maxdepth = maxsize
 
 
 
243
  if populations is None:
244
  populations = procs
245
  if isinstance(binary_operators, str):
 
252
  kwargs = dict(X=X, y=y, weights=weights,
253
  alpha=alpha, annealing=annealing, batchSize=batchSize,
254
  batching=batching, binary_operators=binary_operators,
255
+ fast_cycle=fast_cycle,
256
  fractionReplaced=fractionReplaced,
257
  ncyclesperiteration=ncyclesperiteration,
258
  niterations=niterations, npop=npop,
 
281
 
282
  kwargs = {**_set_paths(tempdir), **kwargs}
283
 
284
+ if equation_file is None:
285
+ if temp_equation_file:
286
+ equation_file = kwargs['tmpdir'] / f'hall_of_fame.csv'
287
+ else:
288
+ date_time = datetime.now().strftime("%Y-%m-%d_%H%M%S.%f")[:-3]
289
+ equation_file = 'hall_of_fame_' + date_time + '.csv'
290
+
291
+ kwargs = {**dict(equation_file=equation_file), **kwargs}
292
+
293
+
294
  pkg_directory = kwargs['pkg_directory']
295
  kwargs['need_install'] = False
296
  if not (pkg_directory / 'Manifest.toml').is_file():