BuildModelFromDAG.build#
- BuildModelFromDAG.build()[source]#
Construct and return the PyMC model implied by the DAG and data.
The method creates a
pm.Data
container for every node to align the observed data with the declareddims
. For each edgeA -> B
, a slope prior is instantiated frommodel_config['slope']
and used in the mean of nodeB
’s likelihood, which is instantiated frommodel_config['likelihood']
.- Returns:
pymc.Model
A fully specified model with slopes and likelihoods for all nodes.
Examples
Build a model and sample from it:
builder = BuildModelFromDAG( dag="A->B", df=df, target="B", dims=("date",), coords={"date": dates} ) model = builder.build() with model: idata = pm.sample(100, tune=100, chains=2, cores=2)
Multi-dimensional dims (e.g. date and country):
dims = ("date", "country") coords = {"date": dates, "country": ["Venezuela", "Colombia"]} builder = BuildModelFromDAG( dag="A->B, B->Y", df=df, target="Y", dims=dims, coords=coords ) model = builder.build()