Interpolation
Provides interpolation algorithms across tabular data for vivarium
simulations.
- vivarium.engine.framework.lookup.interpolation.has_named_row_index(data)[source]
Return True if
datacarries its lookup attributes on the row index.- Parameters:
data (LookupTableData)
- Return type:
TypeGuard[pd.DataFrame | pd.Series[Any]]
- class vivarium.engine.framework.lookup.interpolation.Interpolation(data, value_columns, order, extrapolate, validate)[source]
A callable that interpolates value columns over categorical/continuous parameters.
Lookup attributes are inferred from the input data: when the data has its lookup attributes in the row index (see
has_named_row_index()), the row-index level names are the attributes; when the data is a flat DataFrame (deprecated), the attributes are the columns not listed invalue_columns. Attributes whose names follow the<name>_start/<name>_endconvention are paired up as continuous binned parameters; all other attributes are treated as categorical key columns.This naming convention is the only way
Interpolationdistinguishes continuous from categorical parameters, so the class is not fully generic — it is the interpolation primitive thatLookupTableis built on.- Parameters:
- value_columns: pd.Index[Any]
User-facing column labels (including tuple labels from a column
MultiIndexandNonefrom a nameless Series) restored on the output of__call__().
- continuous_parameters: list[str]
Lookup attributes used as binned ranges. The base name (e.g.
"age") of each<name>_start/<name>_endpair.
- categorical_parameters: list[str]
Lookup attributes used to select between interpolation sub-tables.
- data: pd.DataFrame
Flat DataFrame the interpolation pipeline operates on. Value columns are renamed to opaque internal IDs (see
_FLAT_COLUMN_PREFIX);value_columnscarries the original user-facing labels and is reapplied to the output of__call__().
- order: int
Order of interpolation. Only
0is currently supported.
- extrapolate: bool
Whether to extrapolate beyond the edges of the supplied bins.
- validate: bool
Whether to validate inputs on construction and on call.
- interpolations: dict[Any, Order0Interp]
Per-categorical-group
Order0Interpinstances, keyed by the categorical-parameter tuple (orNonewhen there are no categorical parameters).
- vivarium.engine.framework.lookup.interpolation.validate_parameters(data, categorical_parameters, continuous_parameters, value_columns)[source]
- vivarium.engine.framework.lookup.interpolation.validate_call_data(data, categorical_parameters, continuous_parameters)[source]
- vivarium.engine.framework.lookup.interpolation.check_data_complete(data, continuous_parameters)[source]
Check that data is complete for interpolation.
For any parameters specified with edges, make sure edges don’t overlap and don’t have any gaps. Assumes that edges are specified with ends and starts overlapping (but one exclusive and the other inclusive) so can check that end of previous == start of current.
If multiple parameters, make sure all combinations of parameters are present in data.
Requires that bins of each parameter be standard across all values of other parameters, i.e., all bins for one parameter when de-duplicated should cover a continuous range of that parameter with no overlaps or gaps and the range covered should be the same for all combinations of other parameter values.
- Return type:
- Raises:
ValueError – If there are missing values for every combinations of continuous parameters.
ValueError – If the parameter data contains overlaps.
NotImplementedError – If a parameter contains non-continuous bins.
- Parameters: