ForwardSamplingInference.makeInference

ForwardSamplingInference.makeInference(timeHorizon=5000, burnIn=100)

Start a new sample and normalize resulting posteriors to get an aproximation of the inference.

Parameters:
  • timeHorizon (float) – Duration of the sampling.

  • burnIn (int) – Number of runs before starting the sampling (to ensure ergodicity).

Returns:

Number of runs.

Return type:

int

Example

import numpy as np

import pyagrum as gum
import pyagrum.ctbn as ct

ctbn = ct.CTBN()
ctbn.add(gum.LabelizedVariable("A", "A", ["a0", "a1"]))
ctbn.add(gum.LabelizedVariable("B", "B", ["b0", "b1"]))
ctbn.addArc("A", "B")
ctbn.CIM("A").fromMatrix(np.array([[-2.0, 2.0], [1.0, -1.0]]))
ctbn.CIM("B")[{"A": "a0"}] = [[-1, 1], [2, -2]]
ctbn.CIM("B")[{"A": "a1"}] = [[-3, 3], [4, -4]]
ie = ct.ForwardSamplingInference(ctbn)
nbEvents = ie.makeInference(timeHorizon=200, burnIn=10)
nbEvents > 0
# True
round(ie.posterior("B").sum(), 4)
# 1.0

Class

ForwardSamplingInference