Experiments and studies¶
A Measurement holds observed values, an Experiment binds a model and
its measurements, and a Study groups experiments with the parameters
they share or vary. See fitting
parameters.
diff_soup.inference.Measurement
dataclass
¶
One stream of observed values, compared with an observed quantity of the solution at the given times.
A measurement takes weight= or likelihood=, not both. Without a likelihood the fit is weighted least squares, and the statistics functions that need a noise model refuse it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The label of the measurement in results and diagnostics, unique within an experiment. |
required |
times
|
Any
|
The observation times, a one-dimensional array. |
required |
values
|
Any
|
The observed values with one row per time, or a function of no arguments returning them, called once when first needed. |
required |
weight
|
Any
|
A positive weight on the squared residual, a scalar or an array that broadcasts against |
None
|
likelihood
|
Likelihood | None
|
The noise model, such as Gaussian. |
None
|
observe
|
Callable | str | None
|
The observed quantity: a function |
None
|
mask
|
Any
|
One boolean per time, |
None
|
shape
|
tuple | None
|
The shape of |
None
|
dtype
|
Any
|
The dtype of |
None
|
diff_soup.inference.Experiment
dataclass
¶
One solve of a model, compared against its measurements.
Pass one or several experiments to an InferenceProblem or a Study. Every measurement time lies inside t_span.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
The built problem, or a Recipe template built with the template arguments in |
required |
solver
|
Any
|
The time-stepping solver used for every solve of the fit. |
required |
t_span
|
tuple[float, float]
|
The interval |
required |
initial_state
|
Any
|
The state the solve starts from at |
required |
measurements
|
tuple[Measurement, ...]
|
A non-empty tuple of Measurement with distinct names. |
required |
inputs
|
Mapping[str, Any]
|
Template arguments and fixed parameter values for this experiment alone, by name. |
dict()
|
id
|
Any
|
A hashable name for the experiment, or |
None
|
trajectory
|
Trajectory | None
|
SingleShoot or Multishoot, or |
None
|
schedule
|
Any
|
An operating protocol the solve follows, a |
None
|
parameters
|
Any
|
A mapping from each level of the study's Hierarchy to this experiment's member of it. |
None
|
diff_soup.inference.Study
dataclass
¶
A group of experiments with the parameters they share or vary, lowered with ds.lower for a joint fit.
With a Hierarchy, each experiment names its members in its own parameters=. With a ds.ParameterSet, clusters= gives the owner of each experiment for each cluster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiments
|
Experiment | Any
|
One Experiment or a non-empty iterable of them, with distinct ids. |
required |
parameters
|
ParameterSet | Hierarchy
|
A |
required |
clusters
|
Mapping[str, Any] | None
|
A mapping from cluster name to one owner label per experiment, for a |
None
|
independent
|
bool | None
|
Whether the experiments are independent, which must be |
None
|
diff_soup.inference.Hierarchy
dataclass
¶
Declare which parameters of a study are shared and which take one value per member of a level.
Pass it as parameters= of a Study. Each handle appears once,
in shared or under one level of per, and experiments that name the same member share its
values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
levels
|
Any
|
The level names between the study and its experiments, outermost first, or
|
None
|
shared
|
Any
|
The handles with one value for the whole study. |
()
|
per
|
Any
|
A mapping from level name to the handles with one value per member of that level,
where the key |
None
|
Lowered studies¶
ds.lower(study) returns a LoweredStudy for a hierarchical fit (hierarchical
fits).
diff_soup.inference.LoweredStudy
¶
A study prepared for fitting by ds.lower(study), with its experiments' solves compiled and batched.
ds.inference.optsolve and the statistics methods take it in place of an
InferenceProblem, and ds.inference.TrustRegion fits only this form. A failed solve is
retried from a smaller first step.
retry_kinds
property
¶
retry_kinds: tuple[str, ...]
The failure kinds that are solved again from a smaller first step.
retry_first_step_factors
property
¶
retry_first_step_factors: tuple[float, ...]
The factors of the first step a failed solve is retried with, in the order tried.
evaluation_noise
property
¶
evaluation_noise: float | None
The relative noise of the objective's evaluation, by default the largest rtol of the experiments' solvers, or None.
prepare
¶
prepare(*, modes: Any = None, **options: Any) -> PrepareReport
Compile the study's solves before the first evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
modes
|
Any
|
The evaluation modes to compile, such as |
None
|
**options
|
Any
|
Not accepted. |
{}
|
Returns:
| Type | Description |
|---|---|
PrepareReport
|
A report of what was compiled and how long each setup stage took. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any keyword other than |
evaluate
¶
evaluate(request: Request) -> Results
Evaluate the experiments' solves for one request, retrying failed solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
The |
required |
Returns:
| Type | Description |
|---|---|
Results
|
The |
log_likelihood
¶
log_likelihood(x: Any) -> Any
The log-likelihood of the measurements at x, differentiable with JAX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
A point of the joint parameter vector. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A scalar JAX array. |
value_and_gradient
¶
value_and_gradient(points: Any, *, weights: Any = None) -> ValueAndGradient
Evaluate the objective and its gradient at many points in one batched request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
Any
|
One point |
required |
weights
|
Any
|
A |
None
|
Returns:
| Type | Description |
|---|---|
ValueAndGradient
|
A named tuple of |
observed_information
¶
observed_information(x: Any) -> Any
The observed information at x, the Hessian of the negative log-likelihood.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
A point of the joint parameter vector. |
required |
expected_information
¶
expected_information(x: Any) -> Any
The expected information at x, the Gauss-Newton matrix, or None when the study does not provide it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Any
|
A point of the joint parameter vector. |
required |
tables
¶
tables(lane_ids: Any) -> TreeTables | LevelTables
The tables that map the given solves to their columns of the joint vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lane_ids
|
Any
|
The ids of the solves, as a request's results list them. |
required |
Returns:
| Type | Description |
|---|---|
TreeTables | LevelTables
|
|
for_population
¶
for_population(members: int, *, chunk: Any = 'auto') -> LoweredStudy
A copy of the study re-planned to evaluate members parameter points per request.
Nothing is lowered again, and the copy reuses this study's compiled solves.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
members
|
int
|
The number of points each request evaluates. |
required |
chunk
|
Any
|
The number of solves one compiled call evaluates, |
'auto'
|
close
¶
close() -> None
Stop the other processes of a run of several processes, or do nothing in a run of one.