Bayesian Networks

PyBNesian includes many different types of Bayesian networks.

Abstract Classes

This classes are abstract and define the interface for Bayesian network objects. The BayesianNetworkType specifies the type of Bayesian networks.

Each BayesianNetworkType can be used in many multiple variants of Bayesian networks: BayesianNetworkBase (a normal Bayesian network), ConditionalBayesianNetworkBase (a conditional Bayesian network) and DynamicBayesianNetworkBase (a dynamic Bayesian network).

class pybnesian.BayesianNetworkType

A representation of a BayesianNetwork that defines its behaviour.

__init__(self: pybnesian.BayesianNetworkType) None

Initializes a new BayesianNetworkType

__str__(self: pybnesian.BayesianNetworkType) str
alternative_node_type(model: BayesianNetworkBase or ConditionalBayesianNetworkBase, source: str) List[pybnesian.FactorType]

Returns all feasible alternative FactorType for node.

Parameters
  • model – BayesianNetwork model.

  • node – Name of the node.

Returns

A list of alternative FactorType. If you implement this method in a Python-derived class, you can return an empty list or None to specify that no changes are possible.

can_have_arc(model: BayesianNetworkBase or ConditionalBayesianNetworkBase, source: str, target: str) bool

Checks whether the BayesianNetworkType allows an arc source -> target in the Bayesian network model.

Parameters
  • model – BayesianNetwork model.

  • source – Name of the source node.

  • target – Name of the target node.

Returns

True if the arc source -> target is allowed in model, False otherwise.

compatible_node_type(model: BayesianNetworkBase or ConditionalBayesianNetworkBase, node: str, node_type: pybnesian.FactorType) bool

Checks whether the FactorType node_type is allowed for node by this BayesianNetworkType.

Parameters
  • model – BayesianNetwork model.

  • node – Name of the node to check.

  • node_typeFactorType for node.

Returns

True if the current FactorType is allowed, False otherwise.

data_default_node_type(self: pybnesian.BayesianNetworkType, datatype: pyarrow.DataType) List[pybnesian.FactorType]

Returns a list of default FactorType for the nodes of this Bayesian network type with data type datatype. This method is only needed for non-homogeneous Bayesian networks and defines the priority of use of the different FactorType for the given datatype. If a FactorType is blacklisted for a given node, the next element in the list is used as the default FactorType. See also BayesianNetworkBase.set_unknown_node_types().

Parameters

datatypepyarrow.DataType defining the type of data for a node.

Returns

List of default FactorType for a node given the datatype.

default_node_type(self: pybnesian.BayesianNetworkType) pybnesian.FactorType

Returns the default FactorType of each node in this Bayesian network type. This method is only needed for homogeneous Bayesian networks and returns the unique possible FactorType.

Returns

default FactorType for the nodes.

is_homogeneous(self: pybnesian.BayesianNetworkType) bool

Checks whether the Bayesian network is homogeneous.

A Bayesian network is homogeneous if the FactorType of all the nodes are forced to be the same: for example, a Gaussian network is homogeneous because the FactorType type of each node is always LinearGaussianCPDType.

Returns

True if the Bayesian network is homogeneous, False otherwise.

new_bn(self: pybnesian.BayesianNetworkType, nodes: List[str]) pybnesian.BayesianNetworkBase

Returns an empty unconditional Bayesian network of this type with the given nodes.

Parameters

nodes – Nodes of the new Bayesian network.

Returns

A new empty unconditional Bayesian network.

new_cbn(self: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str]) pybnesian.ConditionalBayesianNetworkBase

Returns an empty conditional Bayesian network of this type with the given nodes and interface_nodes.

Parameters
  • nodes – Nodes of the new Bayesian network.

  • nodes – Interface nodes of the new Bayesian network.

Returns

A new empty conditional Bayesian network.

class pybnesian.BayesianNetworkBase

This class defines an interface of base operations for all the Bayesian networks.

It reproduces many of the methods in the underlying graph to perform additional initializations and simplify the access. See Graph Module.

__str__(self: pybnesian.BayesianNetworkBase) str
add_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) None

Adds an arc between the nodes source and target. If the arc already exists, the graph is left unaffected.

Parameters
  • source – A node name.

  • target – A node name.

add_cpds(self: pybnesian.BayesianNetworkBase, cpds: List[pybnesian.Factor]) None

Adds a list of CPDs to the Bayesian network. The list may be complete (for all the nodes all the Bayesian network) or partial (just some a subset of the nodes).

Parameters

cpds – List of Factor.

add_node(self: pybnesian.BayesianNetworkBase, node: str) int

Adds a node to the Bayesian network and returns its index.

Parameters

node – Name of the new node.

Returns

Index of the new node.

arcs(self: pybnesian.BayesianNetworkBase) List[Tuple[str, str]]

Gets the list of arcs.

Returns

A list of tuples (source, target) representing an arc source -> target.

can_add_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) bool

Checks whether an arc between the nodes source and target can be added.

An arc addition can be not allowed for multiple reasons:

  • It generates a cycle.

  • It is a conditional BN and both source and target are interface nodes.

  • It is not allowed by the BayesianNetworkType.

Parameters
  • source – A node name.

  • target – A node name.

Returns

True if the arc can be added, False otherwise.

can_flip_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) bool

Checks whether an arc between the nodes source and target can be flipped.

An arc flip can be not allowed for multiple reasons:

Parameters
  • source – A node name.

  • target – A node name.

Returns

True if the arc can be added, False otherwise.

children(self: pybnesian.BayesianNetworkBase, node: str) List[str]

Gets the children nodes of a node.

Parameters

node – A node name.

Returns

Children node names.

clone(self: pybnesian.BayesianNetworkBase) pybnesian.BayesianNetworkBase

Clones (copies) this Bayesian network.

Returns

A copy of self.

collapsed_from_index(self: pybnesian.BayesianNetworkBase, index: int) int

Gets the collapsed index of a node from its index.

Parameters

index – Index of the node.

Returns

Collapsed index of the node.

collapsed_index(self: pybnesian.BayesianNetworkBase, node: str) int

Gets the collapsed index of a node from its name.

Parameters

node – Name of the node.

Returns

Collapsed index of the node.

collapsed_indices(self: pybnesian.BayesianNetworkBase) Dict[str, int]

Gets all the collapsed indices for the nodes in the graph.

Returns

A dictionary with the collapsed index of each node.

collapsed_name(self: pybnesian.BayesianNetworkBase, collapsed_index: int) str

