verify.match¶
Match the rows of the results of two dumps and measure their difference.
RowMatch
¶
Bases: NamedTuple
The rows of the output of a task in two dumps which are compared.
InterpolationRange
¶
Bases: NamedTuple
The range of a trajectory at times, from the interpolants of its steps.
Columns
¶
Bases: NamedTuple
A variable of a task in two dumps, one column per point of a scan.
The time is the first dimension, the points are the other dimensions of the variable, matched by name and flattened in the order of the old dump.
PointMatch
¶
Bases: NamedTuple
The rows of points of a task which are compared, see point_matches.
ArrayDifference
¶
Bases: NamedTuple
The difference of an array of two dumps and the resolution it was found at.
point_times
¶
Get the output time of every value of a variable of a task, in its layout.
A grid has one vector of times (("time",)) for every point of a scan; the
ragged layout (_point) has the times of every point, over the dimensions
of the variable, padded with NaN to the longest point.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dump
|
Dump
|
the dump. |
required |
sid
|
str
|
the experiment. |
required |
task
|
str
|
the task. |
required |
dims
|
Sequence[str]
|
the dimensions of the variable. |
required |
shape
|
tuple[int, ...]
|
the shape of the variable. |
required |
Returns:
| Type | Description |
|---|---|
ndarray | None
|
The times in the shape of the variable, or |
ndarray | None
|
times or they do not fit the variable. |
matched_rows
¶
Match the rows of the output times of a task in two dumps.
The times are matched relative to the largest time (TIME_RESOLUTION).
The rows of a time which an output has more than once (a change: the state
before it, then the state after it) are matched from the last one, the k-th
last old row with the k-th last new row, and the surplus rows of the output
with more of them are left out. So every row of the common times of two dumps
is compared, and where one dump has fewer rows at a change than the other
the state after the change is the one compared.
The steps of the integrator differ between two runs whose model or
tolerances differ, so most times of an adaptive output are in one dump
only. A row at such a time is compared with the other output interpolated
at its time (interpolated_old, interpolated_new) if the time lies
between two rows of the other output (a segment between its changes,
interpolation_envelope) and occurs once in its own output (the states
before and after a change which the other output does not have are not
one value of it); every other row of a time only one output has is
unmatched.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_times
|
ndarray
|
the output times of the old dump. |
required |
new_times
|
ndarray
|
the output times of the new dump. |
required |
Returns:
| Type | Description |
|---|---|
RowMatch
|
The rows which are compared and the rows which are not. |
interpolation_envelope
¶
Get the range of the trajectory of an output at times, from its interpolants.
The rows of an adaptive output are the steps of the integrator, which are
too far apart for one interpolant to reach the threshold of a comparison:
between two runs of hctz whose steps differ (the relative tolerance 1e-9
and 1e-10), the linear interpolant is up to 4e-2 of the scale of an array
off the other run, the monotone cubic one 4e-3, the cubic spline swings
at a sharp transient (the concentration in the urine after it was emptied).
Three interpolants of every segment between the changes of the output
(the rows between two repeated times), the linear one, the monotone cubic
one (PCHIP) and the cubic spline (not-a-knot), span the envelope of the
trajectory, and their spread is the uncertainty of the interpolation: the
range is the envelope widened by its width on both sides. A value within
it is no difference which the steps of the output can tell, and the
spread is the resolution which the interpolation reaches: it depends on
the density of the steps only, about 1e-2 of the scale of an oral dose on
20 steps over 48 hr and up to 4e-2 on the steps of hctz, so compare
reports an array whose resolution is coarser than its threshold as
unresolved, never as equal. A column with a value which is not finite in a
segment is interpolated linearly there.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
ndarray
|
the output times, ascending, a time of a change twice. |
required |
values
|
ndarray
|
the values of the rows, (rows, columns). |
required |
at
|
ndarray
|
the times, each between two rows of a segment. |
required |
Returns:
| Type | Description |
|---|---|
InterpolationRange
|
The range and the spread of the interpolants, (times, columns) each. |
columns
¶
task_columns
¶
Get the output times of every point of a task in two dumps.
The times are those of a variable of the task (the first by name), so that the points are matched by the names of their dimensions as the variables are; a task with the times only compares their arrays.
Returns:
| Type | Description |
|---|---|
Columns | None
|
The times as the columns (values and times), or |
point_matches
¶
Match the rows of every point of a task by its own times.
The points of a grid have the same times and one match; a point of a ragged result is matched by its own times, without the NaN which pad it to the longest point. Points with the same times in both dumps share a match.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_times
|
ndarray
|
the times of the old dump, (rows, points). |
required |
new_times
|
ndarray
|
the times of the new dump, (rows, points). |
required |
Returns:
| Type | Description |
|---|---|
list[PointMatch]
|
The matches. |
interpolated_pairs
¶
Get the rows of times only one dump has with the other dump at their times.
A row of the old dump is paired with the nearest value of the range of
the interpolants of the new dump at its time (interpolation_envelope),
a row of the new dump with the nearest value of the range of the old
dump, so the difference of a pair is the distance from the range, zero
within it. The old value comes first, the scale of a comparison, the
spread of the interpolants at the row third, the resolution of the pair.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
found
|
Columns
|
the variable of a task in the two dumps. |
required |
match
|
PointMatch
|
the match of the rows of points with the same times. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[ndarray, ndarray, ndarray]]
|
The old and the new values and the spread, (rows, points) each. |
relative_difference
¶
Get the difference of a result array on the matched rows.
The time is moved first, the other dimensions are matched by name (a
dimension of size 1 which only one array has is left out), and the rows of
every point are matched by its own times (point_matches); a row at a
time which only one dump has is compared with the other dump interpolated
at its time, its distance from the range of the interpolants
(interpolated_pairs). The difference is max|new - old| / max|old|; other
dimensions and NaN at different positions are an infinite difference. A
numeric array without a time, e.g. the values at the end of the points of
a scan, is compared on the same dimensions relative to its scale, any
other array exactly; the variable time is compared as the output times
of the points of the task.
relative_differences
¶
Get the difference of every result array of keys, see relative_difference.
The arrays of a task with the same output times are compared together, so
that the interpolants of a segment are built once for all of them. An array
is compared relative to its scale, but at least to SCALE_FLOOR of the
largest scale of its variable in the tasks of its experiment among the
keys: a variable which is zero in a task, e.g. the drug of a control
without a dose, is the noise of the integrator there (1e-24 against 1e-4
of the doses in hctz), which differs with every other step. The resolution
of an array is the largest spread of the interpolants of its interpolated
rows (interpolation_envelope) relative to the same scale.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old
|
Dump
|
the old dump. |
required |
new
|
Dump
|
the new dump. |
required |
keys
|
Iterable[tuple[str, str, str]]
|
the arrays, (experiment, task, variable). |
required |
Returns:
| Type | Description |
|---|---|
dict[tuple[str, str, str], ArrayDifference]
|
The difference and the resolution of every array. |
scaled_difference
¶
Get max|new - old| / max|old| over pairs of old and new arrays.
NaN at different positions is an infinite difference.