Prediction-error learning for optimization. Every experiment makes the brain smarter.
Project description
theorist
Prediction-error optimization for Python. One file. Zero dependencies.
Most optimization loops try things and keep what works. Theorist does one thing differently: it guesses first. The prediction error is the learning signal.
predict → run → surprise → learn → transfer
What is Theorist?
A first-principles approach to optimization. Instead of blindly searching, Theorist forces a prediction before each experiment and learns from the error. It builds a theory of why things work — not just what works — and transfers that understanding across tasks.
- No dependencies — pure Python, single file
- No LLM or API keys required — the prediction-error loop runs locally
- Cross-domain transfer — what it learns on one task makes the next task faster
- Drop-in replacement for random search or grid search with better sample efficiency
How is this different from Optuna / Ray Tune / Bayesian optimization?
Those tools model what works. Theorist models why it works, by forcing a prediction before each experiment and learning from the error. This means:
- It transfers knowledge across different optimization tasks
- It adapts immediately when the problem changes (e.g., more compute, different dataset)
- It gets better at predicting, not just searching — understanding instead of memorizing
In our experiments, this approach adapted to a 5x compute shift on the first try. Traditional search had to start over. The same pattern that makes autonomous AI agents fragile — optimizing without understanding — is what makes most hyperparameter tools plateau.
Install
pip install theorist
Or just copy theorist.py into your project. It's one file, ~170 lines of logic.
Quick start
import theorist
@theorist.experiment(
search_space={"lr": [1e-4, 1e-3, 1e-2], "layers": [2, 4, 8]},
metric="val_loss",
minimize=True,
)
def train(config):
return {"val_loss": run_training(**config)}
results = train.optimize(n=20)
Brain persists at ~/.theorist/. Second task starts smarter.
Cross-domain transfer
@theorist.experiment(search_space={...}, metric="loss", domain="training")
def task1(config): ...
@theorist.experiment(search_space={...}, metric="loss", domain="inference")
def task2(config): ...
task1.optimize(n=20)
task2.optimize(n=20) # starts smarter — transfers what it learned
Compare vs random search
from theorist import compare
compare(fn=train, space={...}, n=20, metric="loss")
Brain
from theorist import Brain
brain = Brain()
print(brain.summary())
brain.reset()
Origin
This is the SDK version of the prediction-error loop from epistemic-autoresearch.
251 experiments across three autonomous agent types (blind search, reflection, prediction-error). The predicting agent adapted to a 5x compute shift on its first try. The reflecting agent took 7 tries. The searching agent never caught up.
The core insight: an autonomous agent that predicts before it acts builds real understanding. One that only reacts builds nothing. This is why most AI agents are fragile — they optimize without reasoning from first principles.
Theorist packages that loop so any optimization problem can use it.
Research
- Paper + experiments: epistemic-autoresearch
- Previous study: barcaui-predicted-karpathy
License
MIT — Johan David Bonilla
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file theorist-0.1.0.tar.gz.
File metadata
- Download URL: theorist-0.1.0.tar.gz
- Upload date:
- Size: 21.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ac48fce7d4d26a1a7bf05ea3d16cfc3e888764cb2eb9156cabfe14022bf03f1
|
|
| MD5 |
cf56a4dec4b48403520798568bdcfdf1
|
|
| BLAKE2b-256 |
396dbc95354d4c082fc6eb73ec8c0aae33ccde07975c5031ba3734d3d994e0a1
|
File details
Details for the file theorist-0.1.0-py3-none-any.whl.
File metadata
- Download URL: theorist-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e92d628bf43f02de7ac83ab30ea84bb840da2d4db1e0f577544fb8c8ce193cab
|
|
| MD5 |
76e97bb75254d43a9258ec248d44412a
|
|
| BLAKE2b-256 |
23b906dbe686a52f677318c34a2e72d03209fc31d81228cd6b0e5b1782218cd1
|