Gets the name of a node from its collapsed index.

Parameters

collapsed_index – Collapsed index of the node.

Returns

Name of the node.

conditional_bn(*args, **kwargs)

Overloaded function.

  1. conditional_bn(self: pybnesian.BayesianNetworkBase) -> pybnesian.ConditionalBayesianNetworkBase

Returns the conditional Bayesian network version of this Bayesian network.

  • If self is not conditional, it returns a conditional version of the Bayesian network where the graph is transformed using Dag.conditional_graph.

  • If self is conditional, it returns a copy of self.

Returns

The conditional graph transformation of self.

  1. conditional_bn(self: pybnesian.BayesianNetworkBase, nodes: List[str], interface_nodes: List[str]) -> pybnesian.ConditionalBayesianNetworkBase

Returns the conditional Bayesian network version of this Bayesian network.

  • If self is not conditional, it returns a conditional version of the Bayesian network where the graph is transformed using Dag.conditional_graph using the given set of nodes and interface nodes.

  • If self is conditional, it returns a copy of self.

Returns

The conditional graph transformation of self.

contains_node(self: pybnesian.BayesianNetworkBase, node: str) bool

Tests whether the node is in the Bayesian network or not.

Parameters

node – Name of the node.

Returns

True if the Bayesian network contains the node, False otherwise.

cpd(self: pybnesian.BayesianNetworkBase, node: str) pybnesian.Factor

Returns the conditional probability distribution (CPD) associated to node. This is a Factor type.

Parameters

node – A node name.

Returns

The Factor associated to node

Raises

ValueError – If node do not have an associated Factor yet.

fit(self: pybnesian.BayesianNetworkBase, df: DataFrame, construction_args: pybnesian.Arguments = Arguments) None

Fit all the unfitted Factor with the data df.

Parameters
  • df – DataFrame to fit the Bayesian network.

  • construction_args – Additional arguments provided to construct the Factor.

fitted(self: pybnesian.BayesianNetworkBase) bool

Checks whether the model is fitted.

Returns

True if the model is fitted, False otherwise.

flip_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) None

Flips (reverses) an arc between the nodes source and target. If the arc do not exist, the graph is left unaffected.

Parameters
  • source – A node name.

  • target – A node name.

force_type_whitelist(self: pybnesian.BayesianNetworkBase, type_whitelist: List[Tuple[str, pybnesian.FactorType]]) None

Forces the Bayesian network to have the given whitelisted node types.

Parameters

type_whitelist – List of node type tuples (node, FactorType) that specifies the whitelisted type for each node.

force_whitelist(self: pybnesian.BayesianNetworkBase, arc_whitelist: List[Tuple[str, str]]) None

Include the given whitelisted arcs. It checks the validity of the graph after including the arc whitelist.

Parameters

arc_whitelist – List of arcs tuples (source, target) that must be added to the graph.

has_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) bool

Checks whether an arc between the nodes source and target exists.

Parameters
  • source – A node name.

  • target – A node name.

Returns

True if the arc exists, False otherwise.

has_path(self: pybnesian.BayesianNetworkBase, n1: str, n2: str) bool

Checks whether there is a directed path between nodes n1 and n2.

Parameters
  • n1 – A node name.

  • n2 – A node name.

Returns

True if there is an directed path between n1 and n2, False otherwise.

has_unknown_node_types(self: pybnesian.BayesianNetworkBase) bool

Checks whether there are nodes with an unknown node type (i.e. UnknownFactorType).

Returns

True if there are nodes with an unkown node type, False otherwise.

property include_cpd

This property indicates if the factors of the Bayesian network model should be saved when __getstate__ is called.

index(self: pybnesian.BayesianNetworkBase, node: str) int

Gets the index of a node from its name.

Parameters

node – Name of the node.

Returns

Index of the node.

index_from_collapsed(self: pybnesian.BayesianNetworkBase, collapsed_index: int) int

Gets the index of a node from its collapsed index.

Parameters

collapsed_index – Collapsed index of the node.

Returns

Index of the node.

indices(self: pybnesian.BayesianNetworkBase) Dict[str, int]

Gets all the indices in the graph.

Returns

A dictionary with the index of each node.

is_valid(self: pybnesian.BayesianNetworkBase, node: str) bool

Checks whether a node is valid (the node is not removed).

Parameters

node – Node name.

Returns

True if the node is valid, False otherwise.

logl(self: pybnesian.BayesianNetworkBase, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]

Returns the log-likelihood of each instance in the DataFrame df. This returns the sum of the log-likelihood for all the factors in the Bayesian network.

Parameters

df – DataFrame to compute the log-likelihood.

Returns

A numpy.ndarray vector with dtype numpy.float64, where the i-th value is the log-likelihod of the i-th instance of df.

name(self: pybnesian.BayesianNetworkBase, index: int) str

Gets the name of a node from its index.

Parameters

index – Index of the node.

Returns

Name of the node.

node_type(self: pybnesian.BayesianNetworkBase, node: str) pybnesian.FactorType

Gets the corresponding FactorType for node.

Parameters

node – A node name.

Returns

The FactorType of node.

node_types(self: pybnesian.BayesianNetworkBase) Dict[str, pybnesian.FactorType]

Gets the FactorType for all the nodes.

Returns

The corresponding FactorType for each node.

nodes(self: pybnesian.BayesianNetworkBase) List[str]

Gets the nodes of the Bayesian network.

Returns

Nodes of the Bayesian network.

num_arcs(self: pybnesian.BayesianNetworkBase) int

Gets the number of arcs.

Returns

Number of arcs.

num_children(self: pybnesian.BayesianNetworkBase, node: str) int

Gets the number of children nodes of a node.

Parameters

node – A node name.

Returns

Number of children nodes.

num_nodes(self: pybnesian.BayesianNetworkBase) int

Gets the number of nodes.

Returns

Number of nodes.

num_parents(self: pybnesian.BayesianNetworkBase, node: str) int

Gets the number of parent nodes of a node.

Parameters

node – A node name.

Returns

Number of parent nodes.

parents(self: pybnesian.BayesianNetworkBase, node: str) List[str]

Gets the parent nodes of a node.

Parameters

node – A node name.

Returns

Parent node names.

remove_arc(self: pybnesian.BayesianNetworkBase, source: str, target: str) None

Removes an arc between the nodes source and target. If the arc do not exist, the graph is left unaffected.

Parameters
  • source – A node name.

  • target – A node name.

remove_node(self: pybnesian.BayesianNetworkBase, node: str) None

Removes a node.

