Grid Alchemy

In order to build two-level models with the settings from EpiViz-AT but at different parent locations, and extracting the correct information from the measurement inputs, we use a wrapper around all of the modeling components, with a method called construct_two_level_model.

This alchemy object is one of the three things that is read in each time we grab a Context object.

class cascade_at.model.grid_alchemy.Alchemy(settings)[source]

Bases: object

An object initialized with model settings from cascade.settings.configuration.Configuration that can be used to construct parent-child location-specific models with the attribute ModelConstruct.construct_two_level_model().

Examples

>>> from cascade_at.settings.base_case import BASE_CASE
>>> from cascade_at.settings.settings import load_settings
>>> from cascade_at.inputs.measurement_inputs import MeasurementInputsFromSettings
>>> settings = load_settings(BASE_CASE)
>>> mc = Alchemy(settings)
>>> i = MeasurementInputsFromSettings(settings)
>>> i.get_raw_inputs()
>>> mc.construct_two_level_model(location_dag=i.location_dag,
>>>                              parent_location_id=102,
>>>                              covariate_specs=i.covariate_specs)
construct_age_time_grid()[source]

Construct a DEFAULT age-time grid, to be updated when we initialize the model.

Return type

Dict[str, ndarray]

construct_single_age_time_grid()[source]

Construct a single age-time grid. Use this age and time when a smooth grid doesn’t depend on age and time.

Return type

Tuple[ndarray, ndarray]

get_smoothing_grid(rate)[source]

Construct a smoothing grid for any rate in the model.

Parameters

rate (Smoothing) – Some smoothing form for a rate.

Return type

SmoothGrid

Returns

  • The rate translated into a SmoothGrid based on the model settings’

  • default age and time grids.

get_all_rates_grids()[source]

Get a dictionary of all the rates and their grids in the model.

Return type

Dict[str, SmoothGrid]

static override_priors(rate_grid, update_dict=typing.Dict[str, numpy.ndarray], new_prior_distribution='gaussian')[source]

Override priors for rates. This is used when we want to do posterior to prior, so we are overriding the global settings with location-specific settings based on parent posteriors.

Parameters
  • rate_grid (SmoothGrid) – SmoothGrid object for a rate

  • update_dict – Dictionary with ages and times vectors and draws for values, dage, and dtime to use in overriding the prior.

  • new_prior_distribution (Optional[str]) – The new prior distribution to override the existing priors.

static apply_min_cv_to_prior_grid(prior_grid, min_cv, min_std=1e-10)[source]

Applies the minimum coefficient of variation to a _PriorGrid to enforce that minCV across all variables in the grid. Updates the _PriorGrid in place.

Return type

None

construct_two_level_model(location_dag, parent_location_id, covariate_specs, weights=None, omega_df=None, update_prior=None, min_cv=None, update_mulcov_prior=None)[source]

Construct a Model object for a parent location and its children.

Parameters
  • location_dag (LocationDAG) – Location DAG specifying the location hierarchy

  • parent_location_id (int) – Parent location to build the model for

  • covariate_specs (CovariateSpecs) – covariate specifications, specifically will use covariate_specs.covariate_multipliers

  • weights (Optional[Dict[str, Var]]) –

  • omega_df (Optional[DataFrame]) – data frame with omega values in it (other cause mortality)

  • update_prior (Optional[Dict[str, Dict[str, ndarray]]]) – dictionary of dictionary for prior updates to rates

  • update_mulcov_prior (Optional[Dict[Tuple[str, str, str], _Prior]]) – dictionary of mulcov prior updates

  • min_cv (Optional[Dict[str, Dict[str, float]]]) – dictionary (can be defaultdict) for minimum coefficient of variation keyed by cascade level, then by rate