Skip to main content

TuringBot Python Library

Python interface to TuringBot, a symbolic regression engine: it searches for explicit formulas that fit your data, and returns the most accurate formula found for each size.

The engine is compiled C++ and uses simulated annealing. There is no language runtime to set up and no GUI involved, so searches run the same in a notebook, over SSH or on a headless server. Input can be a CSV file, a numpy array or a pandas DataFrame.

Coming from PySR? TuringBotRegressor uses the same API as PySRRegressor.

Installation

pip install turingbot

The engine comes with the TuringBot application: download it and install it. The library needs Python 3.7 or newer and has no dependencies.

Quickstart

import time
import numpy as np
from turingbot import simulation

x = np.linspace(-3, 3, 100)
data = np.column_stack([x, 2.5 * np.sin(x) + x ** 2])  # the last column is the target

with simulation() as sim:
    sim.start_process(input_file=data, column_names=["x", "y"])
    time.sleep(10)
    sim.refresh_functions()
    for f in sim.functions:
        print(f)
[1, 3.27574, '3.0606060606060477']
[3, 1.79969, 'x*x']
[5, 1.03435, 'x*(0.8418349138360374+x)']
[8, 0.93293, 'asinh(x)+x*x']
[10, 0.0, '2.5*sin(x)+x*x']

Each line is [size, error, formula], the Pareto front of size versus error, from the simplest formula to the most accurate. Here, the last one is the formula that generated the data.

The search runs in a background process. refresh_functions() reads the current front at any time, and the search stops at terminate_process() or when the with block exits.

input_file also takes the path of a CSV or TXT file, or a pandas DataFrame; the last column is the target. TuringBot is found in its default install location; otherwise, pass its path with path=. On a Linux server, that can be the AppImage, which needs no installation.

Features

  • Custom search metrics, which can reference dataset columns, for example a weight column w: custom_metric="sum(w*pow(actual-predicted,2))/sum(w)".
  • Custom functions and constants, used as building blocks by the search: custom_functions="bump(x)=exp(-x*x)", custom_constants="g=9.81,c=299792458".
  • Time series: delay, moving_average and decay give formulas access to past values of the inputs, and with allow_target_delay=True, of the target itself.
  • GUI and command line: the same engine runs in the TuringBot desktop app and from the command line, with the same options.

Search options

sim.start_process(
    input_file="data.csv",
    search_metric=4,                       # RMS error (the default)
    allowed_functions="+ * / sin cos exp",
    train_test_split=80,                   # 80% of the rows for training, 20% for testing
    threads=4,
)

With train_test_split, each formula also has its error on the test rows: [size, error, test_error, formula].

Every option, with the IDs of the 16 search metrics: help(simulation.start_process), or the documentation.

Coming from PySR

TuringBotRegressor follows the scikit-learn API and uses PySRRegressor's names where the two match: model_selection ("best", "accuracy" or "score", with the same definitions), equations_, sympy(), max_evals and early_stop_condition. It works in pipelines, cross-validation and grid searches.

from turingbot import TuringBotRegressor

model = TuringBotRegressor(max_time=30).fit(X, y)
print(model.equations_)   # the formulas found, from the simplest to the most accurate
print(model.sympy())      # the chosen formula as a sympy expression
y_pred = model.predict(X_new)
PySRRegressor TuringBotRegressor
niterations, timeout_in_seconds max_time (seconds)
binary_operators, unary_operators allowed_functions
maxsize maximum_formula_complexity

It needs numpy. Its options are in help(TuringBotRegressor).

Citing

If you use TuringBot in your research, please cite it: CITATION.cff has the details, which GitHub also shows under "Cite this repository".

Metadata

Release files for turingbot 4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turingbot 4.0
File Size Uploaded Provenance Actions
turingbot-4.0.tar.gz 21.6 kB Without provenance Details for turingbot-4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for turingbot 4.0
File Interpreter ABI Platform Actions
turingbot-4.0-py3-none-any.whl Python 3 none any Details for turingbot-4.0-py3-none-any.whl

Total release size: 41.6 kB

Release files / turingbot-4.0.tar.gz

Download URL turingbot-4.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a2c4fdf84e62e56c0b11c8a58299b63a9dc1663459936b86200b874996330760
BLAKE2b-256 checksum
How to use checksums
11d7f5320ec6cf5f6c9387d9d587d87569908c1bdb84484f28ebdb72d400085e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / turingbot-4.0-py3-none-any.whl

Download URL turingbot-4.0-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
228cea3a4c6c799e07d6ceff82bfdbb6fe3651f90b0e1e0bd4b62449f64111e1
BLAKE2b-256 checksum
How to use checksums
481b3ccd81af02aec759b5cdf9b7690b89f19b2f9d899baf8bf77d593538667d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for turingbot 4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page