Parameters

node – A node name.

sample(self: pybnesian.BayesianNetworkBase, n: int, seed: Optional[int] = None, ordered: bool = False) DataFrame

Samples n values from this BayesianNetwork. This method returns a pyarrow.RecordBatch with n instances.

If ordered is True, it orders the columns according to the list BayesianNetworkBase.nodes(). Else, it orders the columns according to a topological sort.

Parameters
  • n – Number of instances to sample.

  • seed – A random seed number. If not specified or None, a random seed is generated.

  • ordered – If True, order the columns according to BayesianNetworkBase.nodes().

Returns

A DataFrame with n instances that contains the sampled data.

save(self: pybnesian.BayesianNetworkBase, filename: str, include_cpd: bool = False) None

Saves the Bayesian network in a pickle file with the given name. If include_cpd is True, it also saves the conditional probability distributions (CPDs) in the Bayesian network.

Parameters
  • filename – File name of the saved Bayesian network.

  • include_cpd – Include the CPDs.

set_node_type(self: pybnesian.BayesianNetworkBase, node: str, new_type: pybnesian.FactorType) None

Sets the new_type FactorType for node.

Parameters
  • node – A node name.

  • new_type – The new FactorType for node.

set_unknown_node_types(self: pybnesian.BayesianNetworkBase, df: DataFrame, type_blacklist: List[Tuple[str, pybnesian.FactorType]] = []) None

Changes the unknown node types (i.e. the nodes with UnknownFactorType) to the default node types specified by the BayesianNetworkType. If a FactorType is blacklisted for a given node, the next element in the BayesianNetworkType.data_default_node_type() list is used as the default FactorType.

Parameters
  • df – DataFrame to get the default node type for each unknown node type.

  • type_blacklist – List of type blacklist (forbidden FactorType).

slogl(self: pybnesian.BayesianNetworkBase, df: DataFrame) float

Returns the sum of the log-likelihood of each instance in the DataFrame df. That is, the sum of the result of BayesianNetworkBase.logl().

Parameters

df – DataFrame to compute the sum of the log-likelihood.

Returns

The sum of log-likelihood for DataFrame df.

type(self: pybnesian.BayesianNetworkBase) pybnesian.BayesianNetworkType

Gets the underlying BayesianNetworkType.

Returns

The BayesianNetworkType of self.

unconditional_bn(self: pybnesian.BayesianNetworkBase) pybnesian.BayesianNetworkBase

Returns the unconditional Bayesian network version of this Bayesian network.

  • If self is not conditional, it returns a copy of self.

  • If self is conditional, the interface nodes are included as nodes in the returned Bayesian network.

Returns

The unconditional graph transformation of self.

underlying_node_type(self: pybnesian.BayesianNetworkBase, df: DataFrame, node: str) pybnesian.FactorType

Gets the underlying FactorType for a given node type.

  1. If the node has a node type different from UnknownFactorType, it returns it.

  2. Else, it returns the first default node type from BayesianNetworkType.data_default_node_type.

Parameters
  • df – Data to extract the underlying node type (if 2) is required).

  • node – A node name.

Returns

The underlying FactorType for each node.

class pybnesian.ConditionalBayesianNetworkBase

Bases: BayesianNetworkBase

This class defines an interface of base operations for the conditional Bayesian networks.

It includes some methods of the ConditionalDag to simplify the access to the graph.

add_interface_node(self: pybnesian.ConditionalBayesianNetworkBase, node: str) int

Adds an interface node to the Bayesian network and returns its index.

Parameters

node – Name of the new interface node.

Returns

Index of the new interface node.

clone(self: pybnesian.ConditionalBayesianNetworkBase) pybnesian.ConditionalBayesianNetworkBase

Clones (copies) this Bayesian network.

Returns

A copy of self.

contains_interface_node(self: pybnesian.ConditionalBayesianNetworkBase, node: str) bool

Tests whether the interface node is in the Bayesian network or not.

Parameters

node – Name of the node.

Returns

True if the Bayesian network contains the interface node, False otherwise.

contains_joint_node(self: pybnesian.ConditionalBayesianNetworkBase, node: str) bool

Tests whether the node is in the joint set of nodes or not.

Parameters

node – Name of the node.

Returns

True if the node is in the joint set of nodes, False otherwise.

index_from_interface_collapsed(self: pybnesian.ConditionalBayesianNetworkBase, collapsed_index: int) int

Gets the index of a node from the interface collapsed index.

Parameters

collapsed_index – Interface collapsed index of the node.

Returns

Index of the node.

index_from_joint_collapsed(self: pybnesian.ConditionalBayesianNetworkBase, collapsed_index: int) int

Gets the index of a node from the joint collapsed index.

Parameters

collapsed_index – Joint collapsed index of the node.

Returns

Index of the node.

interface_arcs(self: pybnesian.ConditionalBayesianNetworkBase) List[Tuple[str, str]]

Gets the arcs where the source node is an interface node.

Returns

arcs with an interface node as source node.

interface_collapsed_from_index(self: pybnesian.ConditionalBayesianNetworkBase, index: int) int

Gets the interface collapsed index of a node from its index.

Parameters

index – Index of the node.

Returns

Interface collapsed index of the node.

interface_collapsed_index(self: pybnesian.ConditionalBayesianNetworkBase, node: str) int

Gets the interface collapsed index of an interface node from its name.

Parameters

node – Name of the interface node.

Returns

Interface collapsed index of the interface node.

interface_collapsed_indices(self: pybnesian.ConditionalBayesianNetworkBase) Dict[str, int]

Gets all the interface collapsed indices for the interface nodes in the graph.

Returns

A dictionary with the interface collapsed index of each interface node.

interface_collapsed_name(self: pybnesian.ConditionalBayesianNetworkBase, collapsed_index: int) str

Gets the name of an interface node from its collapsed index.

Parameters

collapsed_index – Collapsed index of the interface node.

Returns

Name of the interface node.

interface_nodes(self: pybnesian.ConditionalBayesianNetworkBase) List[str]

Gets the interface nodes of the Bayesian network.

Returns

Interface nodes of the Bayesian network.

is_interface(self: pybnesian.ConditionalBayesianNetworkBase, node: str) bool

Checks whether the node is an interface node.

Parameters

node – A node name.

Returns

True if node is interface node, False, otherwise.

joint_collapsed_from_index(self: pybnesian.ConditionalBayesianNetworkBase, index: int) int

Gets the joint collapsed index of a node from its index.

Parameters

index – Index of the node.

