The CTBN model

A CTBN is :
  • A bayesian network with pyagrum.DiscreteVariable random variables.

  • A pyagrum.DiGraph to represents dependency between random variables. The model allows cycles.

  • A pyagrum.ctbn.CIM containing exponential distribution parameters for each variable describing its transition duration.

A CIM is :
  • A Conditional Intensity Matrix. The CIM of a variable \(X\) contains at least two variables \(X_i\) and \(X_j\), from/to states.

  • Diagonal coefficients \(q_{i,j}\).

  • \(D_{i,j}\) ~ \(exp(q_{i,j})\) and \(D_i\) ~ \(exp(\sum_jq_{i,j})\), waiting time before going from state i to state j (resp. before leaving state i).

Properties :
  • \(P_X(x_1\rightarrow x_2) = \frac{q_{i,j}}{q_i}\)

  • \(\mathbb{E}(D_{i,j}) = \frac{1}{q_{i,j}}\)

  • \(\forall i \sum_{j}q_{i,j} = 0\)

class pyagrum.ctbn.CIM(pot=None)

This class is used to represent a CIM (random variables and parameters of transition time). A CIM is mainly a pyagrum.Tensor that contains the parameters of an exponential distribution. This class contains also contains the amalgamation operator, used for merging CIMs into one.

Notes

A static string DELIMITER is used to differentiate between the current state of the variable and its next state. <V_name><DELIMITER>i : starting node <V_name><DELIMITER>j : ending node

Parameters:

pot (pyagrum.Tensor | None) – Defines the new CIM using existing tensor.

Scientific notes

A conditional intensity matrix (CIM) [1] gives, for each configuration \(u\) of the parents of \(X\), the intensity matrix \(Q_{X \mid u}\) of a homogeneous Markov process: the off-diagonal entries \(q_{xx' \mid u} \geq 0\) are the rates of the transitions \(x \rightarrow x'\) and each row sums to 0, \(q_{xx \mid u} = -q_{x \mid u} = -\sum_{x' \neq x} q_{xx' \mid u}\). While its parents keep the values \(u\), \(X\) stays in \(x\) for a time of exponential law of parameter \(q_{x \mid u}\) (mean \(1/q_{x \mid u}\)), then moves to \(x'\) with probability \(q_{xx' \mid u} / q_{x \mid u}\). A state with \(q_{x \mid u} = 0\) is absorbing. The product * of two CIMs is their amalgamation (see pyagrum.ctbn.CTBN).

Methods

add()

Add a new variable to the CIM.

amalgamate()

Amalgamation of 2 CIMs, i.e combine 2 CIMs into one.

asTensor()

extract()

Creates a new CIM extracted from the current CIM using the instantiation ctxt.

findVar()

Finds a variable in the CIM using its name.

fromMatrix()

Fills the CIM with matrix mat.

getTensor()

instantiation()

isIM()

isParent()

Uses the syntax convention to check if a variable’s name is the name of a parent in the CIM.

nbrDim()

remove()

Removes a variable from the CIM.

toMatrix()

Converts a CIM to a numpy.array matrix.

varI()

varJ()

varRadical()

variable()

variablesSequence()

Attributes

DELIMITER

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

varNames

class pyagrum.ctbn.CTBN

This class is used to represent a CTBN. A CTBN is : a set of random variables, a CIM for each one of them and a pyagrum.DiGraph to represent dependency relations.

_graph

Graph representing dependency relations between variables. Node names are registered via setName/idFromName.

Type:

pyagrum.DiGraph

_cim

Dict containing a CIM for each nodeId(the integer given to a variable).

Type:

dict[int, CIM]

_id2var

Dict containing the variable associated to a node id.

Type:

dict[int, pyagrum.DiscreteVariable]

Scientific notes

A continuous-time Bayesian network (CTBN) [1] describes a process with finitely many states evolving over continuous time. Each variable \(X\) is a continuous-time Markov process whose transitions depend only on the current values \(u\) of its parents in a directed graph, which may contain cycles (an arc \(Y \rightarrow X\) only says that the speed and the targets of the transitions of \(X\) depend on the current value of \(Y\)). The dynamics of \(X\) is given by its conditional intensity matrices \(Q_{X \mid u}\), one per configuration of its parents (see pyagrum.ctbn.CIM).

The CTBN is a factored representation of a single homogeneous Markov process over the joint states, whose intensity matrix, of size \(\prod_X |\mathrm{Val}(X)|\), is the amalgamation of all the CIMs [1]:

\[Q_{\mathbf{X}} = \mathop{\ast}_{X} Q_{X \mid \mathrm{Pa}(X)} .\]

Its entry for a change of \(X\) alone from \(x\) to \(x'\) is \(q_{xx' \mid u}\), with \(u\) read in the current state; the entries for simultaneous changes of several variables are 0; its diagonal is \(-\sum_X q_{x \mid u}\). Then \(P(\mathbf{X}(t)) = P(\mathbf{X}(0))\, \exp(t\, Q_{\mathbf{X}})\).

Implementation limit. Unlike [1], the model holds no initial distribution \(P(\mathbf{X}(0))\): the inferences start from the uniform distribution (pyagrum.ctbn.SimpleInference, pyagrum.ctbn.ForwardSamplingInference).

Methods

CIM()

add()

Add a new variable to the Ctbn.

addArc()

Adds an arc val1 -> val2.

arcs()

children()

childrenNames()

completeInstantiation()

equals()

Tests the topologic equality with another CTBN.

eraseArc()

Erases an arc from the graph.

fullInstantiation()

labels()

name()

names()

node()

nodes()

parentNames()

parents()

toDot()

Create a display of the graph representating the CTBN.

variable()

variables()

Other functions for CTBN model

randomCTBN()

Generates a random CTBN using Prufer’s sequence.