turingbot 3.2.0__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2025 TuringBot Software. All rights reserved.
2
+
3
+ Permission is granted to use this software solely in conjunction with a
4
+ licensed installation of TuringBot. Redistribution, modification, or use
5
+ independent of TuringBot is not permitted without prior written consent.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
8
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
10
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
11
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
12
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13
+ SOFTWARE.
@@ -1,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: turingbot
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: Python interface for TuringBot, a symbolic regression software that discovers mathematical formulas from data
5
5
  Author: TuringBot Software
6
- License-Expression: MIT
6
+ License-Expression: LicenseRef-Proprietary
7
7
  Project-URL: Homepage, https://turingbotsoftware.com
8
8
  Project-URL: Documentation, https://turingbotsoftware.com/documentation.html
9
9
  Project-URL: Repository, https://github.com/turingbotsoftware/turingbot-python
10
10
  Project-URL: Download, https://turingbotsoftware.com/download.html
11
- Keywords: symbolic regression,symbolic regression software,machine learning,formula discovery,scientific computing,curve fitting,data science,mathematical modeling,simulated annealing
11
+ Keywords: symbolic regression,machine learning,scientific computing,simulated annealing
12
12
  Classifier: Development Status :: 5 - Production/Stable
13
13
  Classifier: Intended Audience :: Science/Research