Returns

Joint collapsed index of the node.

joint_collapsed_index(self: pybnesian.ConditionalBayesianNetworkBase, node: str) int

Gets the joint collapsed index of a node from its name.

Parameters

node – Name of the node.

Returns

Joint collapsed index of the node.

joint_collapsed_indices(self: pybnesian.ConditionalBayesianNetworkBase) Dict[str, int]

Gets all the joint collapsed indices for the joint set of nodes in the graph.

Returns

A dictionary with the joint collapsed index of each joint node.

joint_collapsed_name(self: pybnesian.ConditionalBayesianNetworkBase, collapsed_index: int) str

Gets the name of a node from its joint collapsed index.

Parameters

collapsed_index – Joint collapsed index of the node.

Returns

Name of the node.

joint_nodes(self: pybnesian.ConditionalBayesianNetworkBase) List[str]

Gets the joint set of nodes of the Bayesian network.

Returns

Joint set of nodes of the Bayesian network.

num_interface_nodes(self: pybnesian.ConditionalBayesianNetworkBase) int

Gets the number of interface nodes.

Returns

Number of interface nodes.

num_joint_nodes(self: pybnesian.ConditionalBayesianNetworkBase) int

Gets the number of joint nodes. That is, num_nodes() + num_interface_nodes()

Returns

Number of joint nodes.

remove_interface_node(self: pybnesian.ConditionalBayesianNetworkBase, node: str) None

Removes an interface node.

Parameters

node – A node name.

sample(self: pybnesian.ConditionalBayesianNetworkBase, evidence: DataFrame, seed: Optional[int] = None, concat_evidence: bool = False, ordered: bool = False) DataFrame

Samples n values from this conditional BayesianNetwork conditioned on evidence. evidence must contain a column for each interface node. This method returns a pyarrow.RecordBatch with n instances.

If concat is True, it concatenates evidence in the result.

If ordered is True, it orders the columns according to the list BayesianNetworkBase.nodes(). Else, it orders the columns according to a topological sort.

Parameters
  • n – Number of instances to sample.

  • evidence – A DataFrame of n instances to condition the sampling.

  • seed – A random seed number. If not specified or None, a random seed is generated.

  • ordered – If True, order the columns according to BayesianNetworkBase.nodes().

Returns

A DataFrame with n instances that contains the sampled data.

set_interface(self: pybnesian.ConditionalBayesianNetworkBase, node: str) None

Converts a normal node into an interface node.

Parameters

node – A node name.

set_node(self: pybnesian.ConditionalBayesianNetworkBase, node: str) None

Converts an interface node into a normal node.

Parameters

node – A node name.

class pybnesian.DynamicBayesianNetworkBase

This class defines an interface of a dynamic Bayesian network.

A dynamic Bayesian network is defined over a set of variables. Each variable is replicated in different nodes (one for each temporal slice). Thus, we differentiate in this documentation between the terms “variable” and “node”. To create the nodes, we suffix the variable names using the structure [variable_name]_t_[temporal_index]. The variable_name is the name of each variable, and temporal_index is an index with a range [0-markovian_order]. The index “0” is considered the “present”, the index “1” delays the temporal one step into the “past”, and so on… This is related with the way DynamicDataFrame generates the columns.

The dynamic Bayesian is composed of two Bayesian networks:

  • a static Bayesian network that defines the probability distribution of the first markovian_order instances. It estimates the probability f(t_1,…, t_[markovian_order]). This Bayesian network is represented with a normal Bayesian network.

  • a transition Bayesian network that defines the probability distribution of the i-th instance given the previous markovian_order instances. It estimates the probability f(t_0 | t_1, …, t_[markovian_order]), where t_0 (the present) is the i-th instance. Once the probability of the i-th instance is estimated, the transition network moves a step forward, to estimate the (i+1)-th instance, and so on. This transition Bayesian network is represented with a conditional Bayesian network.

Both Bayesian networks must be of the same BayesianNetworkType.

__str__(self: pybnesian.DynamicBayesianNetworkBase) str
add_variable(self: pybnesian.DynamicBayesianNetworkBase, variable: str) None

Adds a variable to the dynamic Bayesian network. It adds a node for each temporal slice in the static and transition Bayesian networks.

Parameters

variable – Name of the new variable.

contains_variable(self: pybnesian.DynamicBayesianNetworkBase, variable: str) bool

Tests whether the variable is in the dynamic Bayesian network or not.

Parameters

variable – Name of the variable.

Returns

True if the dynamic Bayesian network contains the variable, False otherwise.

fit(self: pybnesian.DynamicBayesianNetworkBase, df: DataFrame, construction_args: pybnesian.Arguments = Arguments) None

Fit all the unfitted Factor with the data df in both the static and transition Bayesian networks.

Parameters
  • df – DataFrame to fit the dynamic Bayesian network.

  • construction_args – Additional arguments provided to construct the Factor.

fitted(self: pybnesian.DynamicBayesianNetworkBase) bool

Checks whether the model is fitted.

Returns

True if the model is fitted, False otherwise.

logl(self: pybnesian.DynamicBayesianNetworkBase, df: DataFrame) numpy.ndarray[numpy.float64[m, 1]]

Returns the log-likelihood of each instance in the DataFrame df.

Parameters

df – DataFrame to compute the log-likelihood.

Returns

A numpy.ndarray vector with dtype numpy.float64, where the i-th value is the log-likelihood of the i-th instance of df.

markovian_order(self: pybnesian.DynamicBayesianNetworkBase) int

Gets the markovian order of the dynamic Bayesian network.

Returns

markovian order of this dynamic Bayesian network.

num_variables(self: pybnesian.DynamicBayesianNetworkBase) int

Gets the number of variables.

Returns

Number of variables.

remove_variable(self: pybnesian.DynamicBayesianNetworkBase, variable: str) None

Removes a variable. It removes all the corresponding nodes in the static and transition Bayesian networks.

Parameters

variable – A variable name.

sample(self: pybnesian.DynamicBayesianNetworkBase, n: int, seed: Optional[int] = None) DataFrame

Samples n values from this dynamic Bayesian network. This method returns a pyarrow.RecordBatch with n instances.

Parameters
  • n – Number of instances to sample.

  • seed – A random seed number. If not specified or None, a random seed is generated.

save(self: pybnesian.DynamicBayesianNetworkBase, filename: str, include_cpd: bool = False) None

Saves the dynamic Bayesian network in a pickle file with the given name. If include_cpd is True, it also saves the conditional probability distributions (CPDs) in the dynamic Bayesian network.

