Interpolation
Provides interpolation algorithms across tabular data for vivarium
simulations.
- class vivarium.engine.framework.lookup.interpolation.ContinuousParameter(name, start_column, end_column, left_edges, max_right)[source]
A continuous (binned) lookup parameter.
- Parameters:
- 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
vivarium.engine.types.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.For order 0 (currently the only supported order) a call resolves each interpolant to the bin its continuous parameters fall in and returns that bin’s values. This requires that the key columns uniquely identify a data row and that the bin edges are identical across every categorical group; both are validated on construction when
validateis set. Withvalidate=Falseviolations surface as aKeyErrororpandas.errors.MergeErroron call.- Parameters:
- property continuous_parameters: list[str]
Lookup attributes used as binned ranges. The base name (e.g.
"age") of each<name>_start/<name>_endpair.
- 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__().
- 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__().
- categorical_parameters: list[str]
Lookup attributes used to select between value rows.
- 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.
- vivarium.engine.framework.lookup.interpolation.validate_parameters(data, categorical_parameters, continuous_parameters, value_columns)[source]
Validate that the source data satisfies the lookup contract.
- vivarium.engine.framework.lookup.interpolation.validate_call_data(data, categorical_parameters, continuous_parameters)[source]
- Return type:
- Parameters:
data (DataFrame)
continuous_parameters (Sequence[ContinuousParameter])
- vivarium.engine.framework.lookup.interpolation.check_data_complete(data, continuous_parameters)[source]
Check that data provides complete, contiguous bins for each continuous parameter.
For each parameter, require that every combination of parameter bins is present, that each left edge pairs with exactly one right edge, and that the bins tile a continuous range: each bin’s exclusive right edge equals the next bin’s inclusive left edge.
- Return type:
- Raises:
ValueError – If bins are duplicated or overlap, or if a combination of continuous parameters is missing.
NotImplementedError – If a parameter contains non-continuous bins.
- Parameters:
data (DataFrame)
continuous_parameters (Sequence[ContinuousParameter])