14
14
  Classifier: Intended Audience :: Education
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  Python interface for [TuringBot](https://turingbotsoftware.com), a symbolic regression software that discovers mathematical formulas from data.
28
28
 
29
- TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 15 search metrics, train/test splits, and a wide range of mathematical functions.
29
+ TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 16 search metrics (including custom metrics), train/test splits, custom base functions, custom constants, and a wide range of mathematical functions.
30
30
 
31
31
  ## Installation
32
32
 
@@ -169,6 +169,7 @@ x1,x2,y
169
169
  | 13 | Residual sum of squares |
170
170
  | 14 | Root mean squared log error |
171
171
  | 15 | Percentile error |
172
+ | 16 | Custom metric |
172
173
 
173
174
  ## Parameters
174
175
 
@@ -181,11 +182,12 @@ See the full list of parameters in the `start_process` [docstring](https://turin
181
182
  - `normalize_dataset` -- Normalize input data
182
183
  - `allowed_functions` -- Restrict which math functions to use
183
184
  - `custom_formula` -- Provide a formula template
185
+ - `custom_constants` -- Define custom constants (e.g. `"g=9.81,c=299792458"`)
186
+ - `custom_functions` -- Define custom base functions (e.g. `"bump(x)=exp(-x*x)"`)
187
+ - `custom_metric` -- Define a custom error metric (e.g. `"mean(pow(actual-predicted,2))"`)
188
+ - `function_size` -- Override base function sizes (e.g. `"sin:3 cos:3 pow:5"`)
184
189
 
185
190
  ## Documentation
186
191
 
187
192
  Full documentation: [turingbotsoftware.com/documentation.html](https://turingbotsoftware.com/documentation.html)
188
193
 
189
- ## License
190
-
191
- MIT
@@ -2,7 +2,7 @@
2
2
 
3
3
  Python interface for [TuringBot](https://turingbotsoftware.com), a symbolic regression software that discovers mathematical formulas from data.
4
4
 
5
- TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 15 search metrics, train/test splits, and a wide range of mathematical functions.
5
+ TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 16 search metrics (including custom metrics), train/test splits, custom base functions, custom constants, and a wide range of mathematical functions.
6
6
 
7
7
  ## Installation
8
8
 
@@ -145,6 +145,7 @@ x1,x2,y
145
145
  | 13 | Residual sum of squares |
146
146
  | 14 | Root mean squared log error |
147
147
  | 15 | Percentile error |
148
+ | 16 | Custom metric |
148
149
 
149
150
  ## Parameters
150
151
 
@@ -157,11 +158,12 @@ See the full list of parameters in the `start_process` [docstring](https://turin
157
158
  - `normalize_dataset` -- Normalize input data
158
159
  - `allowed_functions` -- Restrict which math functions to use
159
160
  - `custom_formula` -- Provide a formula template
161
+ - `custom_constants` -- Define custom constants (e.g. `"g=9.81,c=299792458"`)
162
+ - `custom_functions` -- Define custom base functions (e.g. `"bump(x)=exp(-x*x)"`)
163
+ - `custom_metric` -- Define a custom error metric (e.g. `"mean(pow(actual-predicted,2))"`)
164
+ - `function_size` -- Override base function sizes (e.g. `"sin:3 cos:3 pow:5"`)
160
165
 
161
166
  ## Documentation
162
167
 
163
168
  Full documentation: [turingbotsoftware.com/documentation.html](https://turingbotsoftware.com/documentation.html)
164
169
 
165
- ## License
166
-
167
- MIT
@@ -4,23 +4,18 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "turingbot"
7
- version = "3.2.0"
7
+ version = "3.3.0"
8
8
  description = "Python interface for TuringBot, a symbolic regression software that discovers mathematical formulas from data"
9
9
  readme = "README.md"
10
- license = "MIT"
10
+ license = "LicenseRef-Proprietary"
11
11
  requires-python = ">=3.7"
12
12
  authors = [
13
13
  {name = "TuringBot Software"},
14
14
  ]
15
15
  keywords = [
16
16
  "symbolic regression",
17
- "symbolic regression software",
18
17
  "machine learning",
19
- "formula discovery",
20
18
  "scientific computing",
21
- "curve fitting",
22
- "data science",
23
- "mathematical modeling",
24
19
  "simulated annealing",
25
20
  ]
26
21
  classifiers = [
@@ -1,4 +1,4 @@
1
1
  from .turingbot import simulation, find_executable
2
2
 
3
- __version__ = "3.2.0"
3
+ __version__ = "3.3.0"
4
4
  __all__ = ["simulation", "find_executable"]
@@ -1,6 +1,5 @@
1
1
  import os
2
2
  import platform
3
- import random
4
3
  import shutil
5
4
  import subprocess
6
5
  import tempfile
@@ -55,6 +54,7 @@ def _save_array_to_csv(data, column_names=None):
55
54
  # pandas DataFrame
56
55
  if hasattr(data, "to_csv"):
57
56
  os.close(fd)
57
+ fd = None
58
58
  data.to_csv(path, index=False)
59
59
  return path
60
60
 
@@ -68,6 +68,7 @@ def _save_array_to_csv(data, column_names=None):
68
68
  )
69
69
 
70
70
  os.close(fd)
71
+ fd = None
71
72
  header = ""
72
73
  if column_names is not None:
73
74
  if len(column_names) != data.shape[1]:
@@ -80,6 +81,8 @@ def _save_array_to_csv(data, column_names=None):
80
81
  np.savetxt(path, data, delimiter=",", header=header, comments="")
81
82
  return path
82
83
  except Exception:
84
+ if fd is not None:
85
+ os.close(fd)
83
86
  if os.path.exists(path):
84
87
  os.remove(path)
85
88
  raise
@@ -99,12 +102,23 @@ class simulation:
99
102
  functions = []
100
103
  self.info = lines[0].strip()
101
104
 
105
+ # Determine column layout from header (lines[1] is the actual header;
106
+ # lines[0] is the "Formulas generated:" info line)
107
+ header_fields = lines[1].strip().split()
108
+ has_test_error = "Test_Error" in header_fields
109
+ func_idx = 3 if has_test_error else 2
110
+
102
111
  for i in range(2, len(lines)):
103
- functions.append(lines[i].strip().split())
104
- functions[-1][0] = int(functions[-1][0])
105
- functions[-1][1] = float(functions[-1][1])
106
- if len(functions[-1]) == 4:
107
- functions[-1][2] = float(functions[-1][2])
112
+ parts = lines[i].strip().split()
113
+ if not parts or len(parts) <= func_idx:
114
+ continue
115
+
116
+ entry = [int(parts[0]), float(parts[1])]
117
+ if has_test_error:
118
+ entry.append(float(parts[2]))
119
+ entry.append(parts[func_idx])
120
+
121
+ functions.append(entry)
108
122
 
109
123
  return functions
110
124
 
@@ -137,7 +151,11 @@ class simulation:
137
151
  allow_target_delay: bool = False,
138
152
  force_all_variables: bool = False,
139
153
  custom_formula: str = None,
140
- allowed_functions: str = None,
154
+ custom_constants: str = None,
155
+ custom_functions: str = None,
156
+ custom_metric: str = None,
157
+ allowed_functions=None,
158
+ function_size: str = None,
141
159
  ):
142
160
  """
143
161
  Start the process with the specified configuration and dataset.
@@ -183,6 +201,7 @@ class simulation:
183
201
  13: Residual sum of squares (RSS)
184
202
  14: Root mean squared log error (RMSLE)
185
203
  15: Percentile error
204
+ 16: Custom metric (requires custom_metric parameter)
186
205
  train_test_split : int, optional
187
206
  Train/test split. Default is -1 (no test sample).
188
207
  Options:
@@ -201,8 +220,8 @@ class simulation:
201
220
  Whether to use bound search mode. Default is 0 (deactivated).
202
221
  Options:
203
222
  0: Deactivated (default)
204
- 1: Lower bound search
205
- 2: Upper bound search
223
+ 1: Upper bound search
224
+ 2: Lower bound search
206
225
  maximum_formula_complexity : int, optional
207
226
  Maximum formula complexity. Default is 60.
208
227
  history_size : int, optional
@@ -231,12 +250,47 @@ class simulation:
231
250
  Whether to force the solution to include all input variables. Default is False (not forced).
232
251
  custom_formula : str, optional
233
252
  Custom formula for the search. If not provided, the last column will be treated as the target variable.
234
- allowed_functions : str, optional
235
- Allowed functions for the formula search. Default: "+ * / pow fmod sin cos tan asin acos atan exp log log2 log10 sqrt sinh cosh tanh asinh acosh atanh abs floor ceil round sign tgamma lgamma erf"
253
+ custom_constants : str, optional
254
+ Custom constants, comma-separated name=value pairs. Add |cost
255
+ after the value to set complexity (default: 1). Examples:
256
+ "k=1.380649e-23,h=6.62607e-34"
257
+ "sun=1.989e30|7" (complexity 7)
258
+ custom_functions : str, optional
259
+ Custom base functions, comma-separated. One argument = unary,
260
+ two = binary. Add |cost after the expression to set complexity
261
+ (default: 4). Examples:
262
+ "bump(x)=exp(-x*x)"
263
+ "mydist(x,y)=sqrt(x*x+y*y)"
264
+ "gauss(x)=exp(-x*x)|2" (complexity 2)
265
+ custom_metric : str, optional
266
+ Custom search metric formula. Automatically sets search_metric
267
+ to 16.
268
+ 'actual' and 'predicted' give per-row values and must be
269
+ inside sum(), mean(), median(), maxval(), or minval():
270
+ "mean(pow(actual-predicted,2))"
271
+ "sqrt(mean(pow(actual-predicted,2)))"
272
+ "maxval(abs(actual-predicted))"
273
+ Built-in metrics (rms, mae, mre, maxerr, maxre, accuracy,
274
+ correlation, nash, logloss, mcc_val, rss, rmsle, n) can
275
+ be used directly:
276
+ "0.5*rms+0.5*mae"
277
+ allowed_functions : str or list of str, optional
278
+ Allowed functions for the formula search, as a list of strings
279
+ (e.g. ["+", "sin", "cos"]) or a single string (e.g. "+ sin cos").
280
+ Default: all functions.
281
+ function_size : str, optional
282
+ Override size of base functions. Format: space-separated
283
+ name:size pairs. Only overrides need to be specified; unspecified
284
+ functions keep their defaults. Example: "sin:3 cos:3 pow:5 /:3"
236
285
  """
237
286
 
238
287
  self.functions = []
239
288
 
289
+ # Terminate any previous process and clean up its temp files
290
+ # before overwriting state with new paths
291
+ if self.process is not None:
292
+ self.terminate_process()
293
+
240
294
  if input_file is None:
241
295
  raise ValueError("input_file is required.")
242
296
 
@@ -270,27 +324,20 @@ class simulation:
270
324
  path = f'"{path}"'
271
325
  input_file = f'"{input_file}"'
272
326
  if outfile is None:
273
- if os.name == "nt":
274
- self._outfile = tempfile.gettempdir() + r"\turingbot_%d.txt" % random.randint(1000000000, 9999999999)
275
- else:
276
- self._outfile = tempfile.gettempdir() + "/turingbot_%d.txt" % random.randint(1000000000, 9999999999)
327
+ fd, self._outfile = tempfile.mkstemp(suffix=".txt", prefix="turingbot_")
328
+ os.close(fd)
277
329
  self._outfile_is_temp = True
278
330
  else:
279
331
  self._outfile = outfile
280
332
  self._outfile_is_temp = False
281
333
 
282
- if self.process is not None:
283
- self.process.kill()
284
-
285
334
  if os.name == "nt":
286
- cmd = f"{path} {input_file} --outfile {self._outfile}"
287
- elif os.name == "posix":
288
- cmd = f"exec {path} {input_file} --outfile {self._outfile} 1>/dev/null 2>/dev/null"
335
+ cmd = f'{path} {input_file} --outfile "{self._outfile}"'
289
336
  else:
290
- cmd = f"exec stdbuf -oL {path} {input_file} --outfile {self._outfile} 1>/dev/null 2>/dev/null"
337
+ cmd = f'exec {path} {input_file} --outfile "{self._outfile}" 1>/dev/null'
291
338
 
292
339
  if config is not None:
293
- cmd = f"{cmd} {config}"
340
+ cmd = f'{cmd} "{config}"'
294
341
  else:
295
342
  if search_metric is not None:
296
343
  cmd = f"{cmd} --search-metric {search_metric}"
@@ -330,17 +377,27 @@ class simulation:
330
377
  cmd = f"{cmd} --force-all-variables"
331
378
  if custom_formula is not None:
332
379
  cmd = f"{cmd} --custom-formula \"{custom_formula}\""
380
+ if custom_constants is not None:
381
+ cmd = f'{cmd} --custom-constants "{custom_constants}"'
382
+ if custom_functions is not None:
383
+ cmd = f'{cmd} --custom-functions "{custom_functions}"'
384
+ if custom_metric is not None:
385
+ cmd = f'{cmd} --custom-metric "{custom_metric}"'
333
386
  if allowed_functions is not None:
387
+ if isinstance(allowed_functions, list):
388
+ allowed_functions = " ".join(allowed_functions)
334
389
  cmd = f"{cmd} --allowed-functions \"{allowed_functions}\""
390
+ if function_size is not None:
391
+ cmd = f'{cmd} --function-size "{function_size}"'
335
392
 
336
393
  if threads is not None:
337
394
  cmd = f"{cmd} --threads {int(threads)}"
338
395
 
339
396
  if predictions_file is not None:
340
- cmd = f"{cmd} --predictions-file {predictions_file}"
397
+ cmd = f'{cmd} --predictions-file "{predictions_file}"'
341
398
 
342
399
  if formulas_file is not None:
343
- cmd = f"{cmd} --formulas-file {formulas_file}"
400
+ cmd = f'{cmd} --formulas-file "{formulas_file}"'
344
401
 
345
402
  cmd = f"{cmd} --library-parent-id {str(os.getpid())}"
346
403
 
@@ -348,7 +405,6 @@ class simulation:
348
405
  self.process = subprocess.Popen(
349
406
  cmd,
350
407
  stdout=subprocess.DEVNULL,
351
- stderr=subprocess.DEVNULL
352
408
  )
353
409
  else:
354
410
  self.process = subprocess.Popen(
@@ -363,7 +419,7 @@ class simulation:
363
419
  with open(self._outfile, "r") as f:
364
420
  lines = f.readlines()
365
421
 
366
- if len(lines) > 0:
422
+ if len(lines) >= 2:
367
423
  self.functions = self.parse_lines(lines)
368
424
 
369
425
  def terminate_process(self):
@@ -1,14 +1,14 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: turingbot
3
- Version: 3.2.0
3
+ Version: 3.3.0
4
4
  Summary: Python interface for TuringBot, a symbolic regression software that discovers mathematical formulas from data
5
5
  Author: TuringBot Software
6
- License-Expression: MIT
6
+ License-Expression: LicenseRef-Proprietary
7
7
  Project-URL: Homepage, https://turingbotsoftware.com
8
8
  Project-URL: Documentation, https://turingbotsoftware.com/documentation.html
9
9
  Project-URL: Repository, https://github.com/turingbotsoftware/turingbot-python
10
10
  Project-URL: Download, https://turingbotsoftware.com/download.html
11
- Keywords: symbolic regression,symbolic regression software,machine learning,formula discovery,scientific computing,curve fitting,data science,mathematical modeling,simulated annealing
11
+ Keywords: symbolic regression,machine learning,scientific computing,simulated annealing
12
12
  Classifier: Development Status :: 5 - Production/Stable
13
13
  Classifier: Intended Audience :: Science/Research
14
14
  Classifier: Intended Audience :: Education
@@ -26,7 +26,7 @@ Dynamic: license-file
26
26
 
27
27
  Python interface for [TuringBot](https://turingbotsoftware.com), a symbolic regression software that discovers mathematical formulas from data.
28
28
 
29
- TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 15 search metrics, train/test splits, and a wide range of mathematical functions.
29
+ TuringBot uses simulated annealing to search the space of possible mathematical expressions, finding accurate and compact formulas that describe your data. It supports 16 search metrics (including custom metrics), train/test splits, custom base functions, custom constants, and a wide range of mathematical functions.
30
30
 
31
31
  ## Installation
32
32
 
@@ -169,6 +169,7 @@ x1,x2,y
169
169
  | 13 | Residual sum of squares |
170
170
  | 14 | Root mean squared log error |
171
171
  | 15 | Percentile error |
172
+ | 16 | Custom metric |
172
173
 
173
174
  ## Parameters
174
175
 
@@ -181,11 +182,12 @@ See the full list of parameters in the `start_process` [docstring](https://turin
181
182
  - `normalize_dataset` -- Normalize input data
182
183
  - `allowed_functions` -- Restrict which math functions to use
183
184
  - `custom_formula` -- Provide a formula template
185
+ - `custom_constants` -- Define custom constants (e.g. `"g=9.81,c=299792458"`)
186
+ - `custom_functions` -- Define custom base functions (e.g. `"bump(x)=exp(-x*x)"`)
187
+ - `custom_metric` -- Define a custom error metric (e.g. `"mean(pow(actual-predicted,2))"`)
188
+ - `function_size` -- Override base function sizes (e.g. `"sin:3 cos:3 pow:5"`)
184
189
 
185
190
  ## Documentation
186
191
 
187
192
  Full documentation: [turingbotsoftware.com/documentation.html](https://turingbotsoftware.com/documentation.html)
188
193
 
189
- ## License
190
-
191
- MIT
turingbot-3.2.0/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 TuringBot Software
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
File without changes