pyagrum.lib.dynamicBN

dynamic Bayesian Network are a special class of BNs where variables can be subscripted by a (discrete) time. See this notebook.

_images/dBN.png

The purpose of this module is to provide basic tools for dealing with dynamic Bayesian Network (and inference) : modeling, visualisation, inference.

pyagrum.lib.dynamicBN.getTimeSlices(dbn, size=None)

Try to correctly represent dBN and 2TBN as an HTML string

Parameters:
  • dbn (pyagrum.BayesNet) – a 2TBN or an unrolled BN

  • size (int or str) – size of the fig

Return type:

str

pyagrum.lib.dynamicBN.getTimeSlicesRange(dbn)

get the range and (name,radical) of each variables

Parameters:

dbn (pyagrum.BayesNet) – a 2TBN or an unrolled BN

Returns:

all the timeslice of a dbn : [‘0’,’t’] for a classic 2TBN, range(T) for a classic unrolled BN

Return type:

dict[str,list[T[str,str]]]

pyagrum.lib.dynamicBN.is2TBN(bn)

Check if bn is a 2 TimeSlice Bayesian network

Parameters:

bn (pyagrum.BayesNet) – the Bayesian network

Returns:

True if the BN is syntaxically correct to be a 2TBN

Return type:

bool

pyagrum.lib.dynamicBN.plotFollow(lovars, twoTdbn, T, evs)

Plot modifications of variables in a 2TBN knowing the size of the time window (T) and the evidence on the sequence.

Parameters:
  • lovars (list) – List of variables to follow.

  • twoTdbn (pyagrum.BayesNet) – The two-timeslice dBN.

  • T (int) – The time range.

  • evs (dict) – Observations.

Return type:

None

pyagrum.lib.dynamicBN.plotFollowUnrolled(lovars, dbn, T, evs, vars_title=None)

Plot the dynamic evolution of a list of vars with a dBN.

Parameters:
  • lovars (list) – List of variables to follow.

  • dbn (pyagrum.BayesNet) – The unrolled dBN.

  • T (int) – The time range.

  • evs (dict) – Observations.

  • vars_title (str or dict, optional) – String for default title or a dictionary with the variable name as key and its title as value.

Return type:

None

pyagrum.lib.dynamicBN.realNameFrom2TBNname(name, ts)
Returns:

The dynamic name from static name and timeslice (no check).

Return type:

str

Parameters:
  • name (str)

  • ts (int)

pyagrum.lib.dynamicBN.showTimeSlices(dbn, size=None)

Try to correctly display dBN and 2TBN

Parameters:
  • dbn (pyagrum.BayesNet) – a 2TBN or an unrolled BN

  • size (int or str) – size of the fig

Return type:

None

pyagrum.lib.dynamicBN.unroll2TBN(dbn, nbr)

unroll a 2TBN given the nbr of timeslices

Parameters:
  • dbn (pyagrum.BayesNet) – a 2TBN or an unrolled BN

  • nbr (int) – the number of timeslice

Returns:

unrolled BN from a 2TBN and the nbr of timeslices

Return type:

pyagrum.BayesNet