Model Building (liesel.model)

Model Building (liesel.model)#

This is an overview of the most important building blocks for setting up your model graph with liesel.model.

We usually import liesel.model as follows:

import liesel.model as lsl

The model building workflow in Liesel consists of two steps:

  1. Set up the nodes and variables that make up your model.

  2. Set up a GraphBuilder, add your root node(s) to it, and call GraphBuilder.build_model() to build your model graph.

Note

This document provides an overview of the most important classes for model building. You find more guidance on how to use them in the respective API documentation and in the tutorials.

Nodes and Variables#

The fundamental building blocks of your model graph are given by just four classes. Each of these building blocks is documented with examples, so make sure to check them out.

Var

A variable in a statistical model, typically with a probability distribution.

Data

A Node subclass that holds constant values.

Calc

A Node subclass that calculates its value based on its inputs nodes.

Dist

A Node subclass that wraps a probability distribution.

To set up Var objects, Liesel provides two helper functions:

obs

Helper function that returns an observed Var.

param

Helper function that returns a parameter Var.

Defining Var objects with these functions makes sure that the respective Var.observerd and Var.parameter flags are correctly set. This in turn ensures that the Var.log_prob of an observed variable will be included in the Model.log_lik and the Var.log_prob of a parameter variable will be included in the Model.log_prior.

Build and plot your model#

The most important class here is the GraphBuilder.

GraphBuilder

A graph builder, used to set up a Model.

Model

A model with a static graph.

plot_vars

Plots the variables of a Liesel model.

plot_nodes

Plots the nodes of a Liesel model.