Parameters
  • filename – File name of the saved dynamic Bayesian network.

  • include_cpd – Include the CPDs.

slogl(self: pybnesian.DynamicBayesianNetworkBase, df: DataFrame) float

Returns the sum of the log-likelihood of each instance in the DataFrame df. That is, the sum of the result of DynamicBayesianNetworkBase.logl().

Parameters

df – DataFrame to compute the sum of the log-likelihood.

Returns

The sum of log-likelihood for DataFrame df.

static_bn(self: pybnesian.DynamicBayesianNetworkBase) pybnesian.BayesianNetworkBase

Returns the static Bayesian network.

Returns

Static Bayesian network.

transition_bn(self: pybnesian.DynamicBayesianNetworkBase) pybnesian.ConditionalBayesianNetworkBase

Returns the transition Bayesian network.

Returns

Transition Bayesian network.

type(self: pybnesian.DynamicBayesianNetworkBase) pybnesian.BayesianNetworkType

Gets the underlying BayesianNetworkType.

Returns

The BayesianNetworkType of self.

variables(self: pybnesian.DynamicBayesianNetworkBase) List[str]

Gets the variables of the dynamic Bayesian network.

Returns

Variables of the dynamic Bayesian network.

Bayesian Network Types

class pybnesian.GaussianNetworkType

Bases: BayesianNetworkType

This BayesianNetworkType represents a Gaussian network: homogeneous with LinearGaussianCPD factors.

__init__(self: pybnesian.GaussianNetworkType) None
class pybnesian.SemiparametricBNType

Bases: BayesianNetworkType

This BayesianNetworkType represents a semiparametric Bayesian network: non-homogeneous with LinearGaussianCPD and CKDE factors for continuous data. The default is LinearGaussianCPD. It also supports discrete data using DiscreteFactor.

In a SemiparametricBN network, the discrete nodes can only have discrete parents.

__init__(self: pybnesian.SemiparametricBNType) None
class pybnesian.KDENetworkType

Bases: BayesianNetworkType

This BayesianNetworkType represents a KDE Bayesian network: homogeneous with CKDE factors.

__init__(self: pybnesian.KDENetworkType) None
class pybnesian.DiscreteBNType

Bases: BayesianNetworkType

This BayesianNetworkType represents a discrete Bayesian network: homogeneous with DiscreteFactor factors.

__init__(self: pybnesian.DiscreteBNType) None
class pybnesian.HomogeneousBNType

Bases: BayesianNetworkType

__init__(self: pybnesian.HomogeneousBNType, default_factor_type: pybnesian.FactorType) None

Initializes an HomogeneousBNType with a default node type.

Parameters

default_factor_type – Default factor type for all the nodes in the Bayesian network.

class pybnesian.HeterogeneousBNType

Bases: BayesianNetworkType

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.HeterogeneousBNType, default_factor_type: List[pybnesian.FactorType]) -> None

Initializes an HeterogeneousBNType with a list of default node types for all the data types.

Parameters

default_factor_type – Default factor type for all the nodes in the Bayesian network.

  1. __init__(self: pybnesian.HeterogeneousBNType, default_factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]]) -> None

Initializes an HeterogeneousBNType with a default node type for a set of data types.

Parameters

default_factor_type – Default factor type depending on the factor type.

default_node_types(self: pybnesian.HeterogeneousBNType) Dict[pyarrow.DataType, List[pybnesian.FactorType]]

Returns the dict of default FactorType for each data type.

Returns

dict of default FactorType for each data type.

single_default(self: pybnesian.HeterogeneousBNType) bool

Checks whether the HeterogeneousBNType defines only a default FactorType for all the data types.

Returns

True if it defines a single FactorType for all the data types. False if different default FactorType is defined for different data types.

class pybnesian.CLGNetworkType

Bases: BayesianNetworkType

This BayesianNetworkType represents a conditional linear Gaussian (CLG) network: heterogeneous with LinearGaussianCPD factors for the continuous data and DiscreteFactor for the categorical data.

In a CLG network, the discrete nodes can only have discrete parents, while the continuous nodes can have discrete and continuous parents.

__init__(self: pybnesian.CLGNetworkType) None

Bayesian Networks

class pybnesian.BayesianNetwork

Bases: BayesianNetworkBase

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str]) -> None

Initializes the BayesianNetwork with a given type and nodes.

Parameters
  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the BayesianNetwork with a given type and nodes. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • nodes – List of node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, arcs: List[Tuple[str, str]]) -> None

Initializes the BayesianNetwork with a given type and arcs (the nodes are extracted from the arcs).

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • arcs – Arcs of the Bayesian network.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the BayesianNetwork with a given type and arcs (the nodes are extracted from the arcs). It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • arcs – Arcs of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the BayesianNetwork with a given type, nodes and arcs.

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • nodes – List of node names.

  • arcs – Arcs of the Bayesian network.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the BayesianNetwork with a given type, nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • nodes – List of node names.

  • arcs – Arcs of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.Dag) -> None

Initializes the BayesianNetwork with a given type, and graph

Parameters
  1. __init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the BayesianNetwork with a given type, and graph. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this Bayesian network.

  • graphDag of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

can_have_cpd(self: pybnesian.BayesianNetwork, node: str) bool

Checks whether a given node name can have an associated CPD. For

Parameters

node – A node name.

Returns

True if the given node can have a CPD, False otherwise.

check_compatible_cpd(self: pybnesian.BayesianNetwork, cpd: pybnesian.Factor) None

Checks whether the given CPD is compatible with this Bayesian network.

Parameters

cpd – A Factor.

Returns

True if cpd is compatible with this Bayesian network, False otherwise.

graph(self: pybnesian.BayesianNetwork) pybnesian.Dag

Gets the underlying graph of the Bayesian network.

Returns

Graph of the Bayesian network.

Concrete Bayesian Networks

These classes implements BayesianNetwork with an specific BayesianNetworkType. Thus, the constructors do not have the type parameter.

class pybnesian.GaussianNetwork

Bases: BayesianNetwork

This class implements a BayesianNetwork with the type GaussianNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.GaussianNetwork, nodes: List[str]) -> None

Initializes the GaussianNetwork with the given nodes.

Parameters

nodes – List of node names.

  1. __init__(self: pybnesian.GaussianNetwork, arcs: List[Tuple[str, str]]) -> None

Initializes the GaussianNetwork with the given arcs (the nodes are extracted from the arcs).

Parameters

arcs – Arcs of the GaussianNetwork.

  1. __init__(self: pybnesian.GaussianNetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the GaussianNetwork with the given nodes and arcs.

Parameters
  1. __init__(self: pybnesian.GaussianNetwork, graph: pybnesian.Dag) -> None

Initializes the GaussianNetwork with the given graph.

Parameters

graphDag of the Bayesian network.

class pybnesian.SemiparametricBN

Bases: BayesianNetwork

This class implements a BayesianNetwork with the type SemiparametricBNType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.SemiparametricBN, nodes: List[str]) -> None

Initializes the SemiparametricBN with the given nodes.

Parameters

nodes – List of node names.

  1. __init__(self: pybnesian.SemiparametricBN, arcs: List[Tuple[str, str]]) -> None

Initializes the SemiparametricBN with the given arcs (the nodes are extracted from the arcs).

Parameters

arcs – Arcs of the SemiparametricBN.

  1. __init__(self: pybnesian.SemiparametricBN, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the SemiparametricBN with the given nodes and arcs.

Parameters
  1. __init__(self: pybnesian.SemiparametricBN, graph: pybnesian.Dag) -> None

Initializes the SemiparametricBN with the given graph.

Parameters

graphDag of the Bayesian network.

  1. __init__(self: pybnesian.SemiparametricBN, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the SemiparametricBN with the given nodes. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.SemiparametricBN, arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the SemiparametricBN with the given arcs (the nodes are extracted from the arcs). It specifies the node_types for the nodes.

Parameters
  • arcs – Arcs of the SemiparametricBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.SemiparametricBN, nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the SemiparametricBN with the given nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • arcs – Arcs of the SemiparametricBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.SemiparametricBN, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the SemiparametricBN with the given graph. It specifies the node_types for the nodes.

Parameters
  • graphDag of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

class pybnesian.KDENetwork

Bases: BayesianNetwork

This class implements a BayesianNetwork with the type KDENetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.KDENetwork, nodes: List[str]) -> None

Initializes the KDENetwork with the given nodes.

Parameters

nodes – List of node names.

  1. __init__(self: pybnesian.KDENetwork, arcs: List[Tuple[str, str]]) -> None

Initializes the KDENetwork with the given arcs (the nodes are extracted from the arcs).

Parameters

arcs – Arcs of the KDENetwork.

  1. __init__(self: pybnesian.KDENetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the KDENetwork with the given nodes and arcs.

Parameters
  • nodes – List of node names.

  • arcs – Arcs of the KDENetwork.

  1. __init__(self: pybnesian.KDENetwork, graph: pybnesian.Dag) -> None

Initializes the KDENetwork with the given graph.

Parameters

graphDag of the Bayesian network.

class pybnesian.DiscreteBN

Bases: BayesianNetwork

This class implements a BayesianNetwork with the type DiscreteBNType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DiscreteBN, nodes: List[str]) -> None

Initializes the DiscreteBN with the given nodes.

Parameters

nodes – List of node names.

  1. __init__(self: pybnesian.DiscreteBN, arcs: List[Tuple[str, str]]) -> None

Initializes the DiscreteBN with the given arcs (the nodes are extracted from the arcs).

Parameters

arcs – Arcs of the DiscreteBN.

  1. __init__(self: pybnesian.DiscreteBN, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the DiscreteBN with the given nodes and arcs.

Parameters
  • nodes – List of node names.

  • arcs – Arcs of the DiscreteBN.

  1. __init__(self: pybnesian.DiscreteBN, graph: pybnesian.Dag) -> None

Initializes the DiscreteBN with the given graph.

Parameters

graphDag of the Bayesian network.

class pybnesian.HomogeneousBN

Bases: BayesianNetwork

This class implements an homogeneous Bayesian network. This Bayesian network can be used with any FactorType. You can set the FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str]) -> None

Initializes the HomogeneousBN of factor_type with the given nodes.

Parameters
  • factor_typeFactorType for all the nodes.

  • nodes – List of node names.

  1. __init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, arcs: List[Tuple[str, str]]) -> None

Initializes the HomogeneousBN of factor_type with the given arcs (the nodes are extracted from the arcs).

Parameters
  1. __init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the HomogeneousBN of factor_type with the given nodes and arcs.

Parameters
  1. __init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, graph: pybnesian.Dag) -> None

Initializes the HomogeneousBN of factor_type with the given graph.

Parameters
  • factor_typeFactorType for all the nodes.

  • graphDag of the Bayesian network.

class pybnesian.HeterogeneousBN

Bases: BayesianNetwork

This class implements an heterogeneous Bayesian network. This Bayesian network accepts a different FactorType for each node. You can set the default FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str]) -> None

Initializes the HeterogeneousBN of default factor_type with the given nodes.

Parameters
  • factor_type – List of default FactorType for the Bayesian network.

  • nodes – List of node names.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given nodes and node_types.

Parameters
  • factor_type – List of default FactorType for the Bayesian network.

  • nodes – List of node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], arcs: List[Tuple[str, str]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given arcs (the nodes are extracted from the arcs).

Parameters
  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given arcs (the nodes are extracted from the arcs) and node_types.

Parameters
  • factor_type – List of default FactorType for the Bayesian network.

  • arcs – Arcs of the HeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given nodes and arcs.

Parameters
  • factor_type – List of default FactorType for the Bayesian network.

  • nodes – List of node names.

  • arcs – Arcs of the HeterogeneousBN.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given nodes, arcs and node_types.

Parameters
  • factor_type – List of default FactorType for the Bayesian network.

  • nodes – List of node names.

  • arcs – Arcs of the HeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.Dag) -> None

Initializes the HeterogeneousBN of default factor_type with the given graph.

Parameters
  • factor_type – Default FactorType for the Bayesian network.

  • graphDag of the Bayesian network.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of default factor_type with the given graph and node_types.

Parameters
  • factor_type – Default FactorType for the Bayesian network.

  • graphDag of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str]) -> None

Initializes the HeterogeneousBN of different default factor_types, with the given nodes.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of different default factor_types, with the given nodes and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], arcs: List[Tuple[str, str]]) -> None

Initializes the HeterogeneousBN of different default factor_types with the given arcs (the nodes are extracted from the arcs).

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • arcs – Arcs of the HeterogeneousBN.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of different default factor_types with the given arcs (the nodes are extracted from the arcs) and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • arcs – Arcs of the HeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the HeterogeneousBN of different default factor_types with the given nodes and arcs.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • arcs – Arcs of the HeterogeneousBN.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of different default factor_types with the given nodes, arcs and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • arcs – Arcs of the HeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.Dag) -> None

Initializes the HeterogeneousBN of different default factor_types with the given graph.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • graphDag of the Bayesian network.

  1. __init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the HeterogeneousBN of different default factor_types with the given graph and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • graphDag of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

class pybnesian.CLGNetwork

Bases: BayesianNetwork

This class implements a BayesianNetwork with the type CLGNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.CLGNetwork, nodes: List[str]) -> None

Initializes the CLGNetwork with the given nodes.

Parameters

nodes – List of node names.

  1. __init__(self: pybnesian.CLGNetwork, arcs: List[Tuple[str, str]]) -> None

Initializes the CLGNetwork with the given arcs (the nodes are extracted from the arcs).

Parameters

arcs – Arcs of the CLGNetwork.

  1. __init__(self: pybnesian.CLGNetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the CLGNetwork with the given nodes and arcs.

Parameters
  • nodes – List of node names.

  • arcs – Arcs of the CLGNetwork.

  1. __init__(self: pybnesian.CLGNetwork, graph: pybnesian.Dag) -> None

Initializes the CLGNetwork with the given graph.

Parameters

graphDag of the Bayesian network.

  1. __init__(self: pybnesian.CLGNetwork, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the CLGNetwork with the given nodes. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.CLGNetwork, arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the CLGNetwork with the given arcs (the nodes are extracted from the arcs). It specifies the node_types for the nodes.

Parameters
  • arcs – Arcs of the CLGNetwork.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.CLGNetwork, nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the CLGNetwork with the given nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • arcs – Arcs of the CLGNetwork.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.CLGNetwork, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the CLGNetwork with the given graph. It specifies the node_types for the nodes.

Parameters
  • graphDag of the Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

Conditional Bayesian Networks

class pybnesian.ConditionalBayesianNetwork

Bases: ConditionalBayesianNetworkBase

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalBayesianNetwork with a given type, nodes and interface_nodes.

Parameters
  • typeBayesianNetworkType of this conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalBayesianNetwork with a given type, nodes and interface_nodes. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalBayesianNetwork with a given type, nodes, interface_nodes and arcs.

Parameters
  • typeBayesianNetworkType of this conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the conditional Bayesian network.

  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalBayesianNetwork with a given type, nodes, interface_nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalBayesianNetwork with a given type, and graph

Parameters
  1. __init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalBayesianNetwork with a given type, and graph. It specifies the node_types for the nodes.

Parameters
  • typeBayesianNetworkType of this conditional Bayesian network.

  • graphConditionalDag of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

can_have_cpd(self: pybnesian.ConditionalBayesianNetwork, node: str) bool

Checks whether a given node name can have an associated CPD. For

Parameters

node – A node name.

Returns

True if the given node can have a CPD, False otherwise.

check_compatible_cpd(self: pybnesian.ConditionalBayesianNetwork, cpd: pybnesian.Factor) None

Checks whether the given CPD is compatible with this Bayesian network.

Parameters

cpd – A Factor.

Returns

True if cpd is compatible with this Bayesian network, False otherwise.

graph(self: pybnesian.ConditionalBayesianNetwork) pybnesian.ConditionalDag

Gets the underlying graph of the Bayesian network.

Returns

Graph of the Bayesian network.

Concrete Conditional Bayesian Networks

These classes implements ConditionalBayesianNetwork with an specific BayesianNetworkType. Thus, the constructors do not have the type parameter.

class pybnesian.ConditionalGaussianNetwork

Bases: ConditionalBayesianNetwork

This class implements a ConditionalBayesianNetwork with the type GaussianNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalGaussianNetwork, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalGaussianNetwork with the given nodes and interface_nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalGaussianNetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalGaussianNetwork with the given nodes, interface_nodes and arcs.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalGaussianNetwork.

  1. __init__(self: pybnesian.ConditionalGaussianNetwork, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalGaussianNetwork with the given graph.

Parameters

graphConditionalDag of the conditional Bayesian network.

class pybnesian.ConditionalSemiparametricBN

Bases: ConditionalBayesianNetwork

This class implements a ConditionalBayesianNetwork with the type SemiparametricBNType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalSemiparametricBN with the given nodes and interface_nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalSemiparametricBN with the given nodes, interface_nodes and arcs.

Parameters
  1. __init__(self: pybnesian.ConditionalSemiparametricBN, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalSemiparametricBN with the given graph.

Parameters

graphConditionalDag of the conditional Bayesian network.

  1. __init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalSemiparametricBN with the given nodes and interface_nodes. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalSemiparametricBN with the given nodes, interface_nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalSemiparametricBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalSemiparametricBN, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalSemiparametricBN with the given graph. It specifies the node_types for the nodes.

Parameters
  • graphConditionalDag of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

class pybnesian.ConditionalKDENetwork

Bases: ConditionalBayesianNetwork

This class implements a ConditionalBayesianNetwork with the type KDENetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalKDENetwork, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalKDENetwork with the given nodes and interface_nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalKDENetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalKDENetwork with the given nodes, interface_nodes and arcs.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalKDENetwork.

  1. __init__(self: pybnesian.ConditionalKDENetwork, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalKDENetwork with the given graph.

Parameters

graphConditionalDag of the conditional Bayesian network.

class pybnesian.ConditionalDiscreteBN

Bases: ConditionalBayesianNetwork

This class implements a ConditionalBayesianNetwork with the type DiscreteBNType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalDiscreteBN, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalDiscreteBN with the given nodes and interface_nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalDiscreteBN, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalDiscreteBN with the given nodes, interface_nodes and arcs.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalDiscreteBN.

  1. __init__(self: pybnesian.ConditionalDiscreteBN, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalDiscreteBN with the given graph.

Parameters

graphConditionalDag of the conditional Bayesian network.

class pybnesian.ConditionalHomogeneousBN

Bases: ConditionalBayesianNetwork

This class implements an homogeneous conditional Bayesian network. This conditional Bayesian network can be used with any FactorType. You can set the FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalHomogeneousBN of factor_type with the given nodes and interface_nodes.

Parameters
  • factor_typeFactorType for all the nodes.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalHomogeneousBN of factor_type with the given nodes, interface_nodes and arcs.

Parameters
  • factor_typeFactorType for all the nodes.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalHomogeneousBN.

  1. __init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalHomogeneousBN of factor_type with the given graph.

Parameters
class pybnesian.ConditionalHeterogeneousBN

Bases: ConditionalBayesianNetwork

This class implements an heterogeneous conditional Bayesian network. This conditional Bayesian network accepts a different FactorType for each node. You can set the default FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given nodes and interface_nodes.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given nodes, interface_nodes and node_types.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given nodes, interface_nodes and arcs.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalHeterogeneousBN.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given nodes, interface_nodes, arcs and node_types.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalHeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given graph.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • graphConditionalDag of the conditional Bayesian network.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of default factor_type with the given graph and node_types.

Parameters
  • factor_type – List of default FactorType for the conditional Bayesian network.

  • graphConditionalDag of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given nodes and interface_nodes.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given nodes, interface_nodes and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given nodes, interface_nodes and arcs.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalHeterogeneousBN.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given nodes, interface_nodes, arcs and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalHeterogeneousBN.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given graph.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • graphConditionalDag of the conditional Bayesian network.

  1. __init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalHeterogeneousBN of different default factor_types with the given graph and node_types.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • graphConditionalDag of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

class pybnesian.ConditionalCLGNetwork

Bases: ConditionalBayesianNetwork

This class implements a ConditionalBayesianNetwork with the type CLGNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str]) -> None

Initializes the ConditionalCLGNetwork with the given nodes and interface_nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None

Initializes the ConditionalCLGNetwork with the given nodes, interface_nodes and arcs.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalCLGNetwork.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, graph: pybnesian.ConditionalDag) -> None

Initializes the ConditionalCLGNetwork with the given graph.

Parameters

graphConditionalDag of the conditional Bayesian network.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalCLGNetwork with the given nodes and interface_nodes. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalCLGNetwork with the given nodes, interface_nodes and arcs. It specifies the node_types for the nodes.

Parameters
  • nodes – List of node names.

  • interface_nodes – List of interface node names.

  • arcs – Arcs of the ConditionalCLGNetwork.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

  1. __init__(self: pybnesian.ConditionalCLGNetwork, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None

Initializes the ConditionalCLGNetwork with the given graph. It specifies the node_types for the nodes.

Parameters
  • graphConditionalDag of the conditional Bayesian network.

  • node_types – List of node type tuples (node, FactorType) that specifies the type for each node.

Dynamic Bayesian Networks

class pybnesian.DynamicBayesianNetwork

Bases: DynamicBayesianNetworkBase

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicBayesianNetwork, type: pybnesian.BayesianNetworkType, variables: List[str], markovian_order: int) -> None

Initializes the DynamicBayesianNetwork with the given variables and markovian_order. It creates empty the static and transition Bayesian networks with the given type.

Parameters
  • typeBayesianNetworkType of the static and transition Bayesian networks.

  • variables – List of node names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicBayesianNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicBayesianNetwork with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

The static and transition networks must have the same BayesianNetworkType.

Parameters
  • variables – List of node names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

Concrete Dynamic Bayesian Networks

These classes implements DynamicBayesianNetwork with an specific BayesianNetworkType. Thus, the constructors do not have the type parameter.

class pybnesian.DynamicGaussianNetwork

Bases: DynamicBayesianNetwork

This class implements a DynamicBayesianNetwork with the type GaussianNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicGaussianNetwork, variables: List[str], markovian_order: int) -> None

Initializes the DynamicGaussianNetwork with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicGaussianNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicGaussianNetwork with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicSemiparametricBN

Bases: DynamicBayesianNetwork

This class implements a DynamicBayesianNetwork with the type SemiparametricBNType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicSemiparametricBN, variables: List[str], markovian_order: int) -> None

Initializes the DynamicSemiparametricBN with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicSemiparametricBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicSemiparametricBN with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicKDENetwork

Bases: DynamicBayesianNetwork

This class implements a DynamicBayesianNetwork with the type KDENetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicKDENetwork, variables: List[str], markovian_order: int) -> None

Initializes the DynamicKDENetwork with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicKDENetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicKDENetwork with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicDiscreteBN

Bases: DynamicBayesianNetwork

This class implements a DynamicBayesianNetwork with the type DiscreteBN.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicDiscreteBN, variables: List[str], markovian_order: int) -> None

Initializes the DynamicDiscreteBN with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicDiscreteBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicDiscreteBN with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicHomogeneousBN

Bases: DynamicBayesianNetwork

This class implements an homogeneous dynamic Bayesian network. This dynamic Bayesian network can be used with any FactorType. You can set the FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicHomogeneousBN, factor_type: pybnesian.FactorType, variables: List[str], markovian_order: int) -> None

Initializes the DynamicHomogeneousBN of factor_type with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • factor_typeFactorType for all the nodes.

  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicHomogeneousBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicHomogeneousBN with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

The type of static_bn and transition_bn must be HomogeneousBNType.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicHeterogeneousBN

Bases: DynamicBayesianNetwork

This class implements an heterogeneous dynamic Bayesian network. This dynamic Bayesian network accepts a different FactorType for each node. You can set the default FactorType in the constructor.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicHeterogeneousBN, factor_type: List[pybnesian.FactorType], variables: List[str], markovian_order: int) -> None

Initializes the DynamicHeterogeneousBN of default factor_type with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • factor_type – Default FactorType for the dynamic Bayesian network.

  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], variables: List[str], markovian_order: int) -> None

Initializes the DynamicHeterogeneousBN of different default factor_types with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • factor_types – Default FactorType for the Bayesian network for each different data type.

  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicHeterogeneousBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicHeterogeneousBN with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

The type of static_bn and transition_bn must be HeterogeneousBNType.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.

class pybnesian.DynamicCLGNetwork

Bases: DynamicBayesianNetwork

This class implements a DynamicBayesianNetwork with the type CLGNetworkType.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: pybnesian.DynamicCLGNetwork, variables: List[str], markovian_order: int) -> None

Initializes the DynamicCLGNetwork with the given variables and markovian_order. It creates empty static and transition Bayesian networks.

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  1. __init__(self: pybnesian.DynamicCLGNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None

Initializes the DynamicCLGNetwork with the given variables and markovian_order. The static and transition Bayesian networks are initialized with static_bn and transition_bn respectively.

Both static_bn and transition_bn must contain the expected nodes:

  • For the static network, it must contain the nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

  • For the transition network, it must contain the nodes [variable_name]_t_0, and the interface nodes from [variable_name]_t_1 to [variable_name]_t_[markovian_order].

Parameters
  • variables – List of variable names.

  • markovian_order – Markovian order of the dynamic Bayesian network.

  • static_bn – Static Bayesian network.

  • transition_bn – Transition Bayesian network.