labplan 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.
- labplan/__init__.py +50 -0
- labplan/conformal.py +91 -0
- labplan/fit.py +167 -0
- labplan/model.py +115 -0
- labplan/plan.py +148 -0
- labplan/records.py +90 -0
- labplan/report.py +99 -0
- labplan/stats.py +61 -0
- labplan-0.1.0.dist-info/METADATA +208 -0
- labplan-0.1.0.dist-info/RECORD +13 -0
- labplan-0.1.0.dist-info/WHEEL +5 -0
- labplan-0.1.0.dist-info/licenses/LICENSE +202 -0
- labplan-0.1.0.dist-info/top_level.txt +1 -0
labplan/__init__.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""labplan: plan the measurement, fit the model, keep the record --
|
|
2
|
+
for any lab model.
|
|
3
|
+
|
|
4
|
+
Nine research packages in this organization ended up needing the same
|
|
5
|
+
loop: predict the error bars of a planned measurement before spending
|
|
6
|
+
the instrument time, choose the most informative settings, fit the
|
|
7
|
+
model to the data with honest uncertainties, and refuse -- with an
|
|
8
|
+
explanation -- whenever the design cannot identify the parameters.
|
|
9
|
+
labplan is that loop extracted into one dependency-light package that
|
|
10
|
+
works with ANY forward model you can write as a Python function: a
|
|
11
|
+
spin resonance versus field, a critical current versus temperature, a
|
|
12
|
+
transmittance versus wavelength, a sensor reading versus anything.
|
|
13
|
+
|
|
14
|
+
The promise that makes planning meaningful: the planner's error bars
|
|
15
|
+
and the fitter's error bars are the SAME matrix, (J^T W J)^-1 -- so
|
|
16
|
+
what is promised before the measurement is what is reported after,
|
|
17
|
+
exactly, whenever the model describes the data. On top of the
|
|
18
|
+
model-based statistics, split conformal prediction supplies
|
|
19
|
+
distribution-free intervals with an exact finite-sample guarantee,
|
|
20
|
+
for the day the model is wrong in ways nobody modeled. And every fit
|
|
21
|
+
can be turned into an audit record that states what was fitted, to
|
|
22
|
+
exactly which data (sha256), by which software versions, when.
|
|
23
|
+
|
|
24
|
+
Statistics sources, stated once: weighted least squares and Fisher
|
|
25
|
+
information are textbook (e.g. Cox & Hinkley, Theoretical Statistics
|
|
26
|
+
(1974)); D-optimal design follows F. Pukelsheim, Optimal Design of
|
|
27
|
+
Experiments, SIAM (2006); split conformal prediction follows Vovk,
|
|
28
|
+
Gammerman & Shafer (2005), Lei et al., J. Am. Stat. Assoc. 113, 1094
|
|
29
|
+
(2018) and Angelopoulos & Bates, arXiv:2107.07511. Every statistical
|
|
30
|
+
claim in the test suite is pinned to a closed form, an exact
|
|
31
|
+
identity, or seeded simulation against an exact formula -- never a
|
|
32
|
+
stored number.
|
|
33
|
+
"""
|
|
34
|
+
from .model import Model
|
|
35
|
+
from .fit import FitResult, fit
|
|
36
|
+
from .plan import design, information, repeats_for
|
|
37
|
+
from .conformal import (conformal_interval, conformal_quantile,
|
|
38
|
+
coverage_exact)
|
|
39
|
+
from .report import audit_record, report_text
|
|
40
|
+
from .records import load_measurements_csv, save_measurements_csv
|
|
41
|
+
|
|
42
|
+
__version__ = "0.1.0"
|
|
43
|
+
__all__ = [
|
|
44
|
+
"Model", "FitResult", "fit",
|
|
45
|
+
"information", "design", "repeats_for",
|
|
46
|
+
"conformal_quantile", "conformal_interval", "coverage_exact",
|
|
47
|
+
"audit_record", "report_text",
|
|
48
|
+
"save_measurements_csv", "load_measurements_csv",
|
|
49
|
+
"__version__",
|
|
50
|
+
]
|
labplan/conformal.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Distribution-free prediction intervals with an exact guarantee.
|
|
2
|
+
|
|
3
|
+
The model-based error bars elsewhere in this package assume the model
|
|
4
|
+
is right and the noise is Gaussian. Split conformal prediction makes
|
|
5
|
+
a different, weaker promise that holds with NO such assumptions: hold
|
|
6
|
+
out calibration measurements, score how wrong the model was on each
|
|
7
|
+
(for instance |measured - predicted|), and take
|
|
8
|
+
|
|
9
|
+
q = the ceil((n + 1)(1 - alpha))-th smallest of the n scores.
|
|
10
|
+
|
|
11
|
+
Then a new measurement, exchangeable with the calibration set, falls
|
|
12
|
+
within q of its prediction with probability at least 1 - alpha --
|
|
13
|
+
exactly, at finite n, whatever the model and whatever the noise (V.
|
|
14
|
+
Vovk, A. Gammerman and G. Shafer, Algorithmic Learning in a Random
|
|
15
|
+
World, Springer (2005); J. Lei et al., J. Am. Stat. Assoc. 113, 1094
|
|
16
|
+
(2018); A. N. Angelopoulos and S. Bates, arXiv:2107.07511). For
|
|
17
|
+
continuous scores the coverage is also at most 1 - alpha + 1/(n + 1),
|
|
18
|
+
and its exact value is ceil((n + 1)(1 - alpha)) / (n + 1) -- a rank
|
|
19
|
+
statement the tests verify by seeded simulation against the closed
|
|
20
|
+
form.
|
|
21
|
+
|
|
22
|
+
Honest limits, stated plainly: the guarantee is marginal (on average
|
|
23
|
+
over calibration sets and test points, not conditional on a
|
|
24
|
+
particular x), and it needs exchangeability -- calibration data from
|
|
25
|
+
last month's instrument state do not certify next month's drift.
|
|
26
|
+
"""
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import numpy as np
|
|
30
|
+
|
|
31
|
+
__all__ = ["conformal_quantile", "conformal_interval",
|
|
32
|
+
"coverage_exact"]
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def conformal_quantile(scores, alpha=0.1):
|
|
36
|
+
"""The split-conformal quantile of held-out error scores.
|
|
37
|
+
|
|
38
|
+
scores : (n,) nonnegative error scores of held-out calibration
|
|
39
|
+
measurements (e.g. |measured - predicted|).
|
|
40
|
+
alpha : miscoverage level (0.1 = 90% intervals).
|
|
41
|
+
|
|
42
|
+
Returns q such that |new error| <= q with probability >= 1-alpha.
|
|
43
|
+
Refuses when n is too small for the level: the rank
|
|
44
|
+
ceil((n+1)(1-alpha)) must exist among n scores, which needs
|
|
45
|
+
n >= (1-alpha)/alpha.
|
|
46
|
+
"""
|
|
47
|
+
s = np.asarray(scores, dtype=float).ravel()
|
|
48
|
+
if s.size < 1 or not np.all(np.isfinite(s)) or np.any(s < 0.0):
|
|
49
|
+
raise ValueError("scores must be finite and >= 0 (use "
|
|
50
|
+
"absolute errors)")
|
|
51
|
+
a = float(alpha)
|
|
52
|
+
if not (0.0 < a < 1.0):
|
|
53
|
+
raise ValueError("alpha must lie in (0, 1)")
|
|
54
|
+
n = s.size
|
|
55
|
+
k = int(np.ceil((n + 1) * (1.0 - a)))
|
|
56
|
+
if k > n:
|
|
57
|
+
need = int(np.ceil((1.0 - a) / a))
|
|
58
|
+
raise ValueError(
|
|
59
|
+
f"{n} calibration scores cannot certify level "
|
|
60
|
+
f"{1 - a:.3g}: the required rank {k} exceeds n. Collect "
|
|
61
|
+
f"at least {need} calibration measurements, or lower the "
|
|
62
|
+
"confidence")
|
|
63
|
+
return float(np.sort(s)[k - 1])
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def conformal_interval(prediction, q):
|
|
67
|
+
"""The interval the guarantee applies to: prediction +/- q.
|
|
68
|
+
|
|
69
|
+
Returns (lo, hi) arrays matching the prediction's shape.
|
|
70
|
+
"""
|
|
71
|
+
pred = np.asarray(prediction, dtype=float)
|
|
72
|
+
qv = float(q)
|
|
73
|
+
if not (np.isfinite(qv) and qv >= 0.0):
|
|
74
|
+
raise ValueError("q must be finite and >= 0")
|
|
75
|
+
return pred - qv, pred + qv
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def coverage_exact(n, alpha):
|
|
79
|
+
"""The exact marginal coverage for continuous scores:
|
|
80
|
+
ceil((n+1)(1-alpha)) / (n+1). It always lies in
|
|
81
|
+
[1-alpha, 1-alpha + 1/(n+1)] -- the two-sided guarantee of the
|
|
82
|
+
references, recovered as arithmetic."""
|
|
83
|
+
n = int(n)
|
|
84
|
+
a = float(alpha)
|
|
85
|
+
if n < 1 or not (0.0 < a < 1.0):
|
|
86
|
+
raise ValueError("need n >= 1 and alpha in (0, 1)")
|
|
87
|
+
k = int(np.ceil((n + 1) * (1.0 - a)))
|
|
88
|
+
if k > n:
|
|
89
|
+
raise ValueError("level not certifiable at this n (see "
|
|
90
|
+
"conformal_quantile)")
|
|
91
|
+
return k / (n + 1.0)
|
labplan/fit.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Fit the model to measured data, with error bars that mean it.
|
|
2
|
+
|
|
3
|
+
Levenberg-Marquardt weighted least squares in pure NumPy: no
|
|
4
|
+
dependency beyond the one this package already has. With measurement
|
|
5
|
+
errors supplied, the parameter covariance is the exact known-noise
|
|
6
|
+
result (J^T W J)^-1 and a chi-squared consistency check is reported;
|
|
7
|
+
without them, the error bars are scaled from the residual scatter,
|
|
8
|
+
which needs at least one spare measurement -- stated, not hidden.
|
|
9
|
+
|
|
10
|
+
A design that cannot tell the parameters apart is refused with an
|
|
11
|
+
explanation, never silently pseudo-inverted; a fit that does not
|
|
12
|
+
converge raises instead of returning the last iterate with a
|
|
13
|
+
well-formatted covariance.
|
|
14
|
+
"""
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import dataclasses
|
|
18
|
+
import hashlib
|
|
19
|
+
|
|
20
|
+
import numpy as np
|
|
21
|
+
|
|
22
|
+
from .model import Model, _settings
|
|
23
|
+
from .stats import SINGULAR_MSG, check_sigmas, invert_information
|
|
24
|
+
|
|
25
|
+
__all__ = ["FitResult", "fit"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclasses.dataclass
|
|
29
|
+
class FitResult:
|
|
30
|
+
"""Result of `fit`.
|
|
31
|
+
|
|
32
|
+
values : fitted value of each parameter, by name.
|
|
33
|
+
sigma : 1-sigma uncertainty of each parameter, by name.
|
|
34
|
+
theta, cov : the same as arrays, in `param_names` order.
|
|
35
|
+
chi2, chi2_dof : goodness of fit (chi2 is None when no
|
|
36
|
+
measurement errors were given).
|
|
37
|
+
condition_number : of the unit-free information matrix.
|
|
38
|
+
data_digest : sha256 of the (x, y, sigma) arrays -- the exact
|
|
39
|
+
data this result answers for, recorded for the audit trail.
|
|
40
|
+
model_name, reference : carried from the model.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
values: dict
|
|
44
|
+
sigma: dict
|
|
45
|
+
theta: np.ndarray
|
|
46
|
+
cov: np.ndarray
|
|
47
|
+
chi2: float
|
|
48
|
+
chi2_dof: int
|
|
49
|
+
n_points: int
|
|
50
|
+
condition_number: float
|
|
51
|
+
n_iter: int
|
|
52
|
+
model_name: str
|
|
53
|
+
reference: str
|
|
54
|
+
data_digest: str
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def data_digest(x, y=None, sigmas=None):
|
|
58
|
+
"""sha256 over the byte content of the data arrays, so a report
|
|
59
|
+
can say exactly which data it answers for."""
|
|
60
|
+
h = hashlib.sha256()
|
|
61
|
+
for a in (x, y, sigmas):
|
|
62
|
+
if a is None:
|
|
63
|
+
h.update(b"\x00none\x00")
|
|
64
|
+
else:
|
|
65
|
+
arr = np.ascontiguousarray(np.asarray(a, dtype=float))
|
|
66
|
+
h.update(str(arr.shape).encode())
|
|
67
|
+
h.update(arr.tobytes())
|
|
68
|
+
return h.hexdigest()
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def fit(model: Model, x, y, theta0, sigmas=None, max_iter=200,
|
|
72
|
+
tol=1e-12):
|
|
73
|
+
"""Weighted least-squares fit of `model` to measured data.
|
|
74
|
+
|
|
75
|
+
model : a `Model`.
|
|
76
|
+
x : (n, d) measurement settings (or (n,) for one setting).
|
|
77
|
+
y : (n,) measured readings.
|
|
78
|
+
theta0 : starting parameter vector, in `param_names` order.
|
|
79
|
+
sigmas : optional 1-sigma measurement errors (scalar or (n,)).
|
|
80
|
+
|
|
81
|
+
Returns a `FitResult`. Refuses non-identifiable designs, too few
|
|
82
|
+
points, and non-convergence, each with an explanation.
|
|
83
|
+
"""
|
|
84
|
+
x = _settings(x)
|
|
85
|
+
y = np.asarray(y, dtype=float).ravel()
|
|
86
|
+
n, p = x.shape[0], model.n_params
|
|
87
|
+
if y.size != n:
|
|
88
|
+
raise ValueError("need one measured reading per settings row")
|
|
89
|
+
if not np.all(np.isfinite(y)):
|
|
90
|
+
raise ValueError("measured readings must be finite")
|
|
91
|
+
sig = check_sigmas(sigmas, n)
|
|
92
|
+
if sig is None and n < p + 1:
|
|
93
|
+
raise ValueError(f"{n} measurements cannot determine {p} "
|
|
94
|
+
"parameters and an error scale; add points "
|
|
95
|
+
"or supply sigmas")
|
|
96
|
+
if n < p:
|
|
97
|
+
raise ValueError(f"{n} measurements cannot determine {p} "
|
|
98
|
+
"parameters")
|
|
99
|
+
w = np.ones(n) if sig is None else 1.0 / sig
|
|
100
|
+
th = np.asarray(theta0, dtype=float).ravel()
|
|
101
|
+
if th.size != p or not np.all(np.isfinite(th)):
|
|
102
|
+
raise ValueError(f"theta0 must be {p} finite starting values")
|
|
103
|
+
|
|
104
|
+
def cost(t):
|
|
105
|
+
r = (model.predict(t, x) - y) * w
|
|
106
|
+
return r, float(r @ r)
|
|
107
|
+
|
|
108
|
+
r, c = cost(th)
|
|
109
|
+
mu = 1e-3
|
|
110
|
+
converged = False
|
|
111
|
+
it = 0
|
|
112
|
+
c_old = c
|
|
113
|
+
for it in range(1, max_iter + 1):
|
|
114
|
+
jac = model.jacobian(th, x) * w[:, None]
|
|
115
|
+
jtj = jac.T @ jac
|
|
116
|
+
g = jac.T @ r
|
|
117
|
+
stepped = False
|
|
118
|
+
for _ in range(60):
|
|
119
|
+
try:
|
|
120
|
+
dth = np.linalg.solve(
|
|
121
|
+
jtj + mu * np.diag(np.maximum(np.diag(jtj),
|
|
122
|
+
1e-30)), -g)
|
|
123
|
+
except np.linalg.LinAlgError:
|
|
124
|
+
mu *= 10.0
|
|
125
|
+
continue
|
|
126
|
+
try:
|
|
127
|
+
r_new, c_new = cost(th + dth)
|
|
128
|
+
except ValueError:
|
|
129
|
+
mu *= 10.0
|
|
130
|
+
continue
|
|
131
|
+
if c_new <= c:
|
|
132
|
+
th, r, c_old, c = th + dth, r_new, c, c_new
|
|
133
|
+
mu = max(mu / 10.0, 1e-15)
|
|
134
|
+
stepped = True
|
|
135
|
+
break
|
|
136
|
+
mu *= 10.0
|
|
137
|
+
if not stepped:
|
|
138
|
+
converged = True
|
|
139
|
+
break
|
|
140
|
+
if abs(c_old - c) <= tol * (1.0 + c) and \
|
|
141
|
+
float(np.max(np.abs(dth))) \
|
|
142
|
+
<= 1e-10 * (1.0 + float(np.max(np.abs(th)))):
|
|
143
|
+
converged = True
|
|
144
|
+
break
|
|
145
|
+
if not converged:
|
|
146
|
+
raise RuntimeError("fit did not converge; check the starting "
|
|
147
|
+
"values and that the readings actually "
|
|
148
|
+
"vary with the parameters")
|
|
149
|
+
|
|
150
|
+
jac = model.jacobian(th, x) * w[:, None]
|
|
151
|
+
fisher = jac.T @ jac
|
|
152
|
+
ok, cond, cov, _ = invert_information(fisher, model.param_names)
|
|
153
|
+
if not ok:
|
|
154
|
+
raise ValueError(SINGULAR_MSG)
|
|
155
|
+
if sig is None:
|
|
156
|
+
cov = cov * (c / (n - p))
|
|
157
|
+
chi2, chi2_dof = None, None
|
|
158
|
+
else:
|
|
159
|
+
chi2, chi2_dof = c, n - p
|
|
160
|
+
err = np.sqrt(np.diag(cov))
|
|
161
|
+
return FitResult(
|
|
162
|
+
values={k: float(v) for k, v in zip(model.param_names, th)},
|
|
163
|
+
sigma={k: float(s) for k, s in zip(model.param_names, err)},
|
|
164
|
+
theta=th.copy(), cov=cov, chi2=chi2, chi2_dof=chi2_dof,
|
|
165
|
+
n_points=n, condition_number=cond, n_iter=it,
|
|
166
|
+
model_name=model.name, reference=model.reference,
|
|
167
|
+
data_digest=data_digest(x, y, sig))
|
labplan/model.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""The one thing every calibration needs: a forward model with a name,
|
|
2
|
+
named parameters, and a source.
|
|
3
|
+
|
|
4
|
+
A `Model` wraps YOUR prediction function -- any Python callable that
|
|
5
|
+
maps a parameter vector and measurement settings to predicted values.
|
|
6
|
+
That is the whole requirement: if you can predict what your instrument
|
|
7
|
+
would read, labplan can plan the measurement, fit the parameters, and
|
|
8
|
+
keep the record. The model carries its provenance (`reference`) the
|
|
9
|
+
same way every physical constant in this organization does: it is
|
|
10
|
+
required, on purpose, because a fit whose model nobody can trace is
|
|
11
|
+
not a calibration.
|
|
12
|
+
|
|
13
|
+
Conventions, stated once: `theta` is a 1-D parameter vector in the
|
|
14
|
+
order of `param_names`; `x` is an (n, d) array of measurement settings
|
|
15
|
+
(one row per planned or performed measurement -- a field value, a
|
|
16
|
+
frequency, a temperature, anything, in your units); the forward
|
|
17
|
+
function returns the (n,) predicted readings in your measurement
|
|
18
|
+
units. Nothing here assumes any physics: the statistics downstream are
|
|
19
|
+
exact for any model that is differentiable in its parameters.
|
|
20
|
+
"""
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
import dataclasses
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
__all__ = ["Model"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _check_ref(reference):
|
|
31
|
+
if not isinstance(reference, str) or len(reference.strip()) < 8:
|
|
32
|
+
raise ValueError(
|
|
33
|
+
"a real `reference` string is required: a model without a "
|
|
34
|
+
"traceable source (a paper, a manual, your own derivation "
|
|
35
|
+
"note) cannot anchor a calibration record")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
@dataclasses.dataclass(frozen=True)
|
|
39
|
+
class Model:
|
|
40
|
+
"""A named forward model.
|
|
41
|
+
|
|
42
|
+
name : short name of the model (appears in every report).
|
|
43
|
+
f : callable f(theta, x) -> (n,) predictions, with theta a 1-D
|
|
44
|
+
parameter vector and x an (n, d) settings array.
|
|
45
|
+
param_names : one name per parameter, in theta order.
|
|
46
|
+
reference : where the model comes from. Required, on purpose.
|
|
47
|
+
units : optional free-text note on the units of settings and
|
|
48
|
+
readings, carried into reports verbatim.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
name: str
|
|
52
|
+
f: object
|
|
53
|
+
param_names: tuple
|
|
54
|
+
reference: str
|
|
55
|
+
units: str = ""
|
|
56
|
+
|
|
57
|
+
def __post_init__(self):
|
|
58
|
+
if not isinstance(self.name, str) or not self.name.strip():
|
|
59
|
+
raise ValueError("the model needs a non-empty name")
|
|
60
|
+
if not callable(self.f):
|
|
61
|
+
raise ValueError("f must be a callable f(theta, x) -> "
|
|
62
|
+
"predictions")
|
|
63
|
+
names = tuple(str(n) for n in self.param_names)
|
|
64
|
+
if len(names) < 1 or len(set(names)) != len(names):
|
|
65
|
+
raise ValueError("param_names must be non-empty and "
|
|
66
|
+
"unique")
|
|
67
|
+
object.__setattr__(self, "param_names", names)
|
|
68
|
+
_check_ref(self.reference)
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def n_params(self):
|
|
72
|
+
return len(self.param_names)
|
|
73
|
+
|
|
74
|
+
def predict(self, theta, x):
|
|
75
|
+
"""Evaluate the forward model with shape checking."""
|
|
76
|
+
theta = np.asarray(theta, dtype=float).ravel()
|
|
77
|
+
if theta.size != self.n_params:
|
|
78
|
+
raise ValueError(f"theta must have {self.n_params} "
|
|
79
|
+
"entries, one per parameter name")
|
|
80
|
+
x = _settings(x)
|
|
81
|
+
y = np.asarray(self.f(theta, x), dtype=float).ravel()
|
|
82
|
+
if y.size != x.shape[0]:
|
|
83
|
+
raise ValueError("the forward function must return one "
|
|
84
|
+
"prediction per settings row")
|
|
85
|
+
if not np.all(np.isfinite(y)):
|
|
86
|
+
raise ValueError("the forward function returned non-"
|
|
87
|
+
"finite predictions; check theta and x")
|
|
88
|
+
return y
|
|
89
|
+
|
|
90
|
+
def jacobian(self, theta, x, rel_step=1e-6):
|
|
91
|
+
"""d(prediction)/d(parameter) by central differences, one
|
|
92
|
+
column per parameter."""
|
|
93
|
+
theta = np.asarray(theta, dtype=float).ravel()
|
|
94
|
+
x = _settings(x)
|
|
95
|
+
jac = np.empty((x.shape[0], self.n_params))
|
|
96
|
+
for j in range(self.n_params):
|
|
97
|
+
h = rel_step * max(abs(theta[j]), 1e-3)
|
|
98
|
+
tp, tm = theta.copy(), theta.copy()
|
|
99
|
+
tp[j] += h
|
|
100
|
+
tm[j] -= h
|
|
101
|
+
jac[:, j] = (self.predict(tp, x)
|
|
102
|
+
- self.predict(tm, x)) / (2.0 * h)
|
|
103
|
+
return jac
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def _settings(x):
|
|
107
|
+
x = np.asarray(x, dtype=float)
|
|
108
|
+
if x.ndim == 1:
|
|
109
|
+
x = x[:, None]
|
|
110
|
+
if x.ndim != 2 or x.shape[0] < 1:
|
|
111
|
+
raise ValueError("settings must be an (n, d) array: one row "
|
|
112
|
+
"per measurement")
|
|
113
|
+
if not np.all(np.isfinite(x)):
|
|
114
|
+
raise ValueError("settings must be finite")
|
|
115
|
+
return x
|
labplan/plan.py
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"""Plan the measurement before taking it.
|
|
2
|
+
|
|
3
|
+
`information` answers, from the design alone, the question every
|
|
4
|
+
instrument session should start with: can these planned measurements
|
|
5
|
+
determine the parameters at all, and how small would the error bars
|
|
6
|
+
come out? It is not an approximation of the fit -- it is the same
|
|
7
|
+
(J^T W J) matrix the fit inverts, evaluated at your expected
|
|
8
|
+
parameters, so on data the model describes the promise is kept
|
|
9
|
+
exactly (the tests assert it).
|
|
10
|
+
|
|
11
|
+
`design` picks the most informative subset of candidate measurements
|
|
12
|
+
by the standard determinant criterion (D-optimal design; F.
|
|
13
|
+
Pukelsheim, Optimal Design of Experiments, SIAM (2006)): each greedy
|
|
14
|
+
pick most shrinks the joint parameter uncertainty. The greedy rule is
|
|
15
|
+
transparent and each step can only add information (the rank-one
|
|
16
|
+
determinant identity det(A + g g^T) = det(A)(1 + g^T A^-1 g)), but it
|
|
17
|
+
is a good-practice heuristic, not a proof of the globally best
|
|
18
|
+
subset.
|
|
19
|
+
|
|
20
|
+
`repeats_for` is a closed form, not a search: repeating a design r
|
|
21
|
+
times scales its covariance by exactly 1/r.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import numpy as np
|
|
26
|
+
|
|
27
|
+
from .model import Model, _settings
|
|
28
|
+
from .stats import SINGULAR_MSG, check_sigmas, invert_information
|
|
29
|
+
|
|
30
|
+
__all__ = ["information", "design", "repeats_for"]
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def information(model: Model, theta, x, sigmas=None):
|
|
34
|
+
"""Predicted error bars for a planned design.
|
|
35
|
+
|
|
36
|
+
theta : the working point (your expected parameters -- a previous
|
|
37
|
+
calibration, a datasheet, a cited set).
|
|
38
|
+
x : (n, d) planned measurement settings.
|
|
39
|
+
sigmas : expected 1-sigma reading error (scalar or (n,)). Without
|
|
40
|
+
it the answer is per unit measurement error, and real error
|
|
41
|
+
bars scale linearly with your sigma.
|
|
42
|
+
|
|
43
|
+
Returns dict(fisher, identifiable, condition_number, sigma, cov):
|
|
44
|
+
`sigma` maps each parameter to the error bar the weighted fit
|
|
45
|
+
would report, or is None when the design cannot tell the
|
|
46
|
+
parameters apart.
|
|
47
|
+
"""
|
|
48
|
+
x = _settings(x)
|
|
49
|
+
sig = check_sigmas(sigmas, x.shape[0])
|
|
50
|
+
w = np.ones(x.shape[0]) if sig is None else 1.0 / sig
|
|
51
|
+
theta = np.asarray(theta, dtype=float).ravel()
|
|
52
|
+
jac = model.jacobian(theta, x) * w[:, None]
|
|
53
|
+
fisher = jac.T @ jac
|
|
54
|
+
identifiable, cond, cov, sigma = invert_information(
|
|
55
|
+
fisher, model.param_names)
|
|
56
|
+
if x.shape[0] < model.n_params:
|
|
57
|
+
identifiable, cov, sigma = False, None, None
|
|
58
|
+
return {"fisher": fisher, "identifiable": identifiable,
|
|
59
|
+
"condition_number": cond, "sigma": sigma, "cov": cov}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def design(model: Model, theta, candidates, n_pick, sigmas=None):
|
|
63
|
+
"""Pick the most informative subset of candidate measurements.
|
|
64
|
+
|
|
65
|
+
Greedy D-optimal selection over the candidate settings rows.
|
|
66
|
+
Returns dict(indices, fisher, condition_number, sigma) with the
|
|
67
|
+
chosen candidate indices in pick order. Refuses when even the
|
|
68
|
+
full candidate list cannot identify the parameters.
|
|
69
|
+
"""
|
|
70
|
+
x = _settings(candidates)
|
|
71
|
+
n, p = x.shape[0], model.n_params
|
|
72
|
+
n_pick = int(n_pick)
|
|
73
|
+
if not p <= n_pick <= n:
|
|
74
|
+
raise ValueError(f"n_pick must be between {p} (the number of "
|
|
75
|
+
f"parameters) and {n} (the number of "
|
|
76
|
+
"candidates)")
|
|
77
|
+
sig = check_sigmas(sigmas, n)
|
|
78
|
+
full = information(model, theta, x, sig)
|
|
79
|
+
if not full["identifiable"]:
|
|
80
|
+
raise ValueError("even the full candidate list is not "
|
|
81
|
+
"identifiable: " + SINGULAR_MSG)
|
|
82
|
+
w = np.ones(n) if sig is None else 1.0 / sig
|
|
83
|
+
theta = np.asarray(theta, dtype=float).ravel()
|
|
84
|
+
rows = model.jacobian(theta, x) * w[:, None]
|
|
85
|
+
# column-scaled (unit-free) greedy: identical scaling multiplies
|
|
86
|
+
# every candidate determinant by the same constant, so the picks
|
|
87
|
+
# are unchanged, while the tiny start-up regularizer stays
|
|
88
|
+
# meaningful in every direction
|
|
89
|
+
scale = np.sqrt(np.mean(rows * rows, axis=0))
|
|
90
|
+
scale[scale == 0.0] = 1.0
|
|
91
|
+
rs = rows / scale
|
|
92
|
+
eps = 1e-12 * float(np.max(np.sum(rs * rs, axis=1)))
|
|
93
|
+
fs = eps * np.eye(p)
|
|
94
|
+
chosen = []
|
|
95
|
+
for _ in range(n_pick):
|
|
96
|
+
best_j, best_det = -1, -np.inf
|
|
97
|
+
for j in range(n):
|
|
98
|
+
if j in chosen:
|
|
99
|
+
continue
|
|
100
|
+
det = float(np.linalg.slogdet(
|
|
101
|
+
fs + np.outer(rs[j], rs[j]))[1])
|
|
102
|
+
if det > best_det:
|
|
103
|
+
best_j, best_det = j, det
|
|
104
|
+
fs = fs + np.outer(rs[best_j], rs[best_j])
|
|
105
|
+
chosen.append(best_j)
|
|
106
|
+
fisher = (fs - eps * np.eye(p)) * np.outer(scale, scale)
|
|
107
|
+
_, cond, _, sigma = invert_information(fisher, model.param_names)
|
|
108
|
+
return {"indices": list(chosen), "fisher": fisher,
|
|
109
|
+
"condition_number": cond, "sigma": sigma}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def repeats_for(target_sigma, plan):
|
|
113
|
+
"""How many repeats of a planned design meet a target error bar?
|
|
114
|
+
|
|
115
|
+
Exact closed form: r identical repeats of a design multiply its
|
|
116
|
+
information by r, so every error bar shrinks by exactly
|
|
117
|
+
1/sqrt(r). `target_sigma` is the largest acceptable error bar of
|
|
118
|
+
any parameter, in that parameter's own units -- pass a dict
|
|
119
|
+
{name: target} to set per-parameter targets instead.
|
|
120
|
+
|
|
121
|
+
Returns (r, predicted) with `predicted` the per-parameter error
|
|
122
|
+
bars at r repeats. Refuses a non-identifiable plan: no number of
|
|
123
|
+
repeats can identify what one copy cannot.
|
|
124
|
+
"""
|
|
125
|
+
if not plan.get("identifiable") or plan.get("sigma") is None:
|
|
126
|
+
raise ValueError("the plan is not identifiable; no number of "
|
|
127
|
+
"repeats can identify what one copy of the "
|
|
128
|
+
"design cannot -- change the design")
|
|
129
|
+
sigma = plan["sigma"]
|
|
130
|
+
if isinstance(target_sigma, dict):
|
|
131
|
+
ratios = []
|
|
132
|
+
for name, t in target_sigma.items():
|
|
133
|
+
if name not in sigma:
|
|
134
|
+
raise ValueError(f"unknown parameter {name!r} in "
|
|
135
|
+
"target_sigma")
|
|
136
|
+
t = float(t)
|
|
137
|
+
if not (np.isfinite(t) and t > 0.0):
|
|
138
|
+
raise ValueError("targets must be positive")
|
|
139
|
+
ratios.append(sigma[name] / t)
|
|
140
|
+
worst = max(ratios)
|
|
141
|
+
else:
|
|
142
|
+
t = float(target_sigma)
|
|
143
|
+
if not (np.isfinite(t) and t > 0.0):
|
|
144
|
+
raise ValueError("target_sigma must be positive")
|
|
145
|
+
worst = max(s / t for s in sigma.values())
|
|
146
|
+
r = max(1, int(np.ceil(worst ** 2)))
|
|
147
|
+
predicted = {k: v / np.sqrt(r) for k, v in sigma.items()}
|
|
148
|
+
return r, predicted
|
labplan/records.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"""A plain, checked file contract for measurement records.
|
|
2
|
+
|
|
3
|
+
One CSV per record: setting columns x1..xd, the measured reading y,
|
|
4
|
+
and optionally its 1-sigma error. Values are written with `repr`, so
|
|
5
|
+
the round trip is bit-exact; the header and every value are checked
|
|
6
|
+
on load, and a malformed file is refused, not guessed at -- the same
|
|
7
|
+
contract style every package in this organization uses.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import csv
|
|
12
|
+
|
|
13
|
+
import numpy as np
|
|
14
|
+
|
|
15
|
+
from .model import _settings
|
|
16
|
+
from .stats import check_sigmas
|
|
17
|
+
|
|
18
|
+
__all__ = ["save_measurements_csv", "load_measurements_csv"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _header(d, has_sigma):
|
|
22
|
+
cols = tuple(f"x{i + 1}" for i in range(d)) + ("y",)
|
|
23
|
+
return cols + ("sigma",) if has_sigma else cols
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def save_measurements_csv(path, x, y, sigmas=None):
|
|
27
|
+
"""Write a measurement record; the exact inverse of
|
|
28
|
+
`load_measurements_csv`."""
|
|
29
|
+
x = _settings(x)
|
|
30
|
+
y = np.asarray(y, dtype=float).ravel()
|
|
31
|
+
if y.size != x.shape[0]:
|
|
32
|
+
raise ValueError("need one reading per settings row")
|
|
33
|
+
if not np.all(np.isfinite(y)):
|
|
34
|
+
raise ValueError("readings must be finite")
|
|
35
|
+
sig = check_sigmas(sigmas, x.shape[0])
|
|
36
|
+
header = _header(x.shape[1], sig is not None)
|
|
37
|
+
with open(path, "w", newline="") as fh:
|
|
38
|
+
wr = csv.writer(fh)
|
|
39
|
+
wr.writerow(header)
|
|
40
|
+
for i in range(x.shape[0]):
|
|
41
|
+
row = [repr(float(v)) for v in x[i]] + [repr(float(y[i]))]
|
|
42
|
+
if sig is not None:
|
|
43
|
+
row.append(repr(float(sig[i])))
|
|
44
|
+
wr.writerow(row)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def load_measurements_csv(path):
|
|
48
|
+
"""Read a measurement record written by `save_measurements_csv`.
|
|
49
|
+
|
|
50
|
+
Returns (x, y, sigmas) with sigmas None when the file has no
|
|
51
|
+
sigma column.
|
|
52
|
+
"""
|
|
53
|
+
with open(path, newline="") as fh:
|
|
54
|
+
rows = list(csv.reader(fh))
|
|
55
|
+
if not rows:
|
|
56
|
+
raise ValueError("empty measurement file")
|
|
57
|
+
header = tuple(rows[0])
|
|
58
|
+
if len(header) < 2 or header[-1] not in ("y", "sigma"):
|
|
59
|
+
raise ValueError(f"unrecognized header {header}")
|
|
60
|
+
has_sigma = header[-1] == "sigma"
|
|
61
|
+
d = len(header) - (2 if has_sigma else 1)
|
|
62
|
+
if d < 1 or header != _header(d, has_sigma):
|
|
63
|
+
raise ValueError(f"measurement header must be "
|
|
64
|
+
f"{_header(max(d, 1), has_sigma)}; got "
|
|
65
|
+
f"{header}")
|
|
66
|
+
body = rows[1:]
|
|
67
|
+
if not body:
|
|
68
|
+
raise ValueError("measurement file has no data rows")
|
|
69
|
+
xs, ys, ss = [], [], []
|
|
70
|
+
for row in body:
|
|
71
|
+
if len(row) != len(header):
|
|
72
|
+
raise ValueError(f"row {row!r} does not match the header")
|
|
73
|
+
try:
|
|
74
|
+
vals = [float(v) for v in row]
|
|
75
|
+
except ValueError as exc:
|
|
76
|
+
raise ValueError(f"non-numeric value in row {row!r}") \
|
|
77
|
+
from exc
|
|
78
|
+
xs.append(vals[:d])
|
|
79
|
+
ys.append(vals[d])
|
|
80
|
+
if has_sigma:
|
|
81
|
+
ss.append(vals[d + 1])
|
|
82
|
+
x = np.array(xs)
|
|
83
|
+
y = np.array(ys)
|
|
84
|
+
sig = np.array(ss) if has_sigma else None
|
|
85
|
+
_settings(x)
|
|
86
|
+
if not np.all(np.isfinite(y)):
|
|
87
|
+
raise ValueError("readings must be finite")
|
|
88
|
+
if sig is not None:
|
|
89
|
+
check_sigmas(sig, y.size)
|
|
90
|
+
return x, y, sig
|
labplan/report.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"""The audit trail: what was fitted, to which data, by what, when.
|
|
2
|
+
|
|
3
|
+
A calibration that cannot be traced is an opinion. `audit_record`
|
|
4
|
+
turns a `FitResult` into a plain dictionary that says exactly what
|
|
5
|
+
happened: the model's name and source, every fitted value with its
|
|
6
|
+
error bar, the goodness of fit, the identifiability diagnostics, a
|
|
7
|
+
sha256 digest of the exact data arrays the result answers for, the
|
|
8
|
+
package versions that produced it, and a UTC timestamp. It is
|
|
9
|
+
JSON-serializable as-is, so it can live next to the data forever;
|
|
10
|
+
`report_text` renders the same record for a human or a logbook.
|
|
11
|
+
|
|
12
|
+
Nothing in the record is re-derived at reading time: it is a
|
|
13
|
+
statement of record, checked round-trip in the tests
|
|
14
|
+
(json.dumps -> json.loads reproduces it exactly).
|
|
15
|
+
"""
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import datetime
|
|
19
|
+
import json
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
from .fit import FitResult
|
|
24
|
+
|
|
25
|
+
__all__ = ["audit_record", "report_text"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def audit_record(result: FitResult, operator="", note=""):
|
|
29
|
+
"""A JSON-serializable statement of record for one fit.
|
|
30
|
+
|
|
31
|
+
operator : who ran the calibration (free text, e.g. a name or an
|
|
32
|
+
instrument id); recorded verbatim.
|
|
33
|
+
note : anything else worth remembering, recorded verbatim.
|
|
34
|
+
"""
|
|
35
|
+
from . import __version__
|
|
36
|
+
if not isinstance(operator, str) or not isinstance(note, str):
|
|
37
|
+
raise ValueError("operator and note must be strings")
|
|
38
|
+
rec = {
|
|
39
|
+
"record": "labplan.calibration",
|
|
40
|
+
"model": result.model_name,
|
|
41
|
+
"model_reference": result.reference,
|
|
42
|
+
"parameters": {
|
|
43
|
+
name: {"value": result.values[name],
|
|
44
|
+
"sigma": result.sigma[name]}
|
|
45
|
+
for name in result.values
|
|
46
|
+
},
|
|
47
|
+
"covariance": [[float(v) for v in row] for row in result.cov],
|
|
48
|
+
"chi2": result.chi2,
|
|
49
|
+
"chi2_dof": result.chi2_dof,
|
|
50
|
+
"n_points": result.n_points,
|
|
51
|
+
"condition_number": result.condition_number,
|
|
52
|
+
"data_sha256": result.data_digest,
|
|
53
|
+
"software": {"labplan": __version__,
|
|
54
|
+
"numpy": np.__version__},
|
|
55
|
+
"timestamp_utc": datetime.datetime.now(
|
|
56
|
+
datetime.timezone.utc).isoformat(timespec="seconds"),
|
|
57
|
+
"operator": operator,
|
|
58
|
+
"note": note,
|
|
59
|
+
}
|
|
60
|
+
# the record must survive serialization exactly
|
|
61
|
+
json.dumps(rec)
|
|
62
|
+
return rec
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def report_text(record):
|
|
66
|
+
"""Render an audit record for a human or a logbook."""
|
|
67
|
+
if not isinstance(record, dict) \
|
|
68
|
+
or record.get("record") != "labplan.calibration":
|
|
69
|
+
raise ValueError("expected an audit_record dictionary")
|
|
70
|
+
lines = [
|
|
71
|
+
"labplan calibration record",
|
|
72
|
+
f" model: {record['model']}",
|
|
73
|
+
f" source: {record['model_reference']}",
|
|
74
|
+
f" when (UTC): {record['timestamp_utc']}",
|
|
75
|
+
]
|
|
76
|
+
if record.get("operator"):
|
|
77
|
+
lines.append(f" operator: {record['operator']}")
|
|
78
|
+
lines.append(" parameters:")
|
|
79
|
+
for name, pv in record["parameters"].items():
|
|
80
|
+
lines.append(f" {name} = {pv['value']:.9g} "
|
|
81
|
+
f"+/- {pv['sigma']:.3g}")
|
|
82
|
+
if record["chi2"] is not None:
|
|
83
|
+
lines.append(f" chi2 / dof: {record['chi2']:.4g} / "
|
|
84
|
+
f"{record['chi2_dof']} (near 1 per dof means "
|
|
85
|
+
"model and stated errors agree)")
|
|
86
|
+
else:
|
|
87
|
+
lines.append(" chi2: not available (no measurement "
|
|
88
|
+
"errors were supplied; error bars are scaled "
|
|
89
|
+
"from the residual scatter)")
|
|
90
|
+
lines.append(f" points: {record['n_points']}")
|
|
91
|
+
lines.append(f" condition: {record['condition_number']:.3g} "
|
|
92
|
+
"(unit-free; large means barely identifiable)")
|
|
93
|
+
lines.append(f" data sha256: {record['data_sha256']}")
|
|
94
|
+
sw = record["software"]
|
|
95
|
+
lines.append(f" software: labplan {sw['labplan']}, "
|
|
96
|
+
f"numpy {sw['numpy']}")
|
|
97
|
+
if record.get("note"):
|
|
98
|
+
lines.append(f" note: {record['note']}")
|
|
99
|
+
return "\n".join(lines)
|
labplan/stats.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""The shared exact statistics: weighted least squares, Fisher
|
|
2
|
+
information, scale-invariant identifiability.
|
|
3
|
+
|
|
4
|
+
Everything here is the standard machinery of independent Gaussian
|
|
5
|
+
measurement errors, stated plainly (see e.g. D. R. Cox and D. V.
|
|
6
|
+
Hinkley, Theoretical Statistics (1974), or any statistics text under
|
|
7
|
+
"Cramer-Rao bound"): the information matrix of a design is J^T W J
|
|
8
|
+
with J the model sensitivities and W = diag(1/sigma^2), the
|
|
9
|
+
covariance of the weighted-least-squares estimate is its inverse, and
|
|
10
|
+
both are the SAME matrix -- which is why labplan can promise, before
|
|
11
|
+
any data exist, exactly the error bars the fit will report.
|
|
12
|
+
|
|
13
|
+
Identifiability is judged on the correlation-scaled matrix
|
|
14
|
+
D^-1 F D^-1 with D = sqrt(diag F): parameters carry arbitrary units,
|
|
15
|
+
so the raw condition number partly measures the units, while exact
|
|
16
|
+
functional degeneracies of the model survive the scaling and unit
|
|
17
|
+
mismatches do not.
|
|
18
|
+
"""
|
|
19
|
+
from __future__ import annotations
|
|
20
|
+
|
|
21
|
+
import numpy as np
|
|
22
|
+
|
|
23
|
+
__all__ = ["invert_information"]
|
|
24
|
+
|
|
25
|
+
COND_MAX = 1e10
|
|
26
|
+
|
|
27
|
+
SINGULAR_MSG = ("these measurements cannot tell the parameters apart "
|
|
28
|
+
"(singular or near-singular information matrix): some "
|
|
29
|
+
"combination of parameters changes nothing the design "
|
|
30
|
+
"can see. Measure settings that respond differently "
|
|
31
|
+
"to each parameter -- `information` shows which "
|
|
32
|
+
"designs work before you spend the instrument time")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def invert_information(fisher, names):
|
|
36
|
+
"""Scale-invariant inversion of an information matrix.
|
|
37
|
+
|
|
38
|
+
Returns (identifiable, condition_number, cov, sigma_dict); cov and
|
|
39
|
+
sigma are None when the design is not identifiable.
|
|
40
|
+
"""
|
|
41
|
+
fisher = np.asarray(fisher, dtype=float)
|
|
42
|
+
d = np.sqrt(np.diag(fisher))
|
|
43
|
+
if np.any(d <= 0.0) or not np.all(np.isfinite(d)):
|
|
44
|
+
return False, np.inf, None, None
|
|
45
|
+
fs = fisher / np.outer(d, d)
|
|
46
|
+
sv = np.linalg.svd(fs, compute_uv=False)
|
|
47
|
+
cond = float(sv[0] / sv[-1]) if sv[-1] > 0 else np.inf
|
|
48
|
+
if not (np.isfinite(cond) and cond <= COND_MAX):
|
|
49
|
+
return False, cond, None, None
|
|
50
|
+
cov = np.linalg.inv(fs) / np.outer(d, d)
|
|
51
|
+
err = np.sqrt(np.diag(cov))
|
|
52
|
+
return True, cond, cov, {n: float(s) for n, s in zip(names, err)}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def check_sigmas(sigmas, n):
|
|
56
|
+
if sigmas is None:
|
|
57
|
+
return None
|
|
58
|
+
sig = np.broadcast_to(np.asarray(sigmas, dtype=float), (n,)).copy()
|
|
59
|
+
if np.any(sig <= 0.0) or not np.all(np.isfinite(sig)):
|
|
60
|
+
raise ValueError("sigmas must be finite and positive")
|
|
61
|
+
return sig
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: labplan
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Plan the measurement, fit the model, keep the record - exact measurement planning, calibration and audit trails for any lab model
|
|
5
|
+
Author: Tanvir Mahmud Mahim
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/TaN-MM-Org/labplan
|
|
8
|
+
Project-URL: Issues, https://github.com/TaN-MM-Org/labplan/issues
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy>=1.22
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# labplan
|
|
29
|
+
|
|
30
|
+
[](https://github.com/TaN-MM-Org/labplan/actions)
|
|
31
|
+
[](LICENSE)
|
|
32
|
+
|
|
33
|
+
Every measurement campaign asks the same four questions. Can the
|
|
34
|
+
measurements I am about to take determine the numbers I care about --
|
|
35
|
+
and how well? Which settings are worth the instrument time? Once the
|
|
36
|
+
data exist, what are the numbers, with error bars that mean it? And a
|
|
37
|
+
year from now, can anyone trace exactly what was fitted, to which
|
|
38
|
+
data, by what? `labplan` answers all four for ANY instrument or
|
|
39
|
+
experiment you can describe with a Python function -- and refuses,
|
|
40
|
+
with an explanation, whenever the honest answer is "this design
|
|
41
|
+
cannot tell".
|
|
42
|
+
|
|
43
|
+
Nine research packages in this organization -- covering colour-centre
|
|
44
|
+
spins, squeezed light, spin-squeezed clocks, Raman maps,
|
|
45
|
+
single-photon emitters, superconducting detectors, band structure,
|
|
46
|
+
semiconductor heterostructures and photonic fabrication -- each grew
|
|
47
|
+
the same planning-and-calibration loop for its own physics. `labplan`
|
|
48
|
+
is that loop extracted, generalized, and hardened into a single
|
|
49
|
+
dependency-light package (NumPy only, Python 3.9-3.14): the tenth
|
|
50
|
+
package is the pattern itself.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
pip install labplan # NumPy only
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## The loop in one example
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import numpy as np
|
|
62
|
+
from labplan import (Model, information, design, fit,
|
|
63
|
+
repeats_for, audit_record, report_text)
|
|
64
|
+
|
|
65
|
+
# 1. Your model: anything that predicts a reading from parameters
|
|
66
|
+
# and settings. Here, a sensor line y = gain * x + offset.
|
|
67
|
+
m = Model("sensor line",
|
|
68
|
+
lambda th, x: th[0] * x[:, 0] + th[1],
|
|
69
|
+
param_names=("gain", "offset"),
|
|
70
|
+
reference="sensor manual rev. 3, eq. (2)")
|
|
71
|
+
|
|
72
|
+
# 2. Before measuring: would 12 planned settings determine the
|
|
73
|
+
# parameters, and how well, at 0.05 units of reading noise?
|
|
74
|
+
x_planned = np.linspace(0.5, 5.0, 12)[:, None]
|
|
75
|
+
plan = information(m, theta=[2.0, 0.0], x=x_planned, sigmas=0.05)
|
|
76
|
+
print(plan["identifiable"], plan["sigma"])
|
|
77
|
+
|
|
78
|
+
# ... or let labplan pick the best 5 of the settings you can reach,
|
|
79
|
+
# and price a target error bar in repeats (a closed form):
|
|
80
|
+
pick = design(m, [2.0, 0.0], x_planned, n_pick=5, sigmas=0.05)
|
|
81
|
+
r, predicted = repeats_for({"gain": 0.01}, plan)
|
|
82
|
+
|
|
83
|
+
# 3. After measuring: fit, with the SAME matrix the plan promised.
|
|
84
|
+
res = fit(m, x_planned, y_measured, theta0=[1.0, 0.0], sigmas=0.05)
|
|
85
|
+
print(res.values, res.sigma, res.chi2)
|
|
86
|
+
|
|
87
|
+
# 4. Keep the record: what, to which data (sha256), by what, when.
|
|
88
|
+
rec = audit_record(res, operator="T. Mahim", note="bench 2, warm-up ok")
|
|
89
|
+
print(report_text(rec))
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The central promise: the planner's error bars and the fit's error
|
|
93
|
+
bars are the same matrix, so what is promised before the measurement
|
|
94
|
+
is what is reported after -- exactly, whenever the model describes
|
|
95
|
+
the data. The tests assert that equality to machine precision.
|
|
96
|
+
|
|
97
|
+
## When the model might be wrong
|
|
98
|
+
|
|
99
|
+
Model-based error bars assume the model is right. For the day it is
|
|
100
|
+
not, `conformal_quantile` supplies distribution-free prediction
|
|
101
|
+
intervals from held-out calibration data, with an exact finite-sample
|
|
102
|
+
guarantee that holds whatever the model and whatever the noise (split
|
|
103
|
+
conformal prediction; Vovk, Gammerman and Shafer, Algorithmic
|
|
104
|
+
Learning in a Random World, Springer (2005); Lei et al., J. Am.
|
|
105
|
+
Stat. Assoc. 113, 1094 (2018); Angelopoulos and Bates,
|
|
106
|
+
arXiv:2107.07511):
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
from labplan import conformal_quantile, conformal_interval
|
|
110
|
+
|
|
111
|
+
q = conformal_quantile(abs_errors_heldout, alpha=0.1) # 90% level
|
|
112
|
+
lo, hi = conformal_interval(new_predictions, q)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Its honest limits are stated in the docstring rather than hidden:
|
|
116
|
+
the guarantee is marginal, and it needs the calibration data to be
|
|
117
|
+
exchangeable with the new measurement -- last month's instrument
|
|
118
|
+
state does not certify next month's drift.
|
|
119
|
+
|
|
120
|
+
## What is inside
|
|
121
|
+
|
|
122
|
+
- **`Model`**: your forward function with named parameters and a
|
|
123
|
+
mandatory `reference` -- provenance travels with every prediction,
|
|
124
|
+
the same rule every package in this organization applies.
|
|
125
|
+
- **`information` / `design` / `repeats_for`**: predicted error bars
|
|
126
|
+
from the design alone (the Fisher information of independent
|
|
127
|
+
Gaussian measurements; any statistics text, under "Cramer-Rao
|
|
128
|
+
bound"); greedy D-optimal selection of the most informative
|
|
129
|
+
settings (Pukelsheim, Optimal Design of Experiments, SIAM (2006));
|
|
130
|
+
and the exact 1/sqrt(repeats) law, inverted in closed form.
|
|
131
|
+
- **`fit`**: Levenberg-Marquardt weighted least squares in pure
|
|
132
|
+
NumPy, with exact known-noise covariance and a chi-squared check
|
|
133
|
+
when measurement errors are supplied, and residual-scaled error
|
|
134
|
+
bars (stated as such) when they are not.
|
|
135
|
+
- **`conformal_quantile` / `conformal_interval` / `coverage_exact`**:
|
|
136
|
+
distribution-free intervals with the exact finite-sample coverage
|
|
137
|
+
formula exposed for checking.
|
|
138
|
+
- **`audit_record` / `report_text`**: a JSON-serializable statement
|
|
139
|
+
of record -- model, source, values, error bars, goodness of fit,
|
|
140
|
+
identifiability, the sha256 of the exact data arrays, software
|
|
141
|
+
versions, UTC timestamp, operator -- and its human-readable
|
|
142
|
+
rendering.
|
|
143
|
+
- **`save_measurements_csv` / `load_measurements_csv`**: a plain,
|
|
144
|
+
checked file contract whose round trip is bit-exact.
|
|
145
|
+
|
|
146
|
+
## Refusals, not guesses
|
|
147
|
+
|
|
148
|
+
A design that cannot tell the parameters apart is refused with an
|
|
149
|
+
explanation, in the planner, the fit and the design tool alike --
|
|
150
|
+
judged on a unit-free (correlation-scaled) information matrix, so
|
|
151
|
+
mixed units can never fake or hide a degeneracy. Too few points, a
|
|
152
|
+
non-converging fit, an uncertifiable conformal level, a malformed
|
|
153
|
+
data file: each refuses with the reason and, where one exists, the
|
|
154
|
+
remedy.
|
|
155
|
+
|
|
156
|
+
## How it is checked
|
|
157
|
+
|
|
158
|
+
14 tests (Python 3.9-3.14, run in CI on every push), every
|
|
159
|
+
statistical claim pinned to a closed form, an exact identity, or
|
|
160
|
+
seeded simulation against an exact formula -- never a stored number.
|
|
161
|
+
Highlights: on a linear model the fit covariance equals the textbook
|
|
162
|
+
closed form sigma^2 (X^T X)^-1 exactly, and the planner promises the
|
|
163
|
+
same matrix; 400 seeded Monte-Carlo experiments match the reported
|
|
164
|
+
error bars; an exactly degenerate model is refused via an exact rank
|
|
165
|
+
argument; the greedy design obeys the rank-one determinant identity,
|
|
166
|
+
reproduces its own rule, never loses to a random subset, and -- for
|
|
167
|
+
the two-point line design -- matches the classical optimum found by
|
|
168
|
+
exhaustion; the repeat law is asserted by tiling the design; the
|
|
169
|
+
conformal quantile is the exact rank formula and seeded simulation
|
|
170
|
+
matches the exact closed-form coverage inside the published
|
|
171
|
+
two-sided guarantee; the audit record survives JSON round trip
|
|
172
|
+
exactly and its digest pins the exact data; file round trips are
|
|
173
|
+
bit-exact.
|
|
174
|
+
|
|
175
|
+
## Honest limits
|
|
176
|
+
|
|
177
|
+
Deliberate scope, designed out with reasons: the Gaussian
|
|
178
|
+
error-bar machinery is exact for independent Gaussian measurement
|
|
179
|
+
errors and first-order-accurate otherwise (the conformal tools are
|
|
180
|
+
the assumption-free complement, and their own limits are stated);
|
|
181
|
+
the greedy design is a transparent heuristic, not a proof of global
|
|
182
|
+
optimality; no physics ships in this package at all -- your model
|
|
183
|
+
and its `reference` carry the physics, and the nine physics packages
|
|
184
|
+
of this organization remain the place where specific instruments'
|
|
185
|
+
models live, each already wired into this same loop.
|
|
186
|
+
|
|
187
|
+
## Support and governance
|
|
188
|
+
|
|
189
|
+
Written and maintained by Tanvir Mahmud Mahim (Department of
|
|
190
|
+
Electrical and Electronic Engineering, BRAC University), who reviews
|
|
191
|
+
every change and takes the final decision on scope and releases.
|
|
192
|
+
Design questions are discussed in the open in issues and pull
|
|
193
|
+
requests, and the standing rule of
|
|
194
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) binds the maintainer exactly as it
|
|
195
|
+
binds contributors: a change that touches the statistics arrives with
|
|
196
|
+
a test, and a claim arrives with its source.
|
|
197
|
+
|
|
198
|
+
Support runs through the
|
|
199
|
+
[issue tracker](https://github.com/TaN-MM-Org/labplan/issues). Usage
|
|
200
|
+
questions are welcome alongside bug reports; a docstring that left a
|
|
201
|
+
unit or a convention unclear is treated as a documentation bug, not
|
|
202
|
+
user error. While the version is below 1.0 the API may still move
|
|
203
|
+
between minor versions; such changes are called out in the release
|
|
204
|
+
notes.
|
|
205
|
+
|
|
206
|
+
## License
|
|
207
|
+
|
|
208
|
+
Apache-2.0.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
labplan/__init__.py,sha256=vwzYsh_vjFZcdGgE5gb4HI9OXLcvDrJy-8ACuJD4YOs,2464
|
|
2
|
+
labplan/conformal.py,sha256=V57nOiHXhlcuhXrB0iRjKle3u3fMyZJIZ0BnHo1giIg,3668
|
|
3
|
+
labplan/fit.py,sha256=p6BK732Scqnz34RGozsX2MG2iL76HnLHkOPukfzzdas,5840
|
|
4
|
+
labplan/model.py,sha256=SPM3p9hcQ4rxtvPEgYzMkVpNYeyBOyjIHnzkjcKAigY,4497
|
|
5
|
+
labplan/plan.py,sha256=t44NyKXM0aDnH5hZZm5TQ2VujfdPcrq1PaazG6GArHI,6353
|
|
6
|
+
labplan/records.py,sha256=mkP1jFMPp0DYXrE68LQy9V9f6GcyAO9Y5xkjX1Gr1Bo,3115
|
|
7
|
+
labplan/report.py,sha256=RueDQxiiLwqytxICymCrK4s1VFWaytnzfeoMqlqcm_0,3949
|
|
8
|
+
labplan/stats.py,sha256=Gu_6nHR-daFqDmRGnKb3_RVCV5-1UBL26xWkOE4OoKA,2517
|
|
9
|
+
labplan-0.1.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
10
|
+
labplan-0.1.0.dist-info/METADATA,sha256=ls9uYJUP15GXDidjS3tUmM9iM9U-tmh-pV_Dp6Moe5U,9372
|
|
11
|
+
labplan-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
12
|
+
labplan-0.1.0.dist-info/top_level.txt,sha256=JhJuOv_Gavmvt5oPPnnT9SVWQNam6jJQRf2GVqbd9XQ,8
|
|
13
|
+
labplan-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
labplan
|