Dismod Database Creation and Commands¶
When we want to fill a dismod database with some data for a model, and then run some commands on it, this is the script that we use.
We fill and extract dismod databases using Fill and Extract Helpers classes and functions. Then the databases are filled according to their settings and the arguments passed to these scripts, like whether to override the prior in the settings with a parent prior (this is called “posterior to prior”) or whether to add a covariate multiplier prior.
Dismod Database Script¶
-
cascade_at.executor.dismod_db.
dismod_db
(model_version_id, parent_location_id, sex_id=None, dm_commands=[], dm_options={}, prior_samples=False, prior_parent=None, prior_sex=None, prior_mulcov_model_version_id=None, test_dir=None, fill=False, save_fit=True, save_prior=True)[source]¶ Creates a dismod database using the saved inputs and the file structure specified in the context. Alternatively it will skip the filling stage and move straight to the command stage if you don’t pass –fill.
Then runs an optional set of commands on the database passed in the –commands argument.
Also passes an optional argument –options as a dictionary to the dismod database to fill/modify the options table.
- Parameters
model_version_id (
int
) – The model version IDparent_location_id (
int
) – The parent location for the databasesex_id (
Optional
[int
]) – The parent sex for the databasedm_commands (
List
[str
]) – A list of commands to pass to the run_dismod_commands function, executed directly on the dismod databasedm_options (
Dict
[str
,Union
[int
,float
,str
]]) – A dictionary of options to pass to the the dismod option tableprior_samples (
bool
) – Whether the prior was derived from samples or notprior_mulcov_model_version_id (
Optional
[int
]) – The model version ID to use for pulling covariate multiplier statistics as priors for this fitprior_parent (
Optional
[int
]) – An optional parent location ID that specifies where to pull the prior information from.prior_sex (
Optional
[int
]) – An optional parent sex ID that specifies where to pull the prior information from.test_dir (
Optional
[str
]) – A test directory to create the database in rather than the database specified by the IHME file system context.fill (
bool
) – Whether or not to fill the database with new inputs based on the model_version_id, parent_location_id, and sex_id. If not filling, this script can be used to just execute commands on the database instead.save_fit (
bool
) – Whether or not to save the fit from this database as the parent fit.save_prior (
bool
) – Whether or not to save the prior for the parent as the parent’s prior.
- Return type
None
-
cascade_at.executor.dismod_db.
save_predictions
(db_file, model_version_id, gbd_round_id, out_dir, locations=None, sexes=None, sample=False, predictions=None)[source]¶ Save the fit from this dismod database for a specific location and sex to be uploaded later on.
- Return type
None
-
cascade_at.executor.dismod_db.
fill_database
(path, settings, inputs, alchemy, parent_location_id, sex_id, child_prior, mulcov_prior, options)[source]¶ Fill a DisMod database at the specified path with the inputs, model, and settings specified, for a specific parent and sex ID, with options to override the priors.
- Return type
-
cascade_at.executor.dismod_db.
get_mulcov_priors
(model_version_id)[source]¶ Read in covariate multiplier statistics from a specific model version ID and returns a dictionary with a prior object for that covariate multiplier type, covariate name, and rate or integrand.
- Parameters
model_version_id (
int
) – The model version ID to pull covariate multiplier statistics from- Return type
Dict
[Tuple
[str
,str
,str
],_Prior
]
Dismod Database Cascade Operation¶
-
class
cascade_at.cascade.cascade_operations.
_DismodDB
(model_version_id, parent_location_id, sex_id, fill, prior_samples=False, prior_mulcov=False, prior_parent=None, prior_sex=None, dm_options=None, dm_commands=None, save_prior=False, save_fit=False, **kwargs)[source]¶ Bases:
cascade_at.cascade.cascade_operations._CascadeOperation
Base class for creating an operation that interfaces with the dismod database.
- Parameters
model_version_id (
int
) – The model version to run the model for.parent_location_id (
int
) – The parent location for this dismod database.sex_id (
int
) – The reference sex for this dismod database.fill (
bool
) – Whether or not to fill this database with new data base on the cached inputs or this model version.prior_samples (
bool
) – Whether or not the prior came from samples or just a mean fitprior_mulcov (
bool
) – The model version ID where the covariate multiplier statistics are saved. If this is included, then it will add a prior for the covariate multiplier(s) associated with this model version ID.prior_parent (
Optional
[int
]) – The location ID of the parent database to grab the prior for.prior_sex (
Optional
[int
]) – The sex ID of the parent database to grab the prior for.dm_options (
Optional
[Dict
[str
,Union
[int
,float
,str
]]]) – Additional options to pass to the dismod database, outside of those that would be passed based on the model settings.dm_commands (
Optional
[List
[str
]]) – Commands to run on the dismod database.save_prior (
bool
) – Whether or not to save the prior as the prior for this parent location.save_fit (
bool
) – Whether or not to save the fit as the fit for this parent location.kwargs –
-
class
cascade_at.cascade.cascade_operations.
Fit
(model_version_id, parent_location_id, sex_id, predict=True, fill=True, both=False, save_fit=False, save_prior=False, ode_fit_strategy=False, ode_init=False, **kwargs)[source]¶ Bases:
cascade_at.cascade.cascade_operations._DismodDB
Perform a fit on the dismod database for this model version ID, parent location, and sex ID. (See undocumented arguments in
_DismodDB
.- Parameters
model_version_id (
int
) –parent_location_id (
int
) –sex_id (
int
) –predict (
bool
) – Whether or not to run a predict on this database. Will predict for the avgint table that is based on the IHME-GBD demographics grid.fill (
bool
) –both (
bool
) – Whether or not to run a fit both (True) or a fit fixed only (False)save_fit (
bool
) –save_prior (
bool
) –kwargs –