equationnet 1.0.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.
- equationnet-1.0.0/LICENSE +21 -0
- equationnet-1.0.0/PKG-INFO +468 -0
- equationnet-1.0.0/README.md +445 -0
- equationnet-1.0.0/pyproject.toml +37 -0
- equationnet-1.0.0/setup.cfg +4 -0
- equationnet-1.0.0/src/equationnet/__init__.py +15 -0
- equationnet-1.0.0/src/equationnet/cli.py +124 -0
- equationnet-1.0.0/src/equationnet/codegen.py +106 -0
- equationnet-1.0.0/src/equationnet/data/spring.csv +41 -0
- equationnet-1.0.0/src/equationnet/fit.py +994 -0
- equationnet-1.0.0/src/equationnet/guide.py +777 -0
- equationnet-1.0.0/src/equationnet/models.py +187 -0
- equationnet-1.0.0/src/equationnet/parse.py +339 -0
- equationnet-1.0.0/src/equationnet/table.py +161 -0
- equationnet-1.0.0/src/equationnet/templates.py +1476 -0
- equationnet-1.0.0/src/equationnet.egg-info/PKG-INFO +468 -0
- equationnet-1.0.0/src/equationnet.egg-info/SOURCES.txt +25 -0
- equationnet-1.0.0/src/equationnet.egg-info/dependency_links.txt +1 -0
- equationnet-1.0.0/src/equationnet.egg-info/entry_points.txt +2 -0
- equationnet-1.0.0/src/equationnet.egg-info/requires.txt +5 -0
- equationnet-1.0.0/src/equationnet.egg-info/top_level.txt +1 -0
- equationnet-1.0.0/tests/test_fit.py +289 -0
- equationnet-1.0.0/tests/test_guide.py +369 -0
- equationnet-1.0.0/tests/test_inputs.py +841 -0
- equationnet-1.0.0/tests/test_parse.py +84 -0
- equationnet-1.0.0/tests/test_table.py +66 -0
- equationnet-1.0.0/tests/test_yours.py +328 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cogitan LLC
|
|
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.
|
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: equationnet
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Type an equation: six simple models (three that use it, three data-only baselines), plus any of your own, are trained on your data and ranked on held-out points.
|
|
5
|
+
Author: Cogitan
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Cogitan/equationnet
|
|
8
|
+
Project-URL: Issues, https://github.com/Cogitan/equationnet/issues
|
|
9
|
+
Keywords: differential equations,PINN,model selection,parameter estimation,scientific machine learning
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
Requires-Dist: numpy>=1.24
|
|
18
|
+
Requires-Dist: scipy>=1.10
|
|
19
|
+
Requires-Dist: sympy>=1.12
|
|
20
|
+
Requires-Dist: torch>=2.0
|
|
21
|
+
Requires-Dist: questionary>=2.0
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# equationnet
|
|
25
|
+
|
|
26
|
+
Type a differential equation and give it your data. equationnet trains six simple
|
|
27
|
+
models: three that use the equation and three data-only baselines. It ranks them
|
|
28
|
+
by their error on points they never saw, and gives you each model as a standalone
|
|
29
|
+
script. You can add models of your own to the comparison.
|
|
30
|
+
|
|
31
|
+
No code needed:
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
pip install equationnet
|
|
35
|
+
equationnet
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
That starts a guided session in the terminal. It asks for your data file, a CSV that
|
|
39
|
+
you can drag into the window. Then it asks which column you measured, which is time,
|
|
40
|
+
and which equation to test: a starter such as logistic growth or the heat equation,
|
|
41
|
+
or your own. It trains the six models and says in plain words whether the equation helped,
|
|
42
|
+
with the fitted constants. Then it can save the returned model, or all six, as
|
|
43
|
+
scripts, predict at new times, or try another equation on the same data. Arrow keys
|
|
44
|
+
and Enter choose (with answers piped in, it shows numbered menus instead); Esc or
|
|
45
|
+
Ctrl-C leaves.
|
|
46
|
+
|
|
47
|
+
From Python:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import equationnet as en
|
|
51
|
+
|
|
52
|
+
result = en.fit("u_tt + c*u_t + k*u = 0", "spring.csv") # examples/spring.csv: columns t, u
|
|
53
|
+
print(result.table())
|
|
54
|
+
result.best.save("best_model.py") # a standalone script: numpy + scipy/torch only
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
equation: u_tt + c*u_t + k*u = 0
|
|
59
|
+
target u(t); fit c, k
|
|
60
|
+
split: random, 32 points to train, 8 held out
|
|
61
|
+
|
|
62
|
+
rank model held-out error time fitted
|
|
63
|
+
-----------------------------------------------------------------------
|
|
64
|
+
1 = Smoothing spline (data only) 0.05551 0.7s -
|
|
65
|
+
2 = PINN (neural network + equation) 0.0571 2.7s c=0.3257, k=4.043
|
|
66
|
+
3 = Polynomial + equation 0.05727 4.5s c=0.3261, k=4.038
|
|
67
|
+
4 = Equation fit (classical) 0.05754 11.6s c=0.324+-0.015, k=4.029+-0.043
|
|
68
|
+
5 = Polynomial (data only) 0.05869 0.0s -
|
|
69
|
+
6 Neural network (data only) 0.2913 1.5s -
|
|
70
|
+
|
|
71
|
+
best: Equation fit (classical). Held-out error is the RMS error on data the models never saw.
|
|
72
|
+
= 5 models are within the noise of the lowest error on these 8 held-out points, so the data cannot tell them apart.
|
|
73
|
+
The one the equation constrains most is returned; pick="lowest" would return Smoothing spline (data only).
|
|
74
|
+
+-: one standard error, if the equation is exactly right (a wrong or approximate equation can be off by more).
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
(`examples/spring.csv`: 40 noisy points of a damped spring, true c = 0.3, k = 4,
|
|
78
|
+
noise standard deviation 0.05. Recorded in `bench/stages/stage_d_results.json`;
|
|
79
|
+
`fit` also prints one progress line per model first. Times vary from run to run.)
|
|
80
|
+
|
|
81
|
+
When the data cannot pin a constant down, a line says so. For example, on five of
|
|
82
|
+
the six points of NIST's biochemical oxygen demand data (`u_t = k*(L - u)`, random
|
|
83
|
+
split):
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
not pinned down: L: poorly determined: set to half or one and a half times its value (243.8), the classical fit refits the data as well. If you know it, pass known={'L': ...}. ...
|
|
87
|
+
not pinned down: k: consistent with 0 (classical fit 0.2214 +- 0.12): the data cannot tell it from zero. If you know it, pass known={'k': ...}. ...
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
NIST certifies L = 213.8 +- 12.4 and k = 0.547 +- 0.105 from all six points with the
|
|
91
|
+
start value fixed at zero. equationnet also fits the start value, and with five
|
|
92
|
+
points both come out flagged: L poorly determined, k consistent with zero.
|
|
93
|
+
|
|
94
|
+
When the equation models that score the same, together with the classical fit,
|
|
95
|
+
give values more than 10% and more than two standard errors apart for a constant
|
|
96
|
+
the classical fit does pin down, a separate "models disagree" line says so.
|
|
97
|
+
|
|
98
|
+
## Why it exists
|
|
99
|
+
|
|
100
|
+
A physics-informed neural network (PINN) writes a known equation into a network's
|
|
101
|
+
training. There are good libraries for it (DeepXDE, PINA, NeuroDiffEq, NVIDIA
|
|
102
|
+
PhysicsNeMo, NeuralPDE.jl). equationnet asks a different question: given an
|
|
103
|
+
equation and some data, which simple model should you use?
|
|
104
|
+
|
|
105
|
+
A PINN is not always the answer. On several forward problems, PINNs did not
|
|
106
|
+
outperform the finite element method in solution time or accuracy in Grossmann et
|
|
107
|
+
al. (IMA J. Appl. Math. 89, 143 (2024), doi:10.1093/imamat/hxae011). The finite element method plus an optimizer beat them on
|
|
108
|
+
noisy inverse problems in Jekic et al. (2025 preprint, arXiv:2509.20191). So by
|
|
109
|
+
default equationnet trains the classical fit and data-only baselines next to the
|
|
110
|
+
equation-based networks, and lets held-out data rank them.
|
|
111
|
+
|
|
112
|
+
## The models
|
|
113
|
+
|
|
114
|
+
| name | in the table | what it is | uses the equation |
|
|
115
|
+
|---|---|---|---|
|
|
116
|
+
| `equation_fit` | Equation fit (classical) | SciPy solver + least squares on the unknowns (no network) | yes |
|
|
117
|
+
| `poly_physics` | Polynomial + equation | Chebyshev polynomial trained on data + equation | yes |
|
|
118
|
+
| `pinn` | PINN (neural network + equation) | small neural network trained on data + equation | yes |
|
|
119
|
+
| `poly` | Polynomial (data only) | polynomial, degree chosen by cross-validation | no |
|
|
120
|
+
| `spline` | Smoothing spline (data only) | smoothing spline, smoothness chosen automatically | no |
|
|
121
|
+
| `nn` | Neural network (data only) | neural network on the data only | no |
|
|
122
|
+
|
|
123
|
+
When a model cannot handle an equation, the table says why in words.
|
|
124
|
+
|
|
125
|
+
## Writing equations
|
|
126
|
+
|
|
127
|
+
| you type | meaning |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `u_t`, `u_xx`, `u_xt` | partial derivatives of the target (one letter per variable) |
|
|
130
|
+
| `u'`, `u''` | derivatives when there is one variable |
|
|
131
|
+
| `^` or `**` | powers |
|
|
132
|
+
| `sin cos tan exp log sqrt tanh abs pi` | math (also `ln`, `log10`, `log2`, `asin`/`arcsin` and the other inverse and hyperbolic functions, `sec`, `csc`, `cot`, `erf`, `erfc`) |
|
|
133
|
+
| `f(u)` | an unknown function of one argument, learned from the data |
|
|
134
|
+
| any other name that is not a data column | a constant: fitted, unless you pass it in `known={...}` |
|
|
135
|
+
|
|
136
|
+
Functions that are not smooth or take two arguments (`sign`, `max`, `min`, `floor`,
|
|
137
|
+
`atan2` and similar) stop with a message instead of being learned.
|
|
138
|
+
|
|
139
|
+
Examples: `u_t = r*u*(1 - u/K)`, `u_t = D*u_xx`, `u_t + u*u_x = nu*u_xx`,
|
|
140
|
+
`u'' + c*u' + f(u) = 0`.
|
|
141
|
+
|
|
142
|
+
The data needs one column per variable plus the target (default `u`). Columns
|
|
143
|
+
other than the target are the variables, in order.
|
|
144
|
+
|
|
145
|
+
## Options
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
en.fit(equation, data,
|
|
149
|
+
target="u", # target column
|
|
150
|
+
known={"k": 4.0}, # constants you already know
|
|
151
|
+
models=["equation_fit", "pinn"], # default: all; can include your own (below)
|
|
152
|
+
split="random", # or "forecast": hold out the end in time
|
|
153
|
+
holdout=0.2, seed=0,
|
|
154
|
+
cv=1, # see "How models are scored"
|
|
155
|
+
predict_at={"t": [12, 14]}, # where you will want predictions (e.g. the future)
|
|
156
|
+
pick="simplest", # or "lowest"; see "How models are scored"
|
|
157
|
+
config={"pinn": {"steps": 1000}})
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
`predict_at` matters for forecasting. The PINN and the physics polynomial also
|
|
161
|
+
enforce the equation over the range spanned by the data and those locations
|
|
162
|
+
(never their values, which you don't have). The classical ODE fit tries to start
|
|
163
|
+
its solve at the earliest of these locations and the data, so that predictions there
|
|
164
|
+
run forwards (see "Limits in this version" for when it cannot).
|
|
165
|
+
|
|
166
|
+
`config` sets per-model options: `steps` and `lbfgs` for `pinn`, `poly_physics`
|
|
167
|
+
and `nn`; `collocation` for `pinn` and `poly_physics`; `degree` for
|
|
168
|
+
`poly_physics`. A setting the model does not use is an error, never silently
|
|
169
|
+
ignored.
|
|
170
|
+
|
|
171
|
+
Models run in a fixed order (polynomial, spline, classical fit, physics
|
|
172
|
+
polynomial, data-only network, PINN, then any of your own), and each prints its
|
|
173
|
+
result as it finishes.
|
|
174
|
+
|
|
175
|
+
## Your own model
|
|
176
|
+
|
|
177
|
+
Put your own model in the same table. Anything with `fit(X, y)` and `predict(X)`
|
|
178
|
+
that `copy.deepcopy` can copy works (tested with scikit-learn estimators and plain
|
|
179
|
+
classes), and so does a plain function `predict(X)` that needs no training:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
result = en.fit("u_tt + c*u_t + k*u = 0", "spring.csv",
|
|
183
|
+
models=["all", my_model, en.custom(other_model, name="gp")])
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
`X` has one column per variable, in the data's column order (the target left out),
|
|
187
|
+
and `y` is the target. A fresh copy of your model is trained for every held-out
|
|
188
|
+
split, on the same points as the built-in models, and scored on the same held-out
|
|
189
|
+
points. Your object itself is not changed.
|
|
190
|
+
|
|
191
|
+
A model is named after its class, a function after its name, and a lambda or
|
|
192
|
+
another callable with no name `your_model_1`, `your_model_2`, ... by position. To name it yourself, use
|
|
193
|
+
`en.custom(model, name=...)`: letters, digits, `_` or `-`, starting with a letter
|
|
194
|
+
or `_`, at most 40 characters (the same rule applies to the automatic names). A name
|
|
195
|
+
may not repeat another model's, built-in names included. `result.save_scripts("scripts/")` saves every model's script,
|
|
196
|
+
yours included.
|
|
197
|
+
|
|
198
|
+
What equationnet does not know about your model, it says rather than guesses:
|
|
199
|
+
|
|
200
|
+
- **Ties.** On a tie with a built-in model, the built-in one is returned, because
|
|
201
|
+
equationnet cannot see how much your model is constrained. In the tie order,
|
|
202
|
+
yours come after every built-in model, and those you mark as using the equation
|
|
203
|
+
come first among yours. The table says so when yours had the lowest error, and
|
|
204
|
+
`pick="lowest"` returns it anyway.
|
|
205
|
+
- **Constants and standard errors.** Constants are shown if your model has a
|
|
206
|
+
`fitted_params()` method, standard errors if it has `uncertainty()`; both return
|
|
207
|
+
`{name: value}`. They are kept out of the "not pinned down" and "models
|
|
208
|
+
disagree" checks, since your `c` need not be the equation's `c`.
|
|
209
|
+
- **Uses the equation?** Your model counts as data-only unless you say otherwise:
|
|
210
|
+
`en.custom(model, uses_equation=True)`.
|
|
211
|
+
- **Noise level.** Your model's training error is never used as the noise level
|
|
212
|
+
in the tie rule, and where a model of yours is involved the rule leans toward
|
|
213
|
+
the built-in models both ways. When yours has the lowest held-out error, a
|
|
214
|
+
built-in model counts as tied if its error is within what noise could give, with
|
|
215
|
+
the noise level capped at an upper confidence bound from your model's held-out
|
|
216
|
+
errors (97.5% for one model chosen beforehand, somewhat less for the lowest of
|
|
217
|
+
several): 2.45 times their RMS on 5 points, 1.39 times on 24. So built-in models
|
|
218
|
+
that all fit badly do not tie with a far better model of yours, but on a few
|
|
219
|
+
held-out points a built-in model up to about 4 times worse can (5 points). A model
|
|
220
|
+
of yours counts as tied with the lowest through the two-standard-error test,
|
|
221
|
+
as any model does, or within a noise level capped at the lowest model's own
|
|
222
|
+
held-out RMS error: up to about 1.6 times it on 5 points and 1.3 times on 24.
|
|
223
|
+
Built-in models compared with a built-in lowest keep the rule below, unchanged
|
|
224
|
+
from 0.0.1, so the `=` marks can skip a model of yours that is closer than tied
|
|
225
|
+
built-in models. The table then says so.
|
|
226
|
+
- **Script.** The saved file for your model is a stub: its class, its
|
|
227
|
+
parameters if it reports them (`get_params()`, as scikit-learn models do), and
|
|
228
|
+
how it was trained and called. equationnet cannot write out code it did not
|
|
229
|
+
write.
|
|
230
|
+
|
|
231
|
+
A model of yours that fails (raises, returns the wrong number of values, or returns
|
|
232
|
+
NaN) gets a `failed:` line in the table, and the other models still run.
|
|
233
|
+
|
|
234
|
+
## How models are scored
|
|
235
|
+
|
|
236
|
+
- **Default** (`cv=1`): one held-out split (`holdout`, default 20%). Models are
|
|
237
|
+
trained on the other 80% and ranked by their error on the 20%.
|
|
238
|
+
- **Cross-validation** (`cv=5`, or `cv="auto"` for only under 50 points): 5 folds
|
|
239
|
+
for `split="random"`, or forecast origins for `split="forecast"`. A forecast
|
|
240
|
+
origin trains on everything before a cut and scores the next 20% of the distinct
|
|
241
|
+
times. Earlier origins step back a whole window, so no point is scored twice.
|
|
242
|
+
Models are ranked by the mean over folds, then every model is retrained on all
|
|
243
|
+
your data. Every model is trained once per fold and once more on all the data,
|
|
244
|
+
so it is off by default. `cv="auto"` uses 5 folds (random) or 3 forecast origins.
|
|
245
|
+
- **Ties** (`pick="simplest"`, the default): models whose mean squared held-out
|
|
246
|
+
error is within two standard errors of the lowest one's are marked `=` as tied.
|
|
247
|
+
So is a model whose error is no larger than measurement noise alone would give on
|
|
248
|
+
that many held-out points (97.5% of the time). The noise level is the smallest
|
|
249
|
+
training error of the built-in data-only models, which assume no equation; if
|
|
250
|
+
none of them ran, this second test is off (models of your own: see "Your own
|
|
251
|
+
model"). It has a known weakness, not fixed: on very small data a data-only model
|
|
252
|
+
can pass almost exactly through its training points, so the noise level comes out
|
|
253
|
+
well below the true noise and the test does not fire. In stage A run 5 that is
|
|
254
|
+
behind four of the six picks more than 3x worse than the best, including the worst
|
|
255
|
+
(see "How well it works"). The opposite also happens, also not fixed for the
|
|
256
|
+
built-in models: when all the data-only models fit badly, their training error is
|
|
257
|
+
their misfit, the noise level comes out far above the true noise, and models many
|
|
258
|
+
times worse than the lowest are marked tied. The returned model is still the first
|
|
259
|
+
tied one in the order below, so check the held-out errors, not only the `=` marks.
|
|
260
|
+
Among the tied models, the one the equation
|
|
261
|
+
constrains most is returned: the classical fit, then the physics polynomial, then
|
|
262
|
+
the PINN, then the data-only models, then models of your own. The table says when
|
|
263
|
+
this happened and what `pick="lowest"` would return.
|
|
264
|
+
- **Small held-out sets.** With a handful of held-out points no rule can always
|
|
265
|
+
tell close models apart, and the returned model can be several times worse than
|
|
266
|
+
the best one (see "How well it works"). Treat the ranking as a guide, and use
|
|
267
|
+
`cv=5` or more data when it matters.
|
|
268
|
+
|
|
269
|
+
No data yet? `en.generate("u_t = D*u_xx", "pinn")` returns the training script
|
|
270
|
+
for one model.
|
|
271
|
+
|
|
272
|
+
Command line (`future_times.csv`: a CSV with the variable columns, here `t`):
|
|
273
|
+
|
|
274
|
+
```
|
|
275
|
+
equationnet fit "u_tt + c*u_t + k*u = 0" spring.csv --split forecast --out scripts/
|
|
276
|
+
equationnet fit "u_tt + c*u_t + k*u = 0" spring.csv --cv 5 --predict-at future_times.csv
|
|
277
|
+
equationnet script "u_t = D*u_xx" --model pinn > train_pinn.py
|
|
278
|
+
equationnet models
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## How it works
|
|
282
|
+
|
|
283
|
+
For each model equationnet renders a complete Python script from the equation,
|
|
284
|
+
runs that script, and gives you the same text. The script you save is exactly the
|
|
285
|
+
one that was scored. (For a model of your own the saved file is a stub; see "Your
|
|
286
|
+
own model".) Running it trains the model again on the data you give it, so
|
|
287
|
+
its numbers can differ slightly from the table's.
|
|
288
|
+
|
|
289
|
+
## Limits in this version
|
|
290
|
+
|
|
291
|
+
- It needs data. Pure forward solves with no measurements are not scored yet.
|
|
292
|
+
- Standard errors (`+-` in the table) come from the classical fit only, or from a
|
|
293
|
+
model of your own that reports them. The classical fit's assume the equation is
|
|
294
|
+
exactly right, and an approximate equation can be off by more.
|
|
295
|
+
- The table warns "not pinned down" when a constant's standard error is infinite
|
|
296
|
+
or more than half its value, or the constant is within two standard errors of
|
|
297
|
+
zero. The classical ODE fit also moves each constant to half and to one and a
|
|
298
|
+
half times its value and refits the rest; if it fits the data as well after
|
|
299
|
+
either move (within the 95% chi-squared limit for one number), the constant is
|
|
300
|
+
flagged too, however small its standard error. Read those lines before trusting
|
|
301
|
+
a constant.
|
|
302
|
+
- The classical solver handles one variable, or one space variable plus time in
|
|
303
|
+
the form `u_t = F(u, u_x, u_xx)` with fixed-value edges.
|
|
304
|
+
- Classical ODE (ordinary differential equation) fit: a start read off the data
|
|
305
|
+
(constants of any sign, screened over 24 orders of magnitude), plus 128 random
|
|
306
|
+
guesses from 0.01 to 100. Each is scored with one solve, and the best 6 that
|
|
307
|
+
differ get a full fit. Each guess also needs the start values (u and its
|
|
308
|
+
derivatives at the first time). They are first read off a smooth curve through
|
|
309
|
+
all the data and off a small polynomial through the first few points, whichever
|
|
310
|
+
fits better, and are then fitted along with the constants. Second-order and
|
|
311
|
+
higher equations (oscillators) also get a search on the first quarter of the time
|
|
312
|
+
range, extended step by step to all of it. With the profile check above this
|
|
313
|
+
makes their fits slower: in stage A, 1.25 to 1.8 times as long as before (a Duffing
|
|
314
|
+
oscillator with 48 points took 22 to 43 s). On evenly spaced data
|
|
315
|
+
a fast oscillation can pass through the same points as a slow one. When fits tie
|
|
316
|
+
like that, the smoothest is returned and the table prints a note.
|
|
317
|
+
- Classical PDE (partial differential equation) fit: method of lines on 81 grid
|
|
318
|
+
points with fourth-order differences. The start profile and edge values come
|
|
319
|
+
from the smoothed data near the first time and at the two x edges. A correction
|
|
320
|
+
to each (at every data x up to 25 points, 4 points in time) is fitted along with
|
|
321
|
+
the constants, and the start profile always meets the edge values. The fit then
|
|
322
|
+
checks itself on a grid twice as fine, up to 321 points, and adds any change left
|
|
323
|
+
to the `+-`. The edge values are known only where there is data, so after the
|
|
324
|
+
last training time they are held at their last fitted values. Before the first
|
|
325
|
+
training time the fit returns its start profile. Neither is a prediction from the
|
|
326
|
+
equation. The table notes it when the held-out points or `predict_at` reach past
|
|
327
|
+
the training times (a forecast split, for example); a later call to `predict`
|
|
328
|
+
prints nothing. With `cv` above 1 the returned model is retrained on all the
|
|
329
|
+
data, so no note prints, though each forecast fold was scored with held edges.
|
|
330
|
+
- When predictions are wanted before the first point the classical ODE fit trains
|
|
331
|
+
on (a held-out first point, or `predict_at`), the solve normally starts there and
|
|
332
|
+
runs forwards. If the data cannot place that earlier start (an equation that
|
|
333
|
+
forgets its start quickly, like strong damping), the fit follows a guess and the
|
|
334
|
+
table says so. If the start cannot be moved at all, the table says that the
|
|
335
|
+
predictions before the first training point are solved backwards.
|
|
336
|
+
- Unknown functions take one argument. Classical fits treat them as cubics.
|
|
337
|
+
- No Gaussian process among the built-in models (you can pass one as your own
|
|
338
|
+
model).
|
|
339
|
+
- Parsing uses SymPy, which evaluates text. equationnet refuses any character an
|
|
340
|
+
equation does not need (quotes, dots after names, square or curly brackets, `#`,
|
|
341
|
+
`;`, newlines) and huge exponents before SymPy sees the text. Even so, do not feed
|
|
342
|
+
it equations from people you do not trust, e.g. in a web service.
|
|
343
|
+
|
|
344
|
+
## How well it works
|
|
345
|
+
|
|
346
|
+
From `TESTPLAN.md`, stage A run 5. The test used 14 problems written before any
|
|
347
|
+
run, scored against the exact solution on a dense grid:
|
|
348
|
+
- stiff, nonlinear, forced and unevenly spaced problems, four of them PDEs;
|
|
349
|
+
- 10 to 500 points, noise 0.1% to 20% of the signal's standard deviation;
|
|
350
|
+
- constants from 4e-4 to 1.2e5;
|
|
351
|
+
- two problems built to be nonidentifiable.
|
|
352
|
+
|
|
353
|
+
Each ran on 3 fresh seeds and both splits, with default settings: 84 runs. The
|
|
354
|
+
data are made by the same equation that is fitted. The problems themselves are
|
|
355
|
+
not new to the code: fixes after runs 1 to 4 were diagnosed on them (with other
|
|
356
|
+
seeds).
|
|
357
|
+
|
|
358
|
+
Bars for these numbers were written before the first run and never moved. Run 5
|
|
359
|
+
met all of them except the one on picks, which was missed and accepted in writing.
|
|
360
|
+
TESTPLAN.md has all five runs, with the misses of each.
|
|
361
|
+
|
|
362
|
+
- When the equation is exact, a model that uses it was truly best in 84 of 84 runs.
|
|
363
|
+
- The default pick was within 1.5x of the truly best model in 75 of 84 runs (89%;
|
|
364
|
+
the bar was 90%). 6 picks were more than 3x worse; the bar allowed none.
|
|
365
|
+
- Five of those 6 came with the table's warning that the ranking rests on fewer
|
|
366
|
+
than 5 held-out points: the two smallest problems, with 10 and 20 points. In four
|
|
367
|
+
of them (the worst, 52x, a PINN chosen on 2 held-out points; 26x and 6.3x, where a
|
|
368
|
+
data-only model was returned; and 4.4x) the classical fit was truly best and scored
|
|
369
|
+
at about the noise, and the noise-floor tie described under "Ties" would have
|
|
370
|
+
returned it had its noise level not come out too low. In the fifth (11.9x) the
|
|
371
|
+
classical fit was returned, tied with a physics polynomial that was better still,
|
|
372
|
+
both far below the noise.
|
|
373
|
+
- On the 72 runs with 5 or more held-out points, 69 picks (96%) were within 1.5x.
|
|
374
|
+
The worst was 3.8x, on a problem built to be nonidentifiable, where the classical
|
|
375
|
+
fit has more free numbers than the data need. It was returned by the tie order,
|
|
376
|
+
with an error against the exact solution of about 0.4 of the noise level, while a
|
|
377
|
+
PINN was closer still. That problem was over 3x in four of the five runs and is
|
|
378
|
+
not fixed.
|
|
379
|
+
- On the 12 identifiable problems, the classical constants were within 3 standard
|
|
380
|
+
errors of the truth in 71 of 72 fits. In the other, both constants were just
|
|
381
|
+
outside (3.2 standard errors).
|
|
382
|
+
- Over 20 seeds for each of four problem families, each constant's truth fell
|
|
383
|
+
within 1.96 standard errors in 90% to 95% of cases (the bar was 85% to 98%).
|
|
384
|
+
- "not pinned down" fired on every run of the two nonidentifiable problems and on
|
|
385
|
+
none of the identifiable ones.
|
|
386
|
+
- The PINN failed on 2 of 6 Gompertz runs (`log(K/u)` once training takes u through
|
|
387
|
+
zero). The table says so, and the other models still ran.
|
|
388
|
+
|
|
389
|
+
`bench/headroom.py` and `bench/FINDINGS.md` are the smaller development benchmark
|
|
390
|
+
the defaults were tuned on.
|
|
391
|
+
|
|
392
|
+
## Real data
|
|
393
|
+
|
|
394
|
+
`bench/realG/` holds five reference datasets from the US National Institute of
|
|
395
|
+
Standards and Technology (NIST): real measurements with certified constants. The
|
|
396
|
+
expected outcome of each was written down before running (TESTPLAN.md, stage G).
|
|
397
|
+
- Each set was fitted with NIST's model written as an ODE (10 runs). For Misra1a
|
|
398
|
+
and BoxBOD this also frees the start value, which NIST fixes at zero.
|
|
399
|
+
- Every constant the data could not determine was flagged: Eckerle4's two, and
|
|
400
|
+
BoxBOD's k and L. With 5 training points and the start value freed, BoxBOD's L is
|
|
401
|
+
not pinned down to within half its value. NIST's fit of all 6 points, with the
|
|
402
|
+
start fixed, gives it 6%. Every unflagged constant was within 3 standard errors of NIST's
|
|
403
|
+
certified value, except Misra1a on the random split (A and k at 3.1 and 3.3
|
|
404
|
+
standard errors).
|
|
405
|
+
- 2 of the 9 outcomes written down in advance were not met (3 in the first run,
|
|
406
|
+
before the profile check flagged BoxBOD's L on the forecast as expected);
|
|
407
|
+
TESTPLAN.md explains each.
|
|
408
|
+
- These sets have 6 to 35 points, so 1 to 7 are held out. A data-only model was
|
|
409
|
+
picked in 6 of the 10 runs, so on data this small the ranking is a rough guide.
|
|
410
|
+
|
|
411
|
+
`bench/realG/` also holds one PDE test on real data: a week of hourly soil
|
|
412
|
+
temperature at 5, 10, 20, 50 and 100 cm from NOAA's US Climate Reference Network
|
|
413
|
+
(station Lincoln 11 SW, Nebraska, April 2025; `bench/realG/soil_lincoln_2025.csv`),
|
|
414
|
+
fitted with the heat equation `u_t = a*u_xx`, with the top and bottom sensors as the
|
|
415
|
+
edges. Six outcomes were written in TESTPLAN.md before the run. Apart from the range
|
|
416
|
+
for a, committed earlier, they were committed only with the results, so the record
|
|
417
|
+
cannot prove the order. Two were missed, both on the random split. The classical fit
|
|
418
|
+
gave a = 0.0096 +- 0.0003 m^2/day, below the 0.02 to 0.09 written in advance (a
|
|
419
|
+
range from general knowledge of soils, not a cited source). Its held-out error (0.23
|
|
420
|
+
degrees C) was 4.7 times the smoothing spline's (0.05).
|
|
421
|
+
|
|
422
|
+
After the run, the data turned out not to follow one value of a. Read off how the
|
|
423
|
+
daily swing shrinks and lags between two depths (`bench/realG/soil_harmonics.py`; a
|
|
424
|
+
rough method that assumes a uniform layer and a steady daily cycle), a is about
|
|
425
|
+
0.01 m^2/day between 5 and 10 cm and 0.18 to 0.33 between any two depths from 10 cm
|
|
426
|
+
down. The classical fit matched the top pair, where the daily swing is largest.
|
|
427
|
+
These data cannot say why the top differs. A misplaced sensor would have to be
|
|
428
|
+
about 20 cm off to explain it. A different top layer, heat carried by water, or
|
|
429
|
+
weather that is not a steady daily cycle could each contribute; none was tested. The `+-` (3.5%) did not show the trouble. Three other things in
|
|
430
|
+
the output did: the classical fit ranked fourth, outside the noise; the three
|
|
431
|
+
models that use the equation gave a from 0.0006 to 0.0096 on the same split; and the forecast split
|
|
432
|
+
gave a = 0.0117 +- 0.0004, 4.1 combined standard errors from the random split's.
|
|
433
|
+
|
|
434
|
+
On the forecast split (the last 1.4 days held out) the outcomes written in advance
|
|
435
|
+
were met, including the trouble: the classical fit was best (1.8 degrees C held-out
|
|
436
|
+
error, against 3.0 for the PINN), but its error at 5 cm was 3.5 degrees because it
|
|
437
|
+
held the top edge at its last training value, and it printed no note saying so. The
|
|
438
|
+
note was added after the run (see "Limits in this version").
|
|
439
|
+
|
|
440
|
+
`bench/real/` holds six measured time series from the data sets of Lomen and
|
|
441
|
+
Lovelock's ODE textbook. They were run on an earlier version of equationnet;
|
|
442
|
+
`bench/real/FINDINGS_REAL.md` has the results, which predate the current tie rule
|
|
443
|
+
and fits. One lesson from them still holds: error bars assume the equation is
|
|
444
|
+
exact. There, the fitted room temperature for coffee cooling came out well above
|
|
445
|
+
the stated one. A likely reason is that Newton's law of cooling is only
|
|
446
|
+
approximately right for a cup of coffee, which no error bar computed from noise
|
|
447
|
+
can see.
|
|
448
|
+
|
|
449
|
+
## Status
|
|
450
|
+
|
|
451
|
+
1.0.0. New since 0.0.1: your own model in the comparison ("Your own model", tested
|
|
452
|
+
in stage J of `TESTPLAN.md`). The built-in models are unchanged, and so is the tie
|
|
453
|
+
rule for runs without models of your own, so the results above still apply. The arguments of `fit()` and the layout of the table
|
|
454
|
+
are kept stable within 1.x.
|
|
455
|
+
|
|
456
|
+
## License
|
|
457
|
+
|
|
458
|
+
The code and documentation are under the MIT license (`LICENSE`). The data tables
|
|
459
|
+
in `bench/real/datasets.py` and `bench/realG/datasets_g.py` are third-party
|
|
460
|
+
measurements, not covered by that license. They are reproduced as published, with
|
|
461
|
+
credit to the sources named in each file; neither source page states license
|
|
462
|
+
terms. If you hold rights in any of them and object, open an issue and they will
|
|
463
|
+
be removed.
|
|
464
|
+
|
|
465
|
+
`bench/realG/soil_lincoln_2025.csv` is derived from NOAA's US Climate Reference
|
|
466
|
+
Network hourly data (NOAA National Centers for Environmental Information), a US
|
|
467
|
+
government work in the public domain; `bench/realG/soil.py` rebuilds it from the
|
|
468
|
+
published file.
|