basin-sr 0.1.0__py3-none-any.whl
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.
- basin/__init__.py +87 -0
- basin/core.py +380 -0
- basin/version.py +1 -0
- basin_sr-0.1.0.dist-info/METADATA +767 -0
- basin_sr-0.1.0.dist-info/RECORD +7 -0
- basin_sr-0.1.0.dist-info/WHEEL +4 -0
- basin_sr-0.1.0.dist-info/licenses/LICENSE +21 -0
basin/__init__.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""basin: a law finder for tables of measurements.
|
|
2
|
+
|
|
3
|
+
BACON proposes terms (including fractional powers), sparse regression builds candidate
|
|
4
|
+
laws y = N(x)/D(x), and cross-validation decides between them.
|
|
5
|
+
|
|
6
|
+
>>> import numpy as np, basin
|
|
7
|
+
>>> law = basin.discover(X, y, ["M1", "T1", "M2", "T2"])
|
|
8
|
+
|
|
9
|
+
The method itself lives in `basin.core`, unchanged from the benchmarked version; its
|
|
10
|
+
module-level switches (`POWER_FREE`, `POWER_DENOMINATORS`, ...) can be changed for one
|
|
11
|
+
call with `basin.settings(...)`.
|
|
12
|
+
"""
|
|
13
|
+
from contextlib import contextmanager
|
|
14
|
+
|
|
15
|
+
import sympy as sp
|
|
16
|
+
|
|
17
|
+
from basin import core
|
|
18
|
+
from basin.core import PARAMS, propose_powers, term_list
|
|
19
|
+
from basin.version import __version__
|
|
20
|
+
|
|
21
|
+
__all__ = ["discover", "settings", "propose_powers", "term_list", "core", "PARAMS",
|
|
22
|
+
"SWITCHES", "__version__"]
|
|
23
|
+
|
|
24
|
+
# Settings that `settings()` may change. Their defaults are the benchmark version.
|
|
25
|
+
SWITCHES = ("MAX_FREE", "EXHAUSTIVE_TERMS", "SCREEN_KEEP", "POWER_SE", "POWER_FLOOR",
|
|
26
|
+
"POWER_KEEP", "CV_FLOOR", "FOLDS", "REPEATS", "CV_SEED", "POWER_DENOMINATORS",
|
|
27
|
+
"POWER_FREE", "POWER_FREE_DIGITS")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _symbols(symbols, n):
|
|
31
|
+
if symbols is None:
|
|
32
|
+
return [sp.Symbol(f"x{i}", positive=True) for i in range(n)]
|
|
33
|
+
if len(symbols) != n:
|
|
34
|
+
raise ValueError(f"{len(symbols)} names given for {n} input columns")
|
|
35
|
+
return [s if isinstance(s, sp.Symbol) else sp.Symbol(str(s), positive=True)
|
|
36
|
+
for s in symbols]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def discover(X, y, symbols=None, details=False):
|
|
40
|
+
"""Find a law y = N(x)/D(x) for a table of measurements.
|
|
41
|
+
|
|
42
|
+
Parameters
|
|
43
|
+
----------
|
|
44
|
+
X : array-like, shape (n_rows, n_inputs)
|
|
45
|
+
One row per measurement, one column per input.
|
|
46
|
+
y : array-like, shape (n_rows,)
|
|
47
|
+
The measured output.
|
|
48
|
+
symbols : list of str or sympy.Symbol, optional
|
|
49
|
+
Names of the inputs. Strings become positive sympy symbols. Default x0, x1, ...
|
|
50
|
+
details : bool
|
|
51
|
+
If True, also return a dict with the proposed powers, their estimates, the size of
|
|
52
|
+
the term list, the number of candidate laws and the chosen law's CV error.
|
|
53
|
+
|
|
54
|
+
Returns
|
|
55
|
+
-------
|
|
56
|
+
sympy.Expr, or (sympy.Expr, dict) if details=True. None (or (None, {})) if no
|
|
57
|
+
candidate law could be fitted.
|
|
58
|
+
"""
|
|
59
|
+
import numpy as np
|
|
60
|
+
|
|
61
|
+
X = np.asarray(X, dtype=float)
|
|
62
|
+
if X.ndim == 1:
|
|
63
|
+
X = X[:, None]
|
|
64
|
+
return core.discover(X, y, _symbols(symbols, X.shape[1]), details=details)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@contextmanager
|
|
68
|
+
def settings(**switches):
|
|
69
|
+
"""Temporarily change the method's switches, e.g.
|
|
70
|
+
|
|
71
|
+
with basin.settings(POWER_FREE=True):
|
|
72
|
+
law = basin.discover(X, y, names)
|
|
73
|
+
|
|
74
|
+
The previous values are restored on exit. Not thread-safe (the switches are module
|
|
75
|
+
globals, as in the benchmarked code).
|
|
76
|
+
"""
|
|
77
|
+
unknown = set(switches) - set(SWITCHES)
|
|
78
|
+
if unknown:
|
|
79
|
+
raise ValueError(f"unknown switch(es): {sorted(unknown)}; known: {list(SWITCHES)}")
|
|
80
|
+
old = {k: getattr(core, k) for k in switches}
|
|
81
|
+
try:
|
|
82
|
+
for k, v in switches.items():
|
|
83
|
+
setattr(core, k, v)
|
|
84
|
+
yield
|
|
85
|
+
finally:
|
|
86
|
+
for k, v in old.items():
|
|
87
|
+
setattr(core, k, v)
|
basin/core.py
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
"""Hybrid law finder: BACON proposes terms, sparse regression decides (Test 13 on).
|
|
2
|
+
|
|
3
|
+
Built from what Tests 1-12 showed: PySINDy decides well (one fit on all the data) but can
|
|
4
|
+
only find laws inside its fixed term list; BACON can build the terms real laws need
|
|
5
|
+
(powers like 2/3, sums like L + 3 in a denominator) but decides with yes/no tolerance
|
|
6
|
+
tests on small slices, which break under noise.
|
|
7
|
+
|
|
8
|
+
target y, inputs x_1..x_n (all rows used at every step)
|
|
9
|
+
|
|
10
|
+
1. Propose powers, BACON's way. For each input x_j, use the experiment's structure: rows
|
|
11
|
+
that share the values of every other input form a slice. Fit
|
|
12
|
+
log|y| = (one intercept per slice) + p_j log x_j
|
|
13
|
+
on all slices at once, which gives p_j and its standard error. If p_j is within
|
|
14
|
+
max(2 SE, 0.02) of a simple fraction (denominator 1, 2 or 3, |p| <= 3, not 0), x_j^p
|
|
15
|
+
is proposed (3 SE, floor 0.03; the 2 nearest such fractions at most). Nothing is accepted or rejected here; proposals only add candidate terms.
|
|
16
|
+
(If the data has no slices, as in a time series, one fit of log|y| on all log x_j.)
|
|
17
|
+
2. Term list: every product of non-negative integer powers with total degree <= 2
|
|
18
|
+
(1, x_i, x_i x_j, x_i^2), plus each proposed x_j^p, plus the product of all proposed
|
|
19
|
+
powers (BACON's invariant, e.g. T*D^2).
|
|
20
|
+
3. Implicit form, as in SINDy-PI: y = N(x)/D(x), with N and D sparse sums of terms, fitted
|
|
21
|
+
as the linear problem y*D(x) = N(x), with one D term's coefficient set to 1 (each
|
|
22
|
+
term in turn). Ratio laws like (M1 T1 + M2 T2)/(M1 + M2) or 3/(X + 2) become sums.
|
|
23
|
+
Candidate laws: every law with up to 4 terms in total (screened by a quick fit on all
|
|
24
|
+
rows; the best 30 of each size go on), plus larger ones from two searches per D term:
|
|
25
|
+
PySINDy's STLSQ over the usual threshold grid (normalized columns, no ridge penalty),
|
|
26
|
+
and forward selection (add the term that most reduces the squared error, up to
|
|
27
|
+
MAX_FREE free coefficients).
|
|
28
|
+
4. Decide by held-out error, not tolerances. Every candidate with at most MAX_FREE free
|
|
29
|
+
coefficients is scored by 5-fold cross-validation repeated over 5 random splits
|
|
30
|
+
(leave-one-out below 10 rows): fit on
|
|
31
|
+
the other folds, predict y = N/D on the held-out rows, mean squared relative error.
|
|
32
|
+
Coefficients are first fitted linearly, then refined by least squares on the
|
|
33
|
+
relative prediction error itself. Pick the fewest terms whose error is within one
|
|
34
|
+
standard error of the best (the "one-standard-error rule"; differences below 1e-10
|
|
35
|
+
count as rounding), ties going to lower total power.
|
|
36
|
+
Not built (yet): a further round that proposes new terms from what the chosen law leaves
|
|
37
|
+
unexplained.
|
|
38
|
+
"""
|
|
39
|
+
from fractions import Fraction
|
|
40
|
+
from itertools import combinations_with_replacement
|
|
41
|
+
|
|
42
|
+
import numpy as np
|
|
43
|
+
import pysindy as ps
|
|
44
|
+
import sympy as sp
|
|
45
|
+
import warnings
|
|
46
|
+
|
|
47
|
+
from scipy.optimize import least_squares
|
|
48
|
+
|
|
49
|
+
# PySINDy STLSQ threshold grid on normalized columns, copied from bacon-vs-pysindy's
|
|
50
|
+
# sindy_runner.THRESHOLDS_NORM (same values) so this file stands alone.
|
|
51
|
+
THRESHOLDS_NORM = np.logspace(-3, 3, 25)
|
|
52
|
+
|
|
53
|
+
MAX_FREE = 5 # most free coefficients a law may have (N and D together)
|
|
54
|
+
EXHAUSTIVE_TERMS = 4 # every law with up to this many terms (N and D together) is tried
|
|
55
|
+
SCREEN_KEEP = 30 # per law size, how many survive the quick screen into cross-validation
|
|
56
|
+
POWER_SE = 3 # step 1: accept a fraction within POWER_SE standard errors ...
|
|
57
|
+
POWER_FLOOR = 0.03 # ... or within this, whichever is larger (clean data has SE ~0)
|
|
58
|
+
POWER_KEEP = 2 # ... at most the 2 nearest fractions per input
|
|
59
|
+
CV_FLOOR = 1e-10 # errors below this (relative RMS 1e-5) count as equal: rounding
|
|
60
|
+
FOLDS = 5
|
|
61
|
+
REPEATS = 5 # repeated cross-validation: 5 different random splits into folds
|
|
62
|
+
CV_SEED = 0
|
|
63
|
+
# Named switches (benchmark defaults; every result in README.md uses these values):
|
|
64
|
+
POWER_DENOMINATORS = (1, 2, 3) # step 1: fractions k/d with these denominators, |k/d| <= 3
|
|
65
|
+
POWER_FREE = False # step 1: if no fraction is close enough, propose the estimate itself
|
|
66
|
+
POWER_FREE_DIGITS = 2 # ... rounded to this many decimals
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _rationals(denominators):
|
|
70
|
+
return sorted({Fraction(k, d) for d in denominators for k in range(-3 * d, 3 * d + 1)
|
|
71
|
+
if k != 0})
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
RATIONALS = _rationals(POWER_DENOMINATORS)
|
|
75
|
+
PARAMS = {"max_free": MAX_FREE, "power_se": POWER_SE, "power_floor": POWER_FLOOR,
|
|
76
|
+
"cv_floor": CV_FLOOR, "folds": FOLDS, "repeats": REPEATS, "exhaustive_terms": EXHAUSTIVE_TERMS,
|
|
77
|
+
"screen_keep": SCREEN_KEEP, "refine": "least squares on relative error",
|
|
78
|
+
"cv_seed": CV_SEED, "power_keep": POWER_KEEP, "power_denominators": list(POWER_DENOMINATORS),
|
|
79
|
+
"power_free": POWER_FREE, "max_abs_power": 3,
|
|
80
|
+
"integer_degree": 2, "stlsq_grid": "THRESHOLDS_NORM (25, 0.001-1000)",
|
|
81
|
+
"selection": "one-standard-error rule on cross-validated relative error"}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# --- 1. propose powers --------------------------------------------------------------
|
|
85
|
+
def propose_powers(X, y):
|
|
86
|
+
"""{input index: Fraction power} for inputs whose power law fits a simple fraction."""
|
|
87
|
+
n_rows, n = X.shape
|
|
88
|
+
rationals = (RATIONALS if tuple(POWER_DENOMINATORS) == (1, 2, 3)
|
|
89
|
+
else _rationals(POWER_DENOMINATORS))
|
|
90
|
+
if np.any(y == 0):
|
|
91
|
+
return {}, {}
|
|
92
|
+
ly = np.log(np.abs(y))
|
|
93
|
+
positive = [j for j in range(n) if np.all(X[:, j] > 0)]
|
|
94
|
+
estimates, out = {}, {}
|
|
95
|
+
for j in positive:
|
|
96
|
+
others = np.delete(X, j, axis=1)
|
|
97
|
+
if others.shape[1]:
|
|
98
|
+
_, sid = np.unique(others, axis=0, return_inverse=True)
|
|
99
|
+
else:
|
|
100
|
+
sid = np.zeros(n_rows, dtype=int)
|
|
101
|
+
k = sid.max() + 1
|
|
102
|
+
if n_rows - k - 1 >= 1 and k <= n_rows / 2: # slices exist: BACON's design
|
|
103
|
+
A = np.column_stack([np.eye(k)[sid], np.log(X[:, j])])
|
|
104
|
+
col = A.shape[1] - 1
|
|
105
|
+
else: # no slices: one global fit
|
|
106
|
+
A = np.column_stack([np.ones(n_rows)] + [np.log(X[:, i]) for i in positive])
|
|
107
|
+
col = 1 + positive.index(j)
|
|
108
|
+
coef, *_ = np.linalg.lstsq(A, ly, rcond=None)
|
|
109
|
+
dof = n_rows - np.linalg.matrix_rank(A)
|
|
110
|
+
if dof < 1:
|
|
111
|
+
continue
|
|
112
|
+
resid = ly - A @ coef
|
|
113
|
+
try:
|
|
114
|
+
cov = (resid @ resid / dof) * np.linalg.pinv(A.T @ A)
|
|
115
|
+
except np.linalg.LinAlgError:
|
|
116
|
+
continue
|
|
117
|
+
p, se = float(coef[col]), float(np.sqrt(max(cov[col, col], 0.0)))
|
|
118
|
+
estimates[j] = (p, se)
|
|
119
|
+
tol = max(POWER_SE * se, POWER_FLOOR)
|
|
120
|
+
near = sorted((r for r in rationals if abs(p - float(r)) <= tol),
|
|
121
|
+
key=lambda r: abs(p - float(r)))[:POWER_KEEP]
|
|
122
|
+
if not near and POWER_FREE:
|
|
123
|
+
free = Fraction(round(p, POWER_FREE_DIGITS)).limit_denominator(10 ** POWER_FREE_DIGITS)
|
|
124
|
+
if free != 0 and abs(free) <= 3:
|
|
125
|
+
near = [free]
|
|
126
|
+
if near:
|
|
127
|
+
out[j] = near # nearest first
|
|
128
|
+
return out, estimates
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# --- 2. term list -------------------------------------------------------------------
|
|
132
|
+
def term_list(n, powers):
|
|
133
|
+
"""Exponent vectors (tuples of Fractions), constant first, no duplicates."""
|
|
134
|
+
terms = [tuple(Fraction(0) for _ in range(n))]
|
|
135
|
+
for deg in (1, 2):
|
|
136
|
+
for combo in combinations_with_replacement(range(n), deg):
|
|
137
|
+
e = [Fraction(0)] * n
|
|
138
|
+
for i in combo:
|
|
139
|
+
e[i] += 1
|
|
140
|
+
terms.append(tuple(e))
|
|
141
|
+
for j, ps_ in powers.items():
|
|
142
|
+
for p in ps_:
|
|
143
|
+
e = [Fraction(0)] * n
|
|
144
|
+
e[j] = p
|
|
145
|
+
terms.append(tuple(e))
|
|
146
|
+
if len(powers) >= 2: # BACON's invariant, from each input's nearest fraction
|
|
147
|
+
e = [Fraction(0)] * n
|
|
148
|
+
for j, ps_ in powers.items():
|
|
149
|
+
e[j] = ps_[0]
|
|
150
|
+
terms.append(tuple(e))
|
|
151
|
+
seen, out = set(), []
|
|
152
|
+
for t in terms:
|
|
153
|
+
if t not in seen:
|
|
154
|
+
seen.add(t)
|
|
155
|
+
out.append(t)
|
|
156
|
+
return out
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def columns(X, terms):
|
|
160
|
+
cols = []
|
|
161
|
+
for e in terms:
|
|
162
|
+
c = np.ones(len(X))
|
|
163
|
+
for j, p in enumerate(e):
|
|
164
|
+
if p != 0:
|
|
165
|
+
c = c * (X[:, j] ** int(p) if p.denominator == 1 else X[:, j] ** float(p))
|
|
166
|
+
cols.append(c)
|
|
167
|
+
return np.column_stack(cols)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# --- 3. implicit fit ----------------------------------------------------------------
|
|
171
|
+
def _design(theta, y, anchor):
|
|
172
|
+
"""Features for y*theta[anchor] = sum a_k theta_k - sum_{k != anchor} b_k y theta_k."""
|
|
173
|
+
m = theta.shape[1]
|
|
174
|
+
feats = [theta[:, k] for k in range(m)] + [-y * theta[:, k] for k in range(m) if k != anchor]
|
|
175
|
+
keys = [("N", k) for k in range(m)] + [("D", k) for k in range(m) if k != anchor]
|
|
176
|
+
return np.column_stack(feats), keys, y * theta[:, anchor]
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _lstsq(F, t):
|
|
180
|
+
w, *_ = np.linalg.lstsq(F, t, rcond=None)
|
|
181
|
+
return w
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _candidates(theta, y):
|
|
185
|
+
m = theta.shape[1]
|
|
186
|
+
found = {}
|
|
187
|
+
for anchor in range(m):
|
|
188
|
+
F, keys, t = _design(theta, y, anchor)
|
|
189
|
+
supports = []
|
|
190
|
+
# STLSQ path (PySINDy)
|
|
191
|
+
for thr in THRESHOLDS_NORM:
|
|
192
|
+
opt = ps.STLSQ(threshold=thr, normalize_columns=True, alpha=0.0)
|
|
193
|
+
with warnings.catch_warnings():
|
|
194
|
+
warnings.simplefilter("ignore")
|
|
195
|
+
try:
|
|
196
|
+
opt.fit(F, t.reshape(-1, 1))
|
|
197
|
+
except Exception:
|
|
198
|
+
continue
|
|
199
|
+
s = tuple(np.flatnonzero(np.asarray(opt.coef_).ravel()))
|
|
200
|
+
if 0 < len(s) <= MAX_FREE:
|
|
201
|
+
supports.append(s)
|
|
202
|
+
# forward selection
|
|
203
|
+
chosen = []
|
|
204
|
+
scale = np.linalg.norm(F, axis=0)
|
|
205
|
+
scale[scale == 0] = 1
|
|
206
|
+
Fn = F / scale
|
|
207
|
+
for _ in range(MAX_FREE):
|
|
208
|
+
best, best_rss = None, np.inf
|
|
209
|
+
for k in range(F.shape[1]):
|
|
210
|
+
if k in chosen:
|
|
211
|
+
continue
|
|
212
|
+
cols = chosen + [k]
|
|
213
|
+
w = _lstsq(Fn[:, cols], t)
|
|
214
|
+
rss = float(np.sum((t - Fn[:, cols] @ w) ** 2))
|
|
215
|
+
if rss < best_rss:
|
|
216
|
+
best, best_rss = k, rss
|
|
217
|
+
if best is None:
|
|
218
|
+
break
|
|
219
|
+
chosen.append(best)
|
|
220
|
+
supports.append(tuple(sorted(chosen)))
|
|
221
|
+
for s in supports:
|
|
222
|
+
num = frozenset(keys[i][1] for i in s if keys[i][0] == "N")
|
|
223
|
+
den = frozenset([anchor] + [keys[i][1] for i in s if keys[i][0] == "D"])
|
|
224
|
+
if num and (num, den) not in found:
|
|
225
|
+
found[(num, den)] = (anchor, s)
|
|
226
|
+
return found
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def _unpack(w, keys, support, m, anchor):
|
|
230
|
+
a, b = np.zeros(m), np.zeros(m)
|
|
231
|
+
b[anchor] = 1.0
|
|
232
|
+
for wi, i in zip(w, support):
|
|
233
|
+
side, k = keys[i]
|
|
234
|
+
(a if side == "N" else b)[k] = wi
|
|
235
|
+
return a, b
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
def _exhaustive(theta, y):
|
|
239
|
+
"""Every (N, D) with |N| + |D| <= EXHAUSTIVE_TERMS, screened by the training error of
|
|
240
|
+
the linear implicit fit; the best SCREEN_KEEP of each size are kept."""
|
|
241
|
+
from itertools import combinations
|
|
242
|
+
m = theta.shape[1]
|
|
243
|
+
scale = np.abs(y) if (np.all(y > 0) or np.all(y < 0)) else np.std(y)
|
|
244
|
+
by_size = {}
|
|
245
|
+
for size in range(2, EXHAUSTIVE_TERMS + 1):
|
|
246
|
+
for nd in range(1, size):
|
|
247
|
+
for den in combinations(range(m), size - nd):
|
|
248
|
+
anchor, rest = den[0], den[1:]
|
|
249
|
+
t = y * theta[:, anchor]
|
|
250
|
+
Dpart = -y[:, None] * theta[:, list(rest)]
|
|
251
|
+
for num in combinations(range(m), nd):
|
|
252
|
+
F = np.column_stack([theta[:, list(num)], Dpart])
|
|
253
|
+
w, *_ = np.linalg.lstsq(F, t, rcond=None)
|
|
254
|
+
Nv = theta[:, list(num)] @ w[:nd]
|
|
255
|
+
Dv = theta[:, anchor] + (theta[:, list(rest)] @ w[nd:] if rest else 0)
|
|
256
|
+
with np.errstate(all="ignore"):
|
|
257
|
+
err = np.mean(((Nv / Dv - y) / scale) ** 2)
|
|
258
|
+
if np.isfinite(err):
|
|
259
|
+
by_size.setdefault(size, []).append((err, frozenset(num), frozenset(den)))
|
|
260
|
+
out = {}
|
|
261
|
+
for size, lst in by_size.items():
|
|
262
|
+
lst.sort(key=lambda r: r[0])
|
|
263
|
+
for _, num, den in lst[:SCREEN_KEEP]:
|
|
264
|
+
out[(num, den)] = None
|
|
265
|
+
return out
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def _support_for(num, den, m):
|
|
269
|
+
"""(anchor, support indices into _design's features) for a given N and D."""
|
|
270
|
+
anchor = min(den)
|
|
271
|
+
keys = [("N", k) for k in range(m)] + [("D", k) for k in range(m) if k != anchor]
|
|
272
|
+
sup = tuple(sorted([keys.index(("N", k)) for k in num] +
|
|
273
|
+
[keys.index(("D", k)) for k in den if k != anchor]))
|
|
274
|
+
return anchor, sup
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def _fit_predict(theta_tr, y_tr, theta_te, anchor, support):
|
|
278
|
+
"""Linear implicit fit, then refined on the prediction error itself: the implicit
|
|
279
|
+
residual y*D - N weights rows by D and puts the noise on both sides, which biases the
|
|
280
|
+
coefficients under noise."""
|
|
281
|
+
F, keys, t = _design(theta_tr, y_tr, anchor)
|
|
282
|
+
m = theta_tr.shape[1]
|
|
283
|
+
w0 = _lstsq(F[:, list(support)], t)
|
|
284
|
+
scale = np.abs(y_tr) if (np.all(y_tr > 0) or np.all(y_tr < 0)) else np.std(y_tr)
|
|
285
|
+
|
|
286
|
+
def resid(w):
|
|
287
|
+
a, b = _unpack(w, keys, support, m, anchor)
|
|
288
|
+
with np.errstate(all="ignore"):
|
|
289
|
+
r = ((theta_tr @ a) / (theta_tr @ b) - y_tr) / scale
|
|
290
|
+
return np.where(np.isfinite(r), r, 1e6)
|
|
291
|
+
try:
|
|
292
|
+
w = least_squares(resid, w0, method="lm" if len(y_tr) >= len(w0) else "trf",
|
|
293
|
+
max_nfev=200 * (len(w0) + 1)).x
|
|
294
|
+
if np.sum(resid(w) ** 2) > np.sum(resid(w0) ** 2):
|
|
295
|
+
w = w0
|
|
296
|
+
except Exception:
|
|
297
|
+
w = w0
|
|
298
|
+
a, b = _unpack(w, keys, support, m, anchor)
|
|
299
|
+
with np.errstate(all="ignore"):
|
|
300
|
+
pred = (theta_te @ a) / (theta_te @ b)
|
|
301
|
+
return pred, a, b
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def _errors(pred, y):
|
|
305
|
+
if np.all(y > 0) or np.all(y < 0):
|
|
306
|
+
e = (pred - y) / y
|
|
307
|
+
else:
|
|
308
|
+
e = (pred - y) / np.std(y)
|
|
309
|
+
return float(np.mean(e ** 2)) if np.all(np.isfinite(e)) else np.inf
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _folds(n_rows):
|
|
313
|
+
"""REPEATS x FOLDS held-out sets (leave-one-out below 10 rows). Errors are averaged
|
|
314
|
+
over all of them; the standard error uses one value per repeat."""
|
|
315
|
+
if n_rows < 10:
|
|
316
|
+
return [[np.array([i]) for i in range(n_rows)]]
|
|
317
|
+
rng = np.random.default_rng(CV_SEED)
|
|
318
|
+
reps = []
|
|
319
|
+
for _ in range(REPEATS):
|
|
320
|
+
idx = rng.permutation(n_rows)
|
|
321
|
+
reps.append([idx[i::FOLDS] for i in range(FOLDS)])
|
|
322
|
+
return reps
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
# --- 4. decide ----------------------------------------------------------------------
|
|
326
|
+
def discover(X, y, symbols, details=False):
|
|
327
|
+
"""Returns a sympy expression for y in terms of `symbols` (positive inputs assumed
|
|
328
|
+
only where fractional powers are proposed)."""
|
|
329
|
+
X = np.asarray(X, dtype=float)
|
|
330
|
+
y = np.asarray(y, dtype=float)
|
|
331
|
+
powers, estimates = propose_powers(X, y)
|
|
332
|
+
terms = term_list(X.shape[1], powers)
|
|
333
|
+
theta = columns(X, terms)
|
|
334
|
+
cands = _candidates(theta, y)
|
|
335
|
+
for key in _exhaustive(theta, y):
|
|
336
|
+
if key not in cands:
|
|
337
|
+
cands[key] = _support_for(*key, theta.shape[1])
|
|
338
|
+
folds = _folds(len(y))
|
|
339
|
+
scored = []
|
|
340
|
+
for (num, den), (anchor, support) in cands.items():
|
|
341
|
+
per_rep = []
|
|
342
|
+
for rep in folds:
|
|
343
|
+
errs = []
|
|
344
|
+
for te in rep:
|
|
345
|
+
tr = np.setdiff1d(np.arange(len(y)), te)
|
|
346
|
+
pred, _, _ = _fit_predict(theta[tr], y[tr], theta[te], anchor, support)
|
|
347
|
+
errs.append(_errors(pred, y[te]))
|
|
348
|
+
per_rep.append(errs)
|
|
349
|
+
flat = np.array([e for r in per_rep for e in r])
|
|
350
|
+
cv = float(np.mean(flat))
|
|
351
|
+
if not np.all(np.isfinite(flat)):
|
|
352
|
+
se = np.inf
|
|
353
|
+
elif len(per_rep) > 1: # repeats share rows, so SE from fold scores within a repeat
|
|
354
|
+
se = float(np.mean([np.std(r, ddof=1) / np.sqrt(len(r)) for r in per_rep]))
|
|
355
|
+
else:
|
|
356
|
+
se = float(np.std(flat, ddof=1) / np.sqrt(len(flat)))
|
|
357
|
+
degree = sum(float(sum(abs(p) for p in terms[k])) for k in num | den)
|
|
358
|
+
scored.append((cv, se, len(num) + len(den), anchor, support, num, den, degree))
|
|
359
|
+
finite = [s for s in scored if np.isfinite(s[0])]
|
|
360
|
+
if not finite:
|
|
361
|
+
return (None, {}) if details else None
|
|
362
|
+
best = min(finite, key=lambda s: s[0])
|
|
363
|
+
ok = [s for s in finite if s[0] <= best[0] + max(best[1], CV_FLOOR)]
|
|
364
|
+
# fewest terms; then lowest total power (so u/(w+5), not u*w/(w^2+5w)); then error
|
|
365
|
+
cv, se, nterms, anchor, support, num, den, _ = min(ok, key=lambda s: (s[2], s[7], s[0]))
|
|
366
|
+
_, a, b = _fit_predict(theta, y, theta, anchor, support)
|
|
367
|
+
|
|
368
|
+
def expr(e):
|
|
369
|
+
return sp.Mul(*[s ** sp.Rational(p.numerator, p.denominator)
|
|
370
|
+
for s, p in zip(symbols, e) if p != 0])
|
|
371
|
+
N = sum((float(c) * expr(e) for c, e in zip(a, terms) if c != 0), sp.Integer(0))
|
|
372
|
+
D = sum((float(c) * expr(e) for c, e in zip(b, terms) if c != 0), sp.Integer(0))
|
|
373
|
+
law = N / D
|
|
374
|
+
if details:
|
|
375
|
+
return law, {"proposed_powers": {str(symbols[j]): [str(p) for p in ps_] for j, ps_ in powers.items()},
|
|
376
|
+
"power_estimates": {str(symbols[j]): (round(p, 4), round(s, 4))
|
|
377
|
+
for j, (p, s) in estimates.items()},
|
|
378
|
+
"n_terms_in_list": len(terms), "n_candidates": len(scored),
|
|
379
|
+
"cv_rel_mse": cv, "cv_se": se}
|
|
380
|
+
return law
|
basin/version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
@@ -0,0 +1,767 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: basin-sr
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Law finder for tables of measurements: BACON proposes terms, sparse regression and cross-validation decide
|
|
5
|
+
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: symbolic-regression,equation-discovery,BACON,SINDy,scientific-discovery
|
|
8
|
+
Author: pUrGe12
|
|
9
|
+
Author-email: achintya.jai@owasp.org
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Requires-Dist: numpy (>=1.24)
|
|
22
|
+
Requires-Dist: pysindy (>=2.0,<3.0)
|
|
23
|
+
Requires-Dist: scikit-learn (>=1.3)
|
|
24
|
+
Requires-Dist: scipy (>=1.10)
|
|
25
|
+
Requires-Dist: sympy (>=1.12)
|
|
26
|
+
Project-URL: Homepage, https://github.com/FauvidoTechnologies/basin
|
|
27
|
+
Project-URL: Repository, https://github.com/FauvidoTechnologies/basin
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# basin: BACON proposes terms, regression decides
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install basin-sr
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import basin
|
|
38
|
+
law = basin.discover(X, y, ["M1", "T1", "M2", "T2"]) # a sympy expression
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
In the text below, "the hybrid" means this method.
|
|
42
|
+
|
|
43
|
+
A law finder for tables of measurements: given inputs `x₁ … xₙ` and one measured output
|
|
44
|
+
`y`, it returns a formula `y = N(x)/D(x)`. It combines ideas from BACON (Langley's
|
|
45
|
+
discovery system, as rebuilt by Miller & Banerjee 2025) with SINDy-style sparse
|
|
46
|
+
regression (PySINDy), and decides between candidate laws by cross-validation.
|
|
47
|
+
|
|
48
|
+
It was built and benchmarked in
|
|
49
|
+
[bacon-vs-pysindy](https://github.com/pUrGe12/bacon-vs-pysindy) (Tests 13–15). This
|
|
50
|
+
directory holds a standalone copy of it, so it can be developed and tested against PySR
|
|
51
|
+
on its own.
|
|
52
|
+
|
|
53
|
+
## Where this copy came from
|
|
54
|
+
|
|
55
|
+
- `hybrid.py` is copied from `bacon-vs-pysindy/hybrid.py` at commit `a53d1ce`. That file
|
|
56
|
+
(SHA-256 `b418a97a…`) is the version recorded in all 79 hybrid run records of Test 15,
|
|
57
|
+
unchanged since it was frozen for Test 13.
|
|
58
|
+
- **One change:** the original imported a list of 25 STLSQ thresholds
|
|
59
|
+
(`np.logspace(-3, 3, 25)`) from `sindy_runner.py`. The list is now written into
|
|
60
|
+
`hybrid.py`, so the file stands alone. Nothing else differs (`diff` shows only those
|
|
61
|
+
lines).
|
|
62
|
+
- **Checked:** the copy and the original were run on the same data for four Test 15
|
|
63
|
+
setups, and gave identical formulas, equal to the saved Test 15 answers:
|
|
64
|
+
- I.12.1 at 10% noise: `0.9751*Nn*mu`
|
|
65
|
+
- I.18.4 at 5% noise: `(0.9975*m1*r1 + 0.9982*m2*r2)/(1.0*m1 + 1.009*m2)`
|
|
66
|
+
- I.47.23 with no noise: `1.0*gamma**0.5*pr**0.5/rho**0.5`
|
|
67
|
+
- II.11.28 at 1% noise: `(0.6733*alpha*n + 1.0)/(-0.3292*alpha*n + 1.0)`
|
|
68
|
+
- Any change from here on should be a named switch, with the benchmark version as the
|
|
69
|
+
default, so the results below stay reproducible.
|
|
70
|
+
- **Since then:** two such switches (`POWER_DENOMINATORS`, `POWER_FREE`, see the
|
|
71
|
+
settings table), and the file moved to `basin/core.py` for the package. Black's law in
|
|
72
|
+
`example.py` gives the same formula as the original.
|
|
73
|
+
|
|
74
|
+
## Use
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install basin-sr # the library (imported as `basin`)
|
|
78
|
+
pip install -r requirements.txt # or: the exact versions used for every result below (Python 3.10)
|
|
79
|
+
python example.py # Black's law from 81 noisy rows, about 10 s
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
import basin
|
|
84
|
+
|
|
85
|
+
# X: one row per measurement, one column per input; y: the measured output
|
|
86
|
+
law = basin.discover(X, y, ["M1", "T1", "M2", "T2"]) # names, sympy Symbols, or None (x0, x1, ...)
|
|
87
|
+
law, info = basin.discover(X, y, names, details=True) # also: proposed powers, CV error
|
|
88
|
+
|
|
89
|
+
# the side-run switches (defaults = the benchmark version), changed for a block only:
|
|
90
|
+
with basin.settings(POWER_FREE=True):
|
|
91
|
+
law = basin.discover(X, y, names)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
`basin.core` is the method itself (formerly `hybrid.py`). The top-level `hybrid.py` is a
|
|
95
|
+
shim that makes `import hybrid` return `basin.core`, so the runners in `allen/` and
|
|
96
|
+
`neuromorpho/` work as before.
|
|
97
|
+
|
|
98
|
+
### Releasing (maintainers)
|
|
99
|
+
|
|
100
|
+
`make new-release` builds with poetry, runs `twine check`, and uploads with the token
|
|
101
|
+
`pypy_api_token` from `./.env` (git-ignored; see `.env.example`). Twine gets an empty
|
|
102
|
+
config file and an explicit upload URL, so `~/.pypirc` and other projects' credentials
|
|
103
|
+
are never used. `make test-release` uploads to TestPyPI with `testpypi_api_token`. Raise
|
|
104
|
+
the version in both `basin/version.py` and `pyproject.toml` (the build checks they match).
|
|
105
|
+
|
|
106
|
+
## How it works
|
|
107
|
+
|
|
108
|
+
Given the table (every step uses all rows):
|
|
109
|
+
|
|
110
|
+
1. **Propose powers, BACON's way.** For each input `x_j`, group the rows where every
|
|
111
|
+
other input has the same value (BACON's "slices" of a factorial experiment) and fit
|
|
112
|
+
`log|y| = (one intercept per slice) + p·log x_j` on all slices at once. Every simple
|
|
113
|
+
fraction (denominator 1, 2 or 3, |p| ≤ 3, not 0) within 3 standard errors of `p`
|
|
114
|
+
(at least 0.03; at most the 2 nearest) becomes a candidate term `x_j^p`. So does the
|
|
115
|
+
product of each input's nearest fraction (BACON's invariant, e.g. `T·D²`). Nothing is
|
|
116
|
+
accepted or rejected here. If the rows have no slices, one fit of `log|y|` on all
|
|
117
|
+
`log x_j` is used instead.
|
|
118
|
+
2. **Term list:** `1`, every input, every product of two inputs (squares included), plus
|
|
119
|
+
the proposed terms.
|
|
120
|
+
3. **Fractions as a linear problem (as in SINDy-PI):** `y = N/D` with `N` and `D` sparse
|
|
121
|
+
sums of terms, fitted as `y·D = N` with one `D` coefficient fixed to 1. Candidate laws:
|
|
122
|
+
every law with up to 4 terms in total (screened by a quick fit, best 30 per size),
|
|
123
|
+
plus larger ones (up to 5 free coefficients) from PySINDy's STLSQ and from forward
|
|
124
|
+
selection.
|
|
125
|
+
4. **Decide by held-out error.** Each candidate is scored by 5-fold cross-validation
|
|
126
|
+
repeated over 5 random splits, on mean squared relative error, with coefficients
|
|
127
|
+
refined by least squares on the relative error. Pick the fewest terms whose error is
|
|
128
|
+
within one standard error of the best; ties go to lower total power.
|
|
129
|
+
|
|
130
|
+
| setting | value | meaning |
|
|
131
|
+
|---|---|---|
|
|
132
|
+
| `MAX_FREE` | 5 | most free coefficients in a law (N and D together) |
|
|
133
|
+
| `EXHAUSTIVE_TERMS` | 4 | every law with up to this many terms is tried |
|
|
134
|
+
| `SCREEN_KEEP` | 30 | per law size, candidates kept after the quick screen |
|
|
135
|
+
| `POWER_SE`, `POWER_FLOOR` | 3, 0.03 | step 1 tolerance: 3 standard errors, at least 0.03 |
|
|
136
|
+
| `POWER_KEEP` | 2 | at most 2 proposed fractions per input |
|
|
137
|
+
| `FOLDS`, `REPEATS`, `CV_SEED` | 5, 5, 0 | cross-validation (leave-one-out below 10 rows) |
|
|
138
|
+
| `CV_FLOOR` | 1e-10 | errors closer than this count as equal |
|
|
139
|
+
| `POWER_DENOMINATORS` | (1, 2, 3) | side-run switch: step 1's fractions k/d use these d |
|
|
140
|
+
| `POWER_FREE`, `POWER_FREE_DIGITS` | False, 2 | side-run switch: if no fraction fits, propose the estimate rounded to 2 decimals |
|
|
141
|
+
|
|
142
|
+
The two side-run switches were added after every benchmark below. Their defaults give
|
|
143
|
+
identical results; see `findings/hybrid_power_switches.md`.
|
|
144
|
+
|
|
145
|
+
**What it cannot write:** `sin`, `cos`, `exp`, `log`; powers with a denominator above 3 or
|
|
146
|
+
above 3 in size; laws with more than 5 free coefficients; products of more than two
|
|
147
|
+
inputs unless step 1 proposes them; fractional powers of inputs that are not all
|
|
148
|
+
positive. Step 1 is skipped if any `y` is exactly 0.
|
|
149
|
+
|
|
150
|
+
## Benchmarks
|
|
151
|
+
|
|
152
|
+
All results are from bacon-vs-pysindy. The rules for each test were written down before
|
|
153
|
+
it ran, and the hybrid was not changed after seeing any result. "Exact law" means the
|
|
154
|
+
right terms with every number within 5% of its true value (equivalent rearrangements
|
|
155
|
+
count). Noise is Gaussian on the measured output with sd = level × |y|.
|
|
156
|
+
|
|
157
|
+
### Test 15: the AI Feynman benchmark (79 laws, the hybrid was not designed on these)
|
|
158
|
+
|
|
159
|
+
- **Laws:** every AI Feynman equation (Udrescu & Tegmark 2020) with at most 4 inputs, 79
|
|
160
|
+
laws. No other filtering.
|
|
161
|
+
- **Data:** a full factorial grid over the benchmark's ranges, about 1000 rows (1 input:
|
|
162
|
+
1000 levels; 2 inputs: 32 per input; 3: 10; 4: 6).
|
|
163
|
+
- **Runs:** no noise (1 run per law), 1%, 5% and 10% noise (10 runs per law each).
|
|
164
|
+
- **PySR 2.7.2:** defaults plus every function the 79 laws use (`+ - * /`, `sqrt`, `exp`,
|
|
165
|
+
`sin`, `cos`, `arcsin`), maximum size 40 (the largest true formula needs about 34),
|
|
166
|
+
100 iterations, deterministic. PySR's own "best" model selection.
|
|
167
|
+
- **Scoring:** the answer's numbers are re-fitted to the true law at 500 random points.
|
|
168
|
+
Right terms means the re-fitted formula reproduces the law exactly and no number goes
|
|
169
|
+
to zero. Exact law means right terms and every number within 5% of its re-fitted value.
|
|
170
|
+
This uses the fixed coefficient check from `rescore.py`.
|
|
171
|
+
|
|
172
|
+
**Laws found in more than half the runs, all five methods:**
|
|
173
|
+
|
|
174
|
+
| method | no noise (1 run per law) | 1% noise (10 runs) | 5% noise (10 runs) | 10% noise (10 runs) |
|
|
175
|
+
|---|---|---|---|---|
|
|
176
|
+
| BACON (original) | 40 of 79 | 28 of 79 | 19 of 79 | 14 of 79 |
|
|
177
|
+
| BACON-robust | 44 of 79 | 41 of 79 | 36 of 79 | 14 of 79 |
|
|
178
|
+
| PySINDy | 35 of 79 | 0 of 79 | 0 of 79 | 0 of 79 |
|
|
179
|
+
| **Hybrid** | 43 of 79 | 43 of 79 | 42 of 79 | 41 of 79 |
|
|
180
|
+
| **PySR** | 42 of 79 | 50 of 79 | 50 of 79 | 49 of 79 |
|
|
181
|
+
|
|
182
|
+
**The same, split by kind of law.** The split was made after the run, from the true
|
|
183
|
+
formulas:
|
|
184
|
+
- **A:** one product of powers, e.g. `q1*q2/(4*pi*epsilon*r**2)`.
|
|
185
|
+
- **B:** other algebraic laws: sums, fractions with sums, roots of sums.
|
|
186
|
+
- **C:** laws with `sin`, `cos`, `exp` or `arcsin`.
|
|
187
|
+
|
|
188
|
+
| kind of law | noise | BACON (original) | BACON-robust | PySINDy | Hybrid | PySR |
|
|
189
|
+
|---|---|---|---|---|---|---|
|
|
190
|
+
| A: one product of powers (35 laws) | no noise | 34 | 35 | 32 | 35 | 30 |
|
|
191
|
+
| | 1% noise | 28 | 34 | 0 | 35 | 34 |
|
|
192
|
+
| | 5% noise | 18 | 34 | 0 | 35 | 34 |
|
|
193
|
+
| | 10% noise | 13 | 12 | 0 | 35 | 34 |
|
|
194
|
+
| B: other algebraic (24 laws) | no noise | 6 | 9 | 3 | 8 | 6 |
|
|
195
|
+
| | 1% noise | 0 | 7 | 0 | 8 | 7 |
|
|
196
|
+
| | 5% noise | 1 | 2 | 0 | 7 | 7 |
|
|
197
|
+
| | 10% noise | 1 | 2 | 0 | 6 | 7 |
|
|
198
|
+
| C: sin, cos, exp, arcsin (20 laws) | no noise | 0 | 0 | 0 | 0 | 6 |
|
|
199
|
+
| | 1% noise | 0 | 0 | 0 | 0 | 9 |
|
|
200
|
+
| | 5% noise | 0 | 0 | 0 | 0 | 9 |
|
|
201
|
+
| | 10% noise | 0 | 0 | 0 | 0 | 8 |
|
|
202
|
+
|
|
203
|
+
**Hybrid against PySR, law by law.** Each count is the number of laws where that method
|
|
204
|
+
finds the exact law in more runs than the other. The sign test is two-sided. The "all 79"
|
|
205
|
+
rows were the test's decision rule. The splits by kind were made after the run, so they
|
|
206
|
+
describe the results rather than test them.
|
|
207
|
+
|
|
208
|
+
| laws | noise | Hybrid finds the law in more runs | PySR finds it in more runs | same | sign test |
|
|
209
|
+
|---|---|---|---|---|---|
|
|
210
|
+
| all 79 | no noise | 8 | 7 | 64 | p = 1 |
|
|
211
|
+
| | 1% noise | 6 | 21 | 52 | p = 0.0059 |
|
|
212
|
+
| | 5% noise | 8 | 21 | 50 | p = 0.024 |
|
|
213
|
+
| | 10% noise | 6 | 15 | 58 | p = 0.078 |
|
|
214
|
+
| A: one product of powers (35) | no noise | 5 | 0 | 30 | p = 0.062 |
|
|
215
|
+
| | 1% noise | 3 | 0 | 32 | p = 0.25 |
|
|
216
|
+
| | 5% noise | 5 | 0 | 30 | p = 0.062 |
|
|
217
|
+
| | 10% noise | 3 | 0 | 32 | p = 0.25 |
|
|
218
|
+
| B: other algebraic (24) | no noise | 3 | 1 | 20 | p = 0.62 |
|
|
219
|
+
| | 1% noise | 3 | 5 | 16 | p = 0.73 |
|
|
220
|
+
| | 5% noise | 3 | 4 | 17 | p = 1 |
|
|
221
|
+
| | 10% noise | 3 | 3 | 18 | p = 1 |
|
|
222
|
+
| C: sin, cos, exp, arcsin (20) | no noise | 0 | 6 | 14 | p = 0.031 |
|
|
223
|
+
| | 1% noise | 0 | 16 | 4 | p = 3.1e-05 |
|
|
224
|
+
| | 5% noise | 0 | 17 | 3 | p = 1.5e-05 |
|
|
225
|
+
| | 10% noise | 0 | 12 | 8 | p = 0.00049 |
|
|
226
|
+
| A + B: the 59 algebraic laws | no noise | 8 | 1 | 50 | p = 0.039 |
|
|
227
|
+
| | 1% noise | 6 | 5 | 48 | p = 1 |
|
|
228
|
+
| | 5% noise | 8 | 4 | 47 | p = 0.39 |
|
|
229
|
+
| | 10% noise | 6 | 3 | 50 | p = 0.51 |
|
|
230
|
+
|
|
231
|
+
**How close the answers predict, against the true law.** These counts include runs that
|
|
232
|
+
did not find the exact law. Error is the relative RMS error at 200 random points in the
|
|
233
|
+
ranges. Each cell counts the runs whose answer is within that error.
|
|
234
|
+
|
|
235
|
+
| laws | noise | runs | within 0.1%: Hybrid | PySR | within 1%: Hybrid | PySR | within 5%: Hybrid | PySR |
|
|
236
|
+
|---|---|---|---|---|---|---|---|---|
|
|
237
|
+
| all 79 | no noise | 79 each | 43 | 66 | 53 | 73 | 61 | 75 |
|
|
238
|
+
| | 1% noise | 790 each | 423 | 483 | 528 | 718 | 618 | 766 |
|
|
239
|
+
| | 5% noise | 790 each | 0 | 261 | 483 | 554 | 580 | 749 |
|
|
240
|
+
| | 10% noise | 790 each | 0 | 214 | 0 | 470 | 592 | 675 |
|
|
241
|
+
| 59 algebraic | no noise | 59 each | 43 | 53 | 50 | 57 | 55 | 57 |
|
|
242
|
+
| | 1% noise | 590 each | 423 | 377 | 500 | 557 | 558 | 580 |
|
|
243
|
+
| | 5% noise | 590 each | 0 | 206 | 472 | 429 | 540 | 570 |
|
|
244
|
+
| | 10% noise | 590 each | 0 | 176 | 0 | 380 | 543 | 523 |
|
|
245
|
+
|
|
246
|
+
**The hybrid's numbers shrink with noise.** On runs that find the exact law, the median
|
|
247
|
+
prediction error is:
|
|
248
|
+
|
|
249
|
+
| noise | Hybrid: exact runs | median error | PySR: exact runs | median error |
|
|
250
|
+
|---|---|---|---|---|
|
|
251
|
+
| no noise | 43 | 0.00% | 42 | 0.00% |
|
|
252
|
+
| 1% noise | 430 | 0.04% | 522 | 0.02% |
|
|
253
|
+
| 5% noise | 422 | 0.57% | 517 | 0.09% |
|
|
254
|
+
| 10% noise | 410 | 2.27% | 491 | 0.21% |
|
|
255
|
+
|
|
256
|
+
On simple products the hybrid answers `0.9927*Nn*mu` at 5% noise and `0.9751*Nn*mu` at
|
|
257
|
+
10% (`F = mu*Nn`; the same on `m*g*z`, `q/C`, `Ef*q2`), in every run. PySR answers `Nn*mu`.
|
|
258
|
+
|
|
259
|
+
- **The cause is the hybrid's fitting rule.** Step 4 fits on error relative to the noisy
|
|
260
|
+
`y`, `(prediction − y)/y`. Dividing by a noisy `y` pulls every coefficient down by about
|
|
261
|
+
2σ²: 0.5% at 5% noise, 2% at 10%.
|
|
262
|
+
- **The verdicts don't change.** These answers are still within the 5% check, so this
|
|
263
|
+
does not change any count above. But at around 15–20% noise the bias alone would push
|
|
264
|
+
coefficients past 5%.
|
|
265
|
+
- **Part of PySR's edge here is the benchmark.** Many Feynman laws have the coefficient
|
|
266
|
+
1, which PySR can write with no fitted number at all.
|
|
267
|
+
|
|
268
|
+
**Run time** (all methods running 18 jobs in parallel on a 22-thread laptop at about
|
|
269
|
+
1.2 GHz. Rerun alone on this laptop, four hybrid runs took 3 to 9 times less time):
|
|
270
|
+
|
|
271
|
+
| inputs | laws | Hybrid, median seconds per run | PySR, median seconds per run |
|
|
272
|
+
|---|---|---|---|
|
|
273
|
+
| 1 | 1 | 6 | 131 |
|
|
274
|
+
| 2 | 15 | 17 | 102 |
|
|
275
|
+
| 3 | 36 | 43 | 362 |
|
|
276
|
+
| 4 | 27 | 69 | 149 |
|
|
277
|
+
| all | 79 | 46 (total 34 CPU-hours) | 218 (total 181 CPU-hours) |
|
|
278
|
+
|
|
279
|
+
### Test 16: Test 15 with fewer rows (about 100 and about 30)
|
|
280
|
+
|
|
281
|
+
- **Data:** the same 79 laws and the same kind of grid, with fewer levels per input.
|
|
282
|
+
- About 100 rows: 1 input 100 levels, 2 inputs 10, 3 inputs 5, 4 inputs 3 (81 rows).
|
|
283
|
+
- About 30 rows: 30, 5, 3 and 2 levels (16 rows for 4 inputs).
|
|
284
|
+
- **Everything else as in Test 15:** noise levels, seeds, settings and scoring. The rules
|
|
285
|
+
were written down before running, and no method was changed.
|
|
286
|
+
|
|
287
|
+
**Laws (of 79) whose exact law the method finds in more than half its runs** (fixed
|
|
288
|
+
coefficient check):
|
|
289
|
+
|
|
290
|
+
| method | rows per law | no noise | 1% noise | 5% noise | 10% noise |
|
|
291
|
+
|---|---|---|---|---|---|
|
|
292
|
+
| BACON (original) | about 1000 (Test 15) | 40 | 28 | 19 | 14 |
|
|
293
|
+
| | about 100 | 40 | 28 | 17 | 17 |
|
|
294
|
+
| | about 30 | 29 | 20 | 15 | 10 |
|
|
295
|
+
| BACON-robust | about 1000 (Test 15) | 44 | 41 | 36 | 14 |
|
|
296
|
+
| | about 100 | 33 | 27 | 14 | 0 |
|
|
297
|
+
| | about 30 | 14 | 11 | 0 | 0 |
|
|
298
|
+
| PySINDy | about 1000 (Test 15) | 35 | 0 | 0 | 0 |
|
|
299
|
+
| | about 100 | 34 | 1 | 0 | 0 |
|
|
300
|
+
| | about 30 | 30 | 6 | 0 | 0 |
|
|
301
|
+
| Hybrid | about 1000 (Test 15) | 43 | 43 | 42 | 41 |
|
|
302
|
+
| | about 100 | 43 | 43 | 41 | 37 |
|
|
303
|
+
| | about 30 | 43 | 29 | 26 | 23 |
|
|
304
|
+
| PySR | about 1000 (Test 15) | 42 | 50 | 50 | 49 |
|
|
305
|
+
| | about 100 | 24 | 4 | 2 | 1 |
|
|
306
|
+
| | about 30 | 28 | 0 | 0 | 0 |
|
|
307
|
+
|
|
308
|
+
**Hybrid against PySR, head to head.** Each cell: laws where the hybrid finds the exact
|
|
309
|
+
law in more runs than PySR, then laws where PySR does, then the two-sided sign test.
|
|
310
|
+
|
|
311
|
+
| rows per law | no noise | 1% noise | 5% noise | 10% noise |
|
|
312
|
+
|---|---|---|---|---|
|
|
313
|
+
| about 1000 (Test 15) | 8 to 7, p = 1 | 6 to 21, p = 0.0059 | 8 to 21, p = 0.024 | 6 to 15, p = 0.078 |
|
|
314
|
+
| about 100 | 20 to 1, p = 2.1e-05 | 43 to 15, p = 0.00031 | 42 to 11, p = 2.2e-05 | 38 to 10, p = 6.2e-05 |
|
|
315
|
+
| about 30 | 19 to 4, p = 0.0026 | 43 to 2, p = 5.9e-11 | 41 to 1, p = 2e-11 | 36 to 0, p = 2.9e-11 |
|
|
316
|
+
|
|
317
|
+
With the original coefficient check, the 1% verdict at about 100 rows is level (36 to 21,
|
|
318
|
+
p = 0.063). Every other cell above is significant either way.
|
|
319
|
+
|
|
320
|
+
**The hybrid by number of inputs** (laws found in more than half the runs; no noise, 1%,
|
|
321
|
+
5%, 10%):
|
|
322
|
+
|
|
323
|
+
| inputs (laws) | Test 15 | about 100 rows | about 30 rows |
|
|
324
|
+
|---|---|---|---|
|
|
325
|
+
| 1 (1) | 1000 levels: 0, 0, 0, 0 | 100 levels: 0, 0, 0, 0 | 30 levels: 0, 0, 0, 0 |
|
|
326
|
+
| 2 (15) | 32 levels: 13, 13, 12, 12 | 10 levels: 13, 13, 12, 11 | 5 levels: 13, 12, 11, 11 |
|
|
327
|
+
| 3 (36) | 10 levels: 17, 17, 17, 16 | 5 levels: 17, 17, 17, 15 | 3 levels: 17, 14, 13, 12 |
|
|
328
|
+
| 4 (27) | 6 levels: 13, 13, 13, 13 | 3 levels: 13, 13, 12, 11 | 2 levels: 13, 3, 2, 0 |
|
|
329
|
+
|
|
330
|
+
**Median prediction error** (normalized RMS error at 200 random points, all runs; both
|
|
331
|
+
methods return a formula in every run). Hybrid / PySR:
|
|
332
|
+
|
|
333
|
+
| rows per law | 1% noise | 5% noise | 10% noise |
|
|
334
|
+
|---|---|---|---|
|
|
335
|
+
| about 1000 (Test 15) | 0.09% / 0.06% | 0.77% / 0.29% | 2.6% / 0.60% |
|
|
336
|
+
| about 100 | 0.20% / 0.70% | 1.3% / 3.4% | 3.4% / 6.7% |
|
|
337
|
+
| about 30 | 0.76% / 2.0% | 3.4% / 8.4% | 6.7% / 15% |
|
|
338
|
+
|
|
339
|
+
- **PySR, with its default choice, collapses with noise and few rows; the hybrid does
|
|
340
|
+
not** (with `"score"` it does not collapse either: Test 17). At about 100 rows the
|
|
341
|
+
hybrid is almost unchanged from Test 15. PySR finds 4, 2 and 1 laws with noise, and none
|
|
342
|
+
at about 30 rows.
|
|
343
|
+
- **Why PySR collapses** (checked on one run, I.12.1 `F = mu*Nn`, about 100 rows, 1%
|
|
344
|
+
noise):
|
|
345
|
+
- PySR keeps `Nn*mu` among its formulas, with the highest score of any.
|
|
346
|
+
- Its default choice (`model_selection="best"`) only considers formulas whose loss is
|
|
347
|
+
within 1.5 times the lowest. With 100 rows, long formulas full of `cos` and `exp` fit
|
|
348
|
+
the noise down to a loss of 0.0057, while `Nn*mu` has 0.0135, the noise level.
|
|
349
|
+
- So it answers `Nn*(-0.002042*Nn*mu*(cos(Nn*exp(mu)) - cos(Nn*mu*cos(mu))) + mu)`.
|
|
350
|
+
- With Test 15's 1024 rows, long formulas reach only 0.0093 against 0.0098, so
|
|
351
|
+
`Nn*mu` is chosen.
|
|
352
|
+
- Test 17 (below) reran these PySR runs with its `"score"` choice.
|
|
353
|
+
- **The hybrid's weak spot is 2 levels per input with noise:** the 4-input laws at about
|
|
354
|
+
30 rows (16 rows) drop from 13 to 3, 2 and 0. Two points cannot tell a straight line
|
|
355
|
+
from a curve, so many wrong formulas fit the data equally well. It also loses the other
|
|
356
|
+
algebraic laws (kind B) with noise at about 30 rows: 6, 0 and 0, against 8, 7 and 6 in
|
|
357
|
+
Test 15.
|
|
358
|
+
- Full analysis, including BACON and PySINDy: bacon-vs-pysindy README, Test 16.
|
|
359
|
+
|
|
360
|
+
### Test 17: Test 16 again, PySR choosing with `model_selection="score"`
|
|
361
|
+
|
|
362
|
+
- **Setup:** Test 16's data, seeds and PySR settings, with one change. PySR picks the
|
|
363
|
+
formula with the highest score among the ones it kept (`"score"`), with no loss
|
|
364
|
+
cut-off. Its default `"best"` only looks at formulas within 1.5 times the lowest loss.
|
|
365
|
+
The hybrid was not rerun: its Test 16 answers are compared run for run.
|
|
366
|
+
- **Check:** PySR's search repeated exactly. In all 4,898 runs the formula `"best"`
|
|
367
|
+
would pick is Test 16's answer, so only the choice changed.
|
|
368
|
+
- Rules were written down before running (bacon-vs-pysindy README, Test 17). PySR got
|
|
369
|
+
this second setting after its first failed; the hybrid got no second setting.
|
|
370
|
+
|
|
371
|
+
**Laws found in more than half the runs** (of 79; fixed coefficient check):
|
|
372
|
+
|
|
373
|
+
| method | rows per law | no noise | 1% noise | 5% noise | 10% noise |
|
|
374
|
+
|---|---|---|---|---|---|
|
|
375
|
+
| Hybrid | about 100 | 43 | 43 | 41 | 37 |
|
|
376
|
+
| PySR, `"best"` (Test 16) | about 100 | 24 | 4 | 2 | 1 |
|
|
377
|
+
| PySR, `"score"` | about 100 | 50 | 45 | 38 | 34 |
|
|
378
|
+
| Hybrid | about 30 | 43 | 29 | 26 | 23 |
|
|
379
|
+
| PySR, `"best"` (Test 16) | about 30 | 28 | 0 | 0 | 0 |
|
|
380
|
+
| PySR, `"score"` | about 30 | 45 | 46 | 37 | 29 |
|
|
381
|
+
|
|
382
|
+
**Hybrid against PySR with `"score"`, head to head.** Each cell: laws where the hybrid
|
|
383
|
+
finds the exact law in more runs, then laws where PySR does, then the two-sided sign test.
|
|
384
|
+
|
|
385
|
+
| rows per law | no noise | 1% noise | 5% noise | 10% noise |
|
|
386
|
+
|---|---|---|---|---|
|
|
387
|
+
| about 100 | 3 to 10, p = 0.092 | 10 to 14, p = 0.54 | 14 to 15, p = 1 | 14 to 15, p = 1 |
|
|
388
|
+
| about 30 | 8 to 10, p = 0.81 | 10 to 41, p = 1.5e-05 | 10 to 41, p = 1.5e-05 | 9 to 36, p = 6.6e-05 |
|
|
389
|
+
|
|
390
|
+
**By kind of law** (A one product of powers, B other algebraic, C with `sin`, `cos`, `exp`
|
|
391
|
+
or `arcsin`), laws found in more than half the runs, hybrid / PySR with `"score"`:
|
|
392
|
+
|
|
393
|
+
| kind | rows per law | no noise | 1% noise | 5% noise | 10% noise |
|
|
394
|
+
|---|---|---|---|---|---|
|
|
395
|
+
| A (35) | about 100 | 35 / 34 | 35 / 32 | 35 / 28 | 35 / 25 |
|
|
396
|
+
| A (35) | about 30 | 35 / 32 | 23 / 31 | 26 / 26 | 23 / 23 |
|
|
397
|
+
| B (24) | about 100 | 8 / 8 | 8 / 7 | 6 / 6 | 2 / 5 |
|
|
398
|
+
| B (24) | about 30 | 8 / 5 | 6 / 7 | 0 / 5 | 0 / 2 |
|
|
399
|
+
| C (20) | about 100 | 0 / 8 | 0 / 6 | 0 / 4 | 0 / 4 |
|
|
400
|
+
| C (20) | about 30 | 0 / 8 | 0 / 8 | 0 / 6 | 0 / 4 |
|
|
401
|
+
|
|
402
|
+
**Median prediction error** at 200 random points, hybrid / PySR with `"score"` (PySR with
|
|
403
|
+
`"best"` in brackets):
|
|
404
|
+
|
|
405
|
+
| rows per law | 1% noise | 5% noise | 10% noise |
|
|
406
|
+
|---|---|---|---|
|
|
407
|
+
| about 100 | 0.20% / 0.18% (0.70%) | 1.3% / 1.2% (3.4%) | 3.4% / 2.6% (6.7%) |
|
|
408
|
+
| about 30 | 0.76% / 0.46% (2.0%) | 3.4% / 2.8% (8.4%) | 6.7% / 5.7% (15%) |
|
|
409
|
+
|
|
410
|
+
- **Test 16's win over PySR came from PySR's default choice.** With `"score"`, PySR finds
|
|
411
|
+
about as many laws as the hybrid at about 100 rows, and more at about 30 rows with
|
|
412
|
+
noise.
|
|
413
|
+
- **At about 100 rows the two are level, but on different laws.** The hybrid keeps every
|
|
414
|
+
product-of-powers law (A) at every noise level, where PySR loses up to 10. PySR finds
|
|
415
|
+
4 to 8 trig and exponential laws (C), which the hybrid cannot write.
|
|
416
|
+
- **At about 30 rows PySR is better with noise.** Most of the difference is the 4-input
|
|
417
|
+
laws, which then have 2 levels per input: the hybrid finds 13, 3, 2 and 0 of 27,
|
|
418
|
+
PySR 13, 10, 8 and 7. This is the hybrid's weak spot from Test 16.
|
|
419
|
+
- **PySR's answers now predict slightly better than the hybrid's** at every noise level
|
|
420
|
+
and both sizes.
|
|
421
|
+
- **`"score"` hardly costs PySR anything.** It loses one law that `"best"` found (I.30.5
|
|
422
|
+
at about 100 rows and 1% noise: it answers `lambd/(d*n)`, the small-angle form of
|
|
423
|
+
`asin(lambd/(n*d))`), and on clean data it finds 26 and 17 more laws.
|
|
424
|
+
- Full analysis: bacon-vs-pysindy README, Test 17.
|
|
425
|
+
|
|
426
|
+
### Run time against number of rows (Tests 15 and 16)
|
|
427
|
+
|
|
428
|
+
Every method ran 18 jobs in parallel on the laptop above, so both methods are slower than
|
|
429
|
+
on an idle machine. In the Test 16 pilot on an idle machine, PySR took 35–45 s and the
|
|
430
|
+
hybrid 3–13 s per run.
|
|
431
|
+
|
|
432
|
+
| rows per law | Hybrid, median seconds per run | PySR, median seconds per run | PySR slower by | total CPU-hours, Hybrid / PySR |
|
|
433
|
+
|---|---|---|---|---|
|
|
434
|
+
| about 1000 (Test 15) | 46 | 218 | 4.8× | 34 / 181 |
|
|
435
|
+
| about 100 (Test 16) | 17 | 79 | 4.6× | 13 / 55 |
|
|
436
|
+
| about 30 (Test 16) | 16 | 61 | 3.8× | 12 / 43 |
|
|
437
|
+
|
|
438
|
+
- **PySR is slower at every size.** The gap shrinks with fewer rows: about 5× at 1000
|
|
439
|
+
and 100 rows, about 4× at 30.
|
|
440
|
+
- **The hybrid's time barely changes between 100 and 30 rows** (17 against 16 s). Most of
|
|
441
|
+
its time goes on trying combinations of terms and on repeated cross-validation (5 folds
|
|
442
|
+
× 5 repeats), not on the rows themselves.
|
|
443
|
+
- **PySR gets faster as rows drop.** It runs a fixed number of search rounds and checks
|
|
444
|
+
every candidate formula on every row, so fewer rows means less work per round.
|
|
445
|
+
|
|
446
|
+
### Tests 13–14: BACON's own five laws (the hybrid was designed after seeing these)
|
|
447
|
+
|
|
448
|
+
Exact-law runs. "given" is the authors' own small design and "dense" a larger grid. Same
|
|
449
|
+
data for every method, run for run. BACON is the original at its code defaults.
|
|
450
|
+
|
|
451
|
+
- **PySR 2.7.2 settings:** defaults with `+ - * /` only, maximum size 30, deterministic.
|
|
452
|
+
- **Kepler is outside PySR's formulas** with these operators: it cannot write `P^(2/3)`.
|
|
453
|
+
- **This is a development check, not a fair contest:** the hybrid was designed knowing
|
|
454
|
+
how BACON and PySINDy failed on these laws.
|
|
455
|
+
|
|
456
|
+
| law | design | noise | BACON | PySINDy | Hybrid | PySR |
|
|
457
|
+
|---|---|---|---|---|---|---|
|
|
458
|
+
| ideal gas `V = M(T + 273)/P` | given (27 rows) | none (1 run) | 0 | 0 | **1** | **1** |
|
|
459
|
+
| | | 1% (20 runs) | 0 | 0 | 0 | **2** |
|
|
460
|
+
| | | 5% (20 runs) | 0 | 0 | 0 | **3** |
|
|
461
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | **1** |
|
|
462
|
+
| | dense (216 rows) | none (1 run) | 0 | 0 | **1** | **1** |
|
|
463
|
+
| | | 1% (20 runs) | 0 | 0 | 0 | **19** |
|
|
464
|
+
| | | 5% (20 runs) | 0 | 0 | 0 | **5** |
|
|
465
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
466
|
+
| Ohm (wire) `I = T·D²/(2(L + 3))` | given (27 rows) | none (1 run) | **1** | 0 | **1** | 0 |
|
|
467
|
+
| | | 1% (20 runs) | 0 | 0 | **18** | 0 |
|
|
468
|
+
| | | 5% (20 runs) | 0 | 0 | **6** | 0 |
|
|
469
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
470
|
+
| | dense (216 rows) | none (1 run) | **1** | 0 | **1** | 0 |
|
|
471
|
+
| | | 1% (20 runs) | 0 | 0 | **20** | 6 |
|
|
472
|
+
| | | 5% (20 runs) | 0 | 0 | **12** | 2 |
|
|
473
|
+
| | | 10% (20 runs) | 0 | 0 | **3** | 1 |
|
|
474
|
+
| Black `T_f = (M₁T₁ + M₂T₂)/(M₁ + M₂)` | given (81 rows) | none (1 run) | **1** | 0 | **1** | **1** |
|
|
475
|
+
| | | 1% (20 runs) | 0 | 0 | **20** | 8 |
|
|
476
|
+
| | | 5% (20 runs) | 0 | 0 | 4 | **5** |
|
|
477
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
478
|
+
| | dense (1296 rows) | none (1 run) | **1** | 0 | **1** | **1** |
|
|
479
|
+
| | | 1% (20 runs) | 0 | 0 | **20** | 10 |
|
|
480
|
+
| | | 5% (20 runs) | 0 | 0 | 0 | 0 |
|
|
481
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
482
|
+
| Kepler `D = P^(2/3)` | given (6 rows) | none (1 run) | **1** | 0 | **1** | 0 |
|
|
483
|
+
| | | 1% (20 runs) | **18** | 0 | 13 | 0 |
|
|
484
|
+
| | | 5% (20 runs) | **13** | 0 | 6 | 0 |
|
|
485
|
+
| | | 10% (20 runs) | 5 | 0 | **6** | 0 |
|
|
486
|
+
| | dense (12 rows) | none (1 run) | **1** | 0 | **1** | 0 |
|
|
487
|
+
| | | 1% (20 runs) | **20** | 0 | 18 | 0 |
|
|
488
|
+
| | | 5% (20 runs) | 15 | 0 | **18** | 0 |
|
|
489
|
+
| | | 10% (20 runs) | 4 | 0 | **15** | 0 |
|
|
490
|
+
| synthetic `Y = 3/(X + 2)` | given (5 rows) | none (1 run) | **1** | 0 | **1** | **1** |
|
|
491
|
+
| | | 1% (20 runs) | **8** | 0 | 3 | 0 |
|
|
492
|
+
| | | 5% (20 runs) | 0 | 0 | 0 | 0 |
|
|
493
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
494
|
+
| | dense (12 rows) | none (1 run) | **1** | 0 | **1** | **1** |
|
|
495
|
+
| | | 1% (20 runs) | 2 | 0 | **15** | 0 |
|
|
496
|
+
| | | 5% (20 runs) | 0 | 0 | **1** | 0 |
|
|
497
|
+
| | | 10% (20 runs) | 0 | 0 | 0 | 0 |
|
|
498
|
+
|
|
499
|
+
### What the benchmarks say about the hybrid against PySR
|
|
500
|
+
|
|
501
|
+
- **Algebraic laws: level.** On the 59 laws without `sin`, `cos`, `exp` or `arcsin`, the
|
|
502
|
+
two find about the same laws at every noise level (after-the-run split, not
|
|
503
|
+
significant).
|
|
504
|
+
- The hybrid is more reliable on some laws: 10 of 10 runs at every noise level, where
|
|
505
|
+
PySR gets 3–4 of 10 on I.18.4 `(m1*r1 + m2*r2)/(m1 + m2)` and 2–5 on III.21.20
|
|
506
|
+
`-rho_c_0*q*A_vec/m`.
|
|
507
|
+
- PySR finds II.37.1 `mom*(1 + chi)*B` in 10 of 10 runs at every noise level, and
|
|
508
|
+
I.16.6 on clean data. The hybrid finds neither in any run. `chi` gets no proposed
|
|
509
|
+
power, so the term `mom*chi*B` is not in its list.
|
|
510
|
+
- **Trig and exponential laws: PySR only.** The hybrid cannot write them. This is the
|
|
511
|
+
whole of PySR's lead in the overall counts.
|
|
512
|
+
- **Noise: the hybrid's law count barely moves** (43, 43, 42, 41 laws). But its
|
|
513
|
+
coefficients shrink with noise (above), so PySR's answers are closer to the true law
|
|
514
|
+
at 5–10% noise.
|
|
515
|
+
- **Clean data: PySR sometimes adds a tiny extra term**, e.g.
|
|
516
|
+
`omega_0*v/(c - v + 7.18e-8) + omega_0`. That costs it 11 laws that it finds at 1%
|
|
517
|
+
noise.
|
|
518
|
+
- **Small designs (5–27 rows, Tests 13–14): the hybrid holds up better.** PySR builds
|
|
519
|
+
long formulas that fit the few points. Neither finds the ideal gas law, because
|
|
520
|
+
`T + 273` and its first-order twin fit equally well over the narrow range of `T`.
|
|
521
|
+
- **Fewer rows on the 79 Feynman laws (Tests 16–17): the result depends on how PySR
|
|
522
|
+
chooses its formula.**
|
|
523
|
+
- With PySR's default (`"best"`, Test 16) the hybrid beats it at every noise level, at
|
|
524
|
+
about 100 and about 30 rows (every p ≤ 0.003). PySR finds 4, 2 and 1 laws with noise
|
|
525
|
+
at about 100 rows, and none at about 30.
|
|
526
|
+
- With `"score"` (Test 17) the two are level at about 100 rows. At about 30 rows PySR
|
|
527
|
+
beats the hybrid with noise (41 laws to 10, 41 to 10, 36 to 9), mostly on the
|
|
528
|
+
4-input laws, which then have 2 levels per input.
|
|
529
|
+
- So Test 16 does not confirm Tests 13–14's "the hybrid holds up better with few
|
|
530
|
+
rows" against PySR at its best. Tests 13–14 used PySR's default choice too.
|
|
531
|
+
- **Cost: the hybrid needs about a fifth of PySR's CPU time** (34 against 181 CPU-hours
|
|
532
|
+
for Test 15, 13 against 55 at about 100 rows), and about a quarter to a third at about
|
|
533
|
+
30 rows (12 against 43).
|
|
534
|
+
|
|
535
|
+
### Real neuroscience data (exploratory; full write-ups in `findings/`)
|
|
536
|
+
|
|
537
|
+
- **Three measured datasets,** run on 2026-11-16 with the same method settings as above
|
|
538
|
+
(PySR: the Feynman operators, both `"best"` and `"score"` from one search).
|
|
539
|
+
- **Not a pre-registered test.** The rules were set during the session, not written down
|
|
540
|
+
before running.
|
|
541
|
+
- **Scoring:** every number is a held-out error. Each method's formula is evaluated on
|
|
542
|
+
cells or neurons it did not fit on, and compared with the measured value.
|
|
543
|
+
- **Fits:**
|
|
544
|
+
- Allen: 5 splits of 80/20 over 2,336 cells.
|
|
545
|
+
- NeuroMorpho: 5 fits of 2,000 neurons each, scored on the same 50,000 held-out neurons.
|
|
546
|
+
- **Hybrid-free** is the hybrid with the side-run switch `POWER_FREE = True` (see the
|
|
547
|
+
settings table). It was added *after* the benchmark hybrid failed the wiring test, so
|
|
548
|
+
its wiring result is a development check, like Tests 13–14, not an independent test.
|
|
549
|
+
|
|
550
|
+
**Held-out median error / RMS log error** (lower is better):
|
|
551
|
+
|
|
552
|
+
| dataset | Hybrid | Hybrid-free | PySR "best" | PySR "score" | PySINDy | best simple reference |
|
|
553
|
+
|---|---|---|---|---|---|---|
|
|
554
|
+
| Allen: rheobase ← R, τ, gap | 29.0% / 0.486 | 28.8% / 0.483 | 26.6% / **0.443** | 31.9% / 0.481 | **24.6%** / 0.530 | 25.6% / 0.405 (`515·gap/R`) |
|
|
555
|
+
| NeuroMorpho: volume ← S, L, d | **7.8% / 0.232** | **7.8% / 0.232** | 30.1% / 0.531 | 36.9% / 0.500 | 22.9% / 1.371 | 1.5% / 0.290 (`S·d/4`) |
|
|
556
|
+
| NeuroMorpho: length ← W, H, D, n | 30.9% / 0.592 | **22.2% / 0.383** | 38.7% / 0.561 | 59.4% / 1.066 | 30.3% / 1.555 | 19.3% / 0.339 (power law, log fit) |
|
|
557
|
+
|
|
558
|
+
**Readable law found** (fits giving it):
|
|
559
|
+
|
|
560
|
+
| dataset | Hybrid | Hybrid-free | PySR | PySINDy |
|
|
561
|
+
|---|---|---|---|---|
|
|
562
|
+
| Allen | `gap/R` 6 of 6 | `gap/R` 3 of 6, `gap^0.8/R` 3 | `gap/R` 0 of 6 | about 300 terms |
|
|
563
|
+
| Volume | cylinder law 5 of 5 (`S²/L`) | the same | `c·S·d` 3 of 10 picks | 195 terms |
|
|
564
|
+
| Wiring | none (sums of integer terms) | the power law in 5 of 5, plus small extra terms | none | 617 terms |
|
|
565
|
+
|
|
566
|
+
- **Where the hybrid is clearly ahead: the volume and wiring tests.** Its held-out error is
|
|
567
|
+
far below PySR's and PySINDy's on volume, and below both on wiring with
|
|
568
|
+
`POWER_FREE`. It also finds a readable law in every fit, where PySINDy keeps hundreds of
|
|
569
|
+
terms and PySR changes its answer from fit to fit.
|
|
570
|
+
- **Allen: no clear winner on error.**
|
|
571
|
+
- PySINDy has the lowest median error and PySR "best" the lowest log error.
|
|
572
|
+
- The hybrid is the only method that finds the textbook form `gap/R`, but its fitting
|
|
573
|
+
rule (relative error) pulls the coefficient to 393, against 515 for a log-scale fit.
|
|
574
|
+
- **No method beats a simple reference,** except where that reference is the textbook
|
|
575
|
+
law with the wrong constant.
|
|
576
|
+
- **`POWER_FREE` is not the default.** It changes the Allen answer to `gap^0.8/R` on
|
|
577
|
+
half the splits. It has not been run on the Feynman benchmark (Tests 15–17), where
|
|
578
|
+
free powers could add wrong candidates.
|
|
579
|
+
|
|
580
|
+
## Ideas for testing the hybrid against PySR
|
|
581
|
+
|
|
582
|
+
As in bacon-vs-pysindy: one test at a time, with rules written down before running and
|
|
583
|
+
both methods frozen. Rough cost: about 4 hours per 1,000 PySR runs on this laptop with 18
|
|
584
|
+
parallel jobs, about 1 hour per 1,000 hybrid runs.
|
|
585
|
+
|
|
586
|
+
**No new runs: re-score the saved Test 15 answers**
|
|
587
|
+
|
|
588
|
+
1. **Extrapolation.** Score every saved answer at points outside the training ranges
|
|
589
|
+
(e.g. each input up to twice its range). An exact law keeps working outside the range.
|
|
590
|
+
A formula that only fits inside it stops working, e.g. PySR's
|
|
591
|
+
`1.012*m_0*(1 + exp(-c/v))` for I.10.7. This shows how much each method's "close but
|
|
592
|
+
not exact" answers are worth. It costs minutes.
|
|
593
|
+
|
|
594
|
+
**New runs, both methods unchanged**
|
|
595
|
+
|
|
596
|
+
2. **Random samples instead of a grid.** Test 15 gave every method a factorial grid,
|
|
597
|
+
which is BACON's kind of data and the hybrid's home turf. Standard symbolic-regression
|
|
598
|
+
benchmarks (SRBench, SRSD) sample inputs at random, so there are no slices, and step 1
|
|
599
|
+
falls back to one global fit. This asks whether the hybrid's strength depends on
|
|
600
|
+
designed experiments. Same 79 laws and row counts.
|
|
601
|
+
3. **Noise of constant size** (sd = level × RMS of y, the SRBench convention) instead of
|
|
602
|
+
noise proportional to |y|. The current noise suits the hybrid's log fits and relative
|
|
603
|
+
errors. With constant noise, small values of `y` get large relative noise and can
|
|
604
|
+
change sign. Pairs naturally with idea 2 as one test with four conditions: grid or
|
|
605
|
+
random, proportional or constant noise.
|
|
606
|
+
4. **Higher noise: 15%, 20%, 30%.** This tests the bias above. The prediction is that
|
|
607
|
+
the hybrid starts missing laws it has the right terms for, at around 15–20%.
|
|
608
|
+
5. **Fewer rows. Done as Test 16** (about 100 and about 30 rows, above). PySR with its
|
|
609
|
+
default choice collapsed with noise (not with `"score"`, Test 17). The hybrid held at
|
|
610
|
+
about 100 rows and lost the 2-level laws at about 30.
|
|
611
|
+
6. **Constants that are not 1.** Many Feynman laws can be written with no fitted number,
|
|
612
|
+
which PySR does exactly. Two ways to remove that edge:
|
|
613
|
+
- Multiply each law by a random constant.
|
|
614
|
+
- Use SRSD-Feynman (Matsubara et al.), which keeps the physical constants and more
|
|
615
|
+
realistic ranges.
|
|
616
|
+
|
|
617
|
+
This also tests the hybrid with very small or large values, e.g. ε₀ ≈ 8.85e-12.
|
|
618
|
+
7. **Irrelevant inputs.** Add 1–3 inputs that do not affect `y`; SRSD has "dummy
|
|
619
|
+
variable" versions for this. Both methods must leave them out. The hybrid's term list
|
|
620
|
+
grows with the square of the number of inputs.
|
|
621
|
+
8. **More inputs: the 21 Feynman laws with 5–9 inputs**, held out so far.
|
|
622
|
+
- 8 of them use trig or exp: I.12.11, I.40.1, I.41.16, II.11.17, II.35.18, II.35.21,
|
|
623
|
+
III.9.52, III.14.14.
|
|
624
|
+
- This tests how the hybrid's search scales, and whether its 5-coefficient limit
|
|
625
|
+
blocks laws.
|
|
626
|
+
9. **PySR given more:**
|
|
627
|
+
- 10 times the iterations: does more search find more laws, or add more extra
|
|
628
|
+
terms?
|
|
629
|
+
- Its "score" model selection instead of "best". **Done as Test 17** on Test 16's
|
|
630
|
+
data: PySR's collapse goes away, and on clean data it finds 26 and 17 more laws.
|
|
631
|
+
Not yet run on Test 15's data (about 1000 rows), where the clean-data extra terms
|
|
632
|
+
were first seen.
|
|
633
|
+
- Only the hybrid's operators on the algebraic laws.
|
|
634
|
+
|
|
635
|
+
This checks that PySR is not handicapped by its default settings.
|
|
636
|
+
|
|
637
|
+
**Changes to the hybrid (each a switch, frozen before the test)**
|
|
638
|
+
|
|
639
|
+
10. **Remove the coefficient bias:** refine on error relative to the fitted value instead
|
|
640
|
+
of the noisy `y`, repeating the fit. Test together with idea 4.
|
|
641
|
+
11. **`sin`, `cos`, `exp` shapes in step 1.** Propose `g(x_j)` for a small set of shapes,
|
|
642
|
+
the same way as powers. This could reach 9 of the 20 trig laws: I.18.12, I.18.14,
|
|
643
|
+
II.6.11, II.6.15b, II.15.4, II.15.5, III.17.37, I.37.4, I.6.2a. The other 11 need the
|
|
644
|
+
inside of the function found too (e.g. `ω·t` or `θ/σ`).
|
|
645
|
+
12. **Ablations: switch off one part at a time** — the BACON step, the fraction form, or
|
|
646
|
+
cross-validation (in-sample error instead). This shows which part makes the
|
|
647
|
+
difference against PySR before building more on it (e.g. ABACUS ideas).
|
|
648
|
+
13. **The BACON step inside PySR:** give PySR the proposed terms `x_j^p` as extra inputs.
|
|
649
|
+
This shows whether BACON's proposals help a genetic search too.
|
|
650
|
+
|
|
651
|
+
**Suggested order:**
|
|
652
|
+
1. Idea 1: it is free.
|
|
653
|
+
2. Idea 9's model-selection check on Test 16's data: done (Test 17). Comparisons with
|
|
654
|
+
PySR from here on should use `"score"`, or report both choices.
|
|
655
|
+
3. Ideas 2 + 3 as the next test, run on fresh noise seeds. It would also repeat the
|
|
656
|
+
after-the-run "level on algebraic laws" result as a proper test.
|
|
657
|
+
4. Ideas 4 + 10, then idea 11.
|
|
658
|
+
|
|
659
|
+
## Files
|
|
660
|
+
|
|
661
|
+
| file | what it is |
|
|
662
|
+
|---|---|
|
|
663
|
+
| `basin/core.py` | the method (copy of bacon-vs-pysindy's `hybrid.py`, see above) |
|
|
664
|
+
| `basin/__init__.py` | the library API: `discover` (accepts names), `settings` |
|
|
665
|
+
| `hybrid.py` | shim: `import hybrid` gives `basin.core` |
|
|
666
|
+
| `tests/`, `pyproject.toml`, `Makefile` | tests, packaging, release targets |
|
|
667
|
+
| `example.py` | small example: Black's law from a noisy 81-row grid |
|
|
668
|
+
| `requirements.txt` | package versions used for every result above |
|
|
669
|
+
| `benchmarks/test15_feynman.csv` | Test 15, every law × method × noise level: runs, exact (fixed and original check), right terms, median prediction error, median seconds |
|
|
670
|
+
| `benchmarks/test15_hybrid_pysr_answers.csv` | every hybrid and PySR answer in Test 15 (4 significant digits), with its verdict |
|
|
671
|
+
| `benchmarks/test16_feynman.csv` | Test 16, every grid × law × method × noise level: levels per input, rows, runs, exact (fixed and original check), right terms, median prediction error, median seconds |
|
|
672
|
+
| `benchmarks/test16_hybrid_pysr_answers.csv` | every hybrid and PySR answer in Test 16 (4 significant digits), with its verdict |
|
|
673
|
+
| `benchmarks/test17_feynman.csv` | Test 17, every grid × law × noise level for the hybrid, PySR with "best" (Test 16) and PySR with "score": runs, exact (fixed and original check), right terms, median prediction error |
|
|
674
|
+
| `benchmarks/test17_pysr_score_answers.csv` | every PySR answer with "score" in Test 17 (4 significant digits), with its verdict |
|
|
675
|
+
| `benchmarks/tests12_14_bacon_laws.csv` | Tests 12–14, BACON's five laws, every method |
|
|
676
|
+
| `findings/` | write-ups of the real-data runs (Allen, NeuroMorpho volume and wiring, the power switches) |
|
|
677
|
+
| `allen/run_allen.py`, `allen/results/` | Allen Cell Types runner, per-fit answers and `allen_scores.csv` |
|
|
678
|
+
| `neuromorpho/run_neuromorpho.py`, `neuromorpho/run_wiring.py`, `neuromorpho/results*/` | NeuroMorpho runners (volume, wiring), per-fit answers and scores |
|
|
679
|
+
| `data/allen/`, `data/neuromorpho/` | not in git (197 MB): the raw downloads (Allen API JSON, NeuroMorpho morphometry pages and merged CSV) |
|
|
680
|
+
|
|
681
|
+
## Per-law results, Test 15: hybrid / PySR
|
|
682
|
+
|
|
683
|
+
Exact-law runs, hybrid first, then PySR; the larger is in bold. Kind: A one product of
|
|
684
|
+
powers, B other algebraic, C with `sin`, `cos`, `exp` or `arcsin`.
|
|
685
|
+
|
|
686
|
+
| law | kind | formula | no noise (1 run) | 1% (10 runs) | 5% (10 runs) | 10% (10 runs) |
|
|
687
|
+
|---|---|---|---|---|---|---|
|
|
688
|
+
| I.6.2 | C | `f = exp(-(theta/sigma)**2/2)/(sqrt(2*pi)*sigma)` | 0 / 0 | 0 / 0 | 0 / **1** | 0 / **1** |
|
|
689
|
+
| I.6.2a | C | `f = exp(-theta**2/2)/sqrt(2*pi)` | 0 / **1** | 0 / **3** | 0 / **4** | 0 / **1** |
|
|
690
|
+
| I.6.2b | C | `f = exp(-((theta-theta1)/sigma)**2/2)/(sqrt(2*pi)*sigma)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
691
|
+
| I.8.14 | B | `d = sqrt((x2-x1)**2+(y2-y1)**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
692
|
+
| I.10.7 | B | `m = m_0/sqrt(1-v**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
693
|
+
| I.12.1 | A | `F = mu*Nn` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
694
|
+
| I.12.2 | A | `F = q1*q2*r/(4*pi*epsilon*r**3)` | 1 / 1 | 10 / 10 | **10** / 9 | 10 / 10 |
|
|
695
|
+
| I.12.4 | A | `Ef = q1*r/(4*pi*epsilon*r**3)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
696
|
+
| I.12.5 | A | `F = q2*Ef` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
697
|
+
| I.13.4 | B | `K = 1/2*m*(v**2+u**2+w**2)` | 0 / 0 | 0 / **1** | 0 / 0 | 0 / 0 |
|
|
698
|
+
| I.14.3 | A | `U = m*g*z` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
699
|
+
| I.14.4 | A | `U = 1/2*k_spring*x**2` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
700
|
+
| I.15.1 | B | `p = m_0*v/sqrt(1-v**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
701
|
+
| I.15.3t | B | `t1 = (t-u*x/c**2)/sqrt(1-u**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
702
|
+
| I.15.3x | B | `x1 = (x-u*t)/sqrt(1-u**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
703
|
+
| I.16.6 | B | `v1 = (u+v)/(1+u*v/c**2)` | 0 / **1** | 0 / **4** | 0 / **2** | 0 / 0 |
|
|
704
|
+
| I.18.4 | B | `r = (m1*r1+m2*r2)/(m1+m2)` | **1** / 0 | **10** / 3 | **10** / 4 | **10** / 3 |
|
|
705
|
+
| I.18.12 | C | `tau = r*F*sin(theta)` | 0 / 0 | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
706
|
+
| I.18.14 | C | `L = m*r*v*sin(theta)` | 0 / **1** | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
707
|
+
| I.24.6 | B | `E_n = 1/2*m*(omega**2+omega_0**2)*1/2*x**2` | 0 / 0 | 0 / 0 | 0 / **3** | 0 / 0 |
|
|
708
|
+
| I.25.13 | A | `Volt = q/C` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
709
|
+
| I.26.2 | C | `theta1 = arcsin(n*sin(theta2))` | 0 / **1** | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
710
|
+
| I.27.6 | B | `foc = 1/(1/d1+n/d2)` | 1 / 1 | **10** / 9 | 10 / 10 | 10 / 10 |
|
|
711
|
+
| I.29.4 | A | `k = omega/c` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
712
|
+
| I.29.16 | C | `x = sqrt(x1**2+x2**2-2*x1*x2*cos(theta1-theta2))` | 0 / 0 | 0 / **1** | 0 / **1** | 0 / 0 |
|
|
713
|
+
| I.30.3 | C | `Int = Int_0*sin(n*theta/2)**2/sin(theta/2)**2` | 0 / 0 | 0 / **2** | 0 / **2** | 0 / 0 |
|
|
714
|
+
| I.30.5 | C | `theta = arcsin(lambd/(n*d))` | 0 / **1** | 0 / **10** | 0 / **9** | 0 / 0 |
|
|
715
|
+
| I.32.5 | A | `Pwr = q**2*a**2/(6*pi*epsilon*c**3)` | 1 / 1 | **10** / 7 | **10** / 8 | **10** / 6 |
|
|
716
|
+
| I.34.1 | B | `omega = omega_0/(1-v/c)` | **1** / 0 | 10 / 10 | **10** / 7 | **10** / 7 |
|
|
717
|
+
| I.34.8 | A | `omega = q*v*B/p` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
718
|
+
| I.34.14 | B | `omega = (1+v/c)/sqrt(1-v**2/c**2)*omega_0` | 0 / 0 | 0 / **1** | 0 / 0 | 0 / 0 |
|
|
719
|
+
| I.34.27 | A | `E_n = (h/(2*pi))*omega` | **1** / 0 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
720
|
+
| I.37.4 | C | `Int = I1+I2+2*sqrt(I1*I2)*cos(delta)` | 0 / 0 | 0 / **2** | 0 / **2** | 0 / 0 |
|
|
721
|
+
| I.38.12 | A | `r = 4*pi*epsilon*(h/(2*pi))**2/(m*q**2)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
722
|
+
| I.39.1 | A | `E_n = 3/2*pr*V` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
723
|
+
| I.39.11 | B | `E_n = 1/(gamma-1)*pr*V` | 1 / 1 | 10 / 10 | 10 / 10 | 4 / **10** |
|
|
724
|
+
| I.39.22 | A | `pr = n*kb*T/V` | **1** / 0 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
725
|
+
| I.43.16 | A | `v = mu_drift*q*Volt/d` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
726
|
+
| I.43.31 | A | `D = mob*kb*T` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
727
|
+
| I.43.43 | B | `kappa = 1/(gamma-1)*kb*v/A` | 1 / 1 | 10 / 10 | 10 / 10 | 7 / **10** |
|
|
728
|
+
| I.47.23 | A | `c = sqrt(gamma*pr/rho)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
729
|
+
| I.48.2 | B | `E_n = m*c**2/sqrt(1-v**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
730
|
+
| I.50.26 | C | `x = x1*(cos(omega*t)+alpha*cos(omega*t)**2)` | 0 / 0 | 0 / **7** | 0 / **7** | 0 / **8** |
|
|
731
|
+
| II.3.24 | A | `flux = Pwr/(4*pi*r**2)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
732
|
+
| II.4.23 | A | `Volt = q/(4*pi*epsilon*r)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
733
|
+
| II.6.11 | C | `Volt = 1/(4*pi*epsilon)*p_d*cos(theta)/r**2` | 0 / 0 | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
734
|
+
| II.6.15b | C | `Ef = p_d/(4*pi*epsilon)*3*cos(theta)*sin(theta)/r**3` | 0 / **1** | 0 / **8** | 0 / **9** | 0 / **8** |
|
|
735
|
+
| II.8.7 | A | `E_n = 3/5*q**2/(4*pi*epsilon*d)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
736
|
+
| II.8.31 | A | `E_den = epsilon*Ef**2/2` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
737
|
+
| II.10.9 | B | `Ef = sigma_den/epsilon*1/(1+chi)` | 1 / 1 | 10 / 10 | 10 / 10 | 9 / 9 |
|
|
738
|
+
| II.11.27 | B | `Pol = n*alpha/(1-(n*alpha/3))*epsilon*Ef` | 0 / 0 | 0 / **1** | 0 / 0 | 0 / 0 |
|
|
739
|
+
| II.11.28 | B | `theta = 1+n*alpha/(1-(n*alpha/3))` | **1** / 0 | **10** / 0 | **2** / 0 | 0 / 0 |
|
|
740
|
+
| II.13.17 | A | `B = 1/(4*pi*epsilon*c**2)*2*I/r` | 1 / 1 | 10 / 10 | **10** / 9 | 10 / 10 |
|
|
741
|
+
| II.13.23 | B | `rho_c = rho_c_0/sqrt(1-v**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
742
|
+
| II.13.34 | B | `j = rho_c_0*v/sqrt(1-v**2/c**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
743
|
+
| II.15.4 | C | `E_n = -mom*B*cos(theta)` | 0 / 0 | 0 / **4** | 0 / **4** | 0 / **5** |
|
|
744
|
+
| II.15.5 | C | `E_n = -p_d*Ef*cos(theta)` | 0 / 0 | 0 / **4** | 0 / **4** | 0 / **5** |
|
|
745
|
+
| II.24.17 | B | `k = sqrt(omega**2/c**2-pi**2/d**2)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
746
|
+
| II.27.16 | A | `flux = epsilon*c*Ef**2` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
747
|
+
| II.27.18 | A | `E_den = epsilon*Ef**2` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
748
|
+
| II.34.2 | A | `mom = q*v*r/2` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
749
|
+
| II.34.2a | A | `I = q*v/(2*pi*r)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
750
|
+
| II.34.11 | A | `omega = g_*q*B/(2*m)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
751
|
+
| II.34.29a | A | `mom = q*h/(4*pi*m)` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
752
|
+
| II.37.1 | B | `E_n = mom*(1+chi)*B` | 0 / 0 | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
753
|
+
| II.38.3 | A | `F = Y*A*x/d` | **1** / 0 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
754
|
+
| II.38.14 | B | `mu_S = Y/(2*(1+sigma))` | 1 / 1 | 10 / 10 | 10 / 10 | **10** / 8 |
|
|
755
|
+
| III.4.32 | C | `n = 1/(exp((h/(2*pi))*omega/(kb*T))-1)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
756
|
+
| III.4.33 | C | `E_n = (h/(2*pi))*omega/(exp((h/(2*pi))*omega/(kb*T))-1)` | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 |
|
|
757
|
+
| III.7.38 | A | `omega = 2*mom*B/(h/(2*pi))` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
758
|
+
| III.8.54 | C | `prob = sin(E_n*t/(h/(2*pi)))**2` | 0 / 0 | 0 / **2** | 0 / **1** | 0 / 0 |
|
|
759
|
+
| III.10.19 | B | `E_n = mom*sqrt(Bx**2+By**2+Bz**2)` | 0 / 0 | 0 / 0 | 0 / **1** | 0 / 0 |
|
|
760
|
+
| III.12.43 | A | `L = n*(h/(2*pi))` | **1** / 0 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
761
|
+
| III.13.18 | A | `v = 2*E_n*d**2*k/(h/(2*pi))` | 1 / 1 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
762
|
+
| III.15.12 | C | `E_n = 2*U*(1-cos(k*d))` | 0 / **1** | 0 / **10** | 0 / **9** | 0 / **9** |
|
|
763
|
+
| III.15.14 | A | `m = (h/(2*pi))**2/(2*E_n*d**2)` | 1 / 1 | **10** / 8 | **10** / 9 | **10** / 9 |
|
|
764
|
+
| III.15.27 | A | `k = 2*pi*alpha/(n*d)` | **1** / 0 | 10 / 10 | 10 / 10 | 10 / 10 |
|
|
765
|
+
| III.17.37 | C | `f = beta*(1+alpha*cos(theta))` | 0 / 0 | 0 / **10** | 0 / **10** | 0 / **10** |
|
|
766
|
+
| III.21.20 | A | `j = -rho_c_0*q*A_vec/m` | 1 / 1 | **10** / 5 | **10** / 2 | **10** / 2 |
|
|
767
|
+
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
basin/__init__.py,sha256=ExbQF0IA5VctDnCAY6izNV7Qv57JFaC2TmlIurTublU,3125
|
|
2
|
+
basin/core.py,sha256=rEjFtFxgFkB8i3CfsotaxjSo3h1fICr56sfYP0K3i6w,17078
|
|
3
|
+
basin/version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
4
|
+
basin_sr-0.1.0.dist-info/METADATA,sha256=Ru63lKYbHrij0v2zN04byBeFpUMW7sKn8MQ4kNzvuyA,45265
|
|
5
|
+
basin_sr-0.1.0.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
6
|
+
basin_sr-0.1.0.dist-info/licenses/LICENSE,sha256=3lq98mkjN2QeyQXj-4ZvabcRLjRqmSMLKHBVtepxwHo,1076
|
|
7
|
+
basin_sr-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FauvidoTechnologies
|
|
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.
|