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
fornode
.- 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 arcsource
->target
in the Bayesian networkmodel
.- 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 inmodel
, False otherwise.
- compatible_node_type(model: BayesianNetworkBase or ConditionalBayesianNetworkBase, node: str, node_type: pybnesian.FactorType) bool
Checks whether the
FactorType
node_type
is allowed fornode
by thisBayesianNetworkType
.- Parameters
model – BayesianNetwork model.
node – Name of the node to check.
node_type –
FactorType
fornode
.
- 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 typedatatype
. This method is only needed for non-homogeneous Bayesian networks and defines the priority of use of the differentFactorType
for the givendatatype
. If aFactorType
is blacklisted for a given node, the next element in the list is used as the defaultFactorType
. See alsoBayesianNetworkBase.set_unknown_node_types()
.- Parameters
datatype –
pyarrow.DataType
defining the type of data for a node.- Returns
List of default
FactorType
for a node given thedatatype
.
- 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 possibleFactorType
.- 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 theFactorType
type of each node is alwaysLinearGaussianCPDType
.- 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
andinterface_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
andtarget
. 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
andtarget
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
andtarget
can be flipped.An arc flip can be not allowed for multiple reasons:
It generates a cycle.
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.
- 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.
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 usingDag.conditional_graph
.If
self
is conditional, it returns a copy ofself
.
- Returns
The conditional graph transformation of
self
.
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 usingDag.conditional_graph
using the given set of nodes and interface nodes.If
self
is conditional, it returns a copy ofself
.
- 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 aFactor
type.- Parameters
node – A node name.
- Returns
The
Factor
associated tonode
- Raises
ValueError – If
node
do not have an associatedFactor
yet.
- fit(self: pybnesian.BayesianNetworkBase, df: DataFrame, construction_args: pybnesian.Arguments = Arguments) None
Fit all the unfitted
Factor
with the datadf
.- 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
andtarget
. 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
andtarget
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
andn2
.- Parameters
n1 – A node name.
n2 – A node name.
- Returns
True if there is an directed path between
n1
andn2
, 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 dtypenumpy.float64
, where the i-th value is the log-likelihod of the i-th instance ofdf
.
- 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
fornode
.- Parameters
node – A node name.
- Returns
The
FactorType
ofnode
.
- 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
andtarget
. 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 apyarrow.RecordBatch
withn
instances.If
ordered
is True, it orders the columns according to the listBayesianNetworkBase.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
fornode
.- Parameters
node – A node name.
new_type – The new
FactorType
fornode
.
- 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 theBayesianNetworkType
. If aFactorType
is blacklisted for a given node, the next element in theBayesianNetworkType.data_default_node_type()
list is used as the defaultFactorType
.- 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 ofBayesianNetworkBase.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
ofself
.
- 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 ofself
.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.If the node has a node type different from
UnknownFactorType
, it returns it.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:
pybnesian.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 onevidence
.evidence
must contain a column for each interface node. This method returns apyarrow.RecordBatch
withn
instances.If
concat
is True, it concatenatesevidence
in the result.If
ordered
is True, it orders the columns according to the listBayesianNetworkBase.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]
. Thevariable_name
is the name of each variable, andtemporal_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 wayDynamicDataFrame
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]
), wheret_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 datadf
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 dtypenumpy.float64
, where the i-th value is the log-likelihood of the i-th instance ofdf
.
- 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 apyarrow.RecordBatch
withn
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 ofDynamicBayesianNetworkBase.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
ofself
.
- 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:
pybnesian.BayesianNetworkType
This
BayesianNetworkType
represents a Gaussian network: homogeneous withLinearGaussianCPD
factors.- __init__(self: pybnesian.GaussianNetworkType) None
- class pybnesian.SemiparametricBNType
Bases:
pybnesian.BayesianNetworkType
This
BayesianNetworkType
represents a semiparametric Bayesian network: non-homogeneous withLinearGaussianCPD
andCKDE
factors for continuous data. The default isLinearGaussianCPD
. It also supports discrete data usingDiscreteFactor
.In a SemiparametricBN network, the discrete nodes can only have discrete parents.
- __init__(self: pybnesian.SemiparametricBNType) None
- class pybnesian.KDENetworkType
Bases:
pybnesian.BayesianNetworkType
This
BayesianNetworkType
represents a KDE Bayesian network: homogeneous withCKDE
factors.- __init__(self: pybnesian.KDENetworkType) None
- class pybnesian.DiscreteBNType
Bases:
pybnesian.BayesianNetworkType
This
BayesianNetworkType
represents a discrete Bayesian network: homogeneous withDiscreteFactor
factors.- __init__(self: pybnesian.DiscreteBNType) None
- class pybnesian.HomogeneousBNType
Bases:
pybnesian.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:
pybnesian.BayesianNetworkType
- __init__(*args, **kwargs)
Overloaded function.
__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.
__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 defaultFactorType
for all the data types.- Returns
True if it defines a single
FactorType
for all the data types. False if different defaultFactorType
is defined for different data types.
- class pybnesian.CLGNetworkType
Bases:
pybnesian.BayesianNetworkType
This
BayesianNetworkType
represents a conditional linear Gaussian (CLG) network: heterogeneous withLinearGaussianCPD
factors for the continuous data andDiscreteFactor
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:
pybnesian.BayesianNetworkBase
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str]) -> None
Initializes the
BayesianNetwork
with a giventype
andnodes
.- Parameters
type –
BayesianNetworkType
of this Bayesian network.nodes – List of node names.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
BayesianNetwork
with a giventype
andnodes
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
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.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, arcs: List[Tuple[str, str]]) -> None
Initializes the
BayesianNetwork
with a giventype
andarcs
(the nodes are extracted from the arcs).- Parameters
type –
BayesianNetworkType
of this Bayesian network.arcs – Arcs of the Bayesian network.
__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 giventype
andarcs
(the nodes are extracted from the arcs). It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
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.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
BayesianNetwork
with a giventype
,nodes
andarcs
.- Parameters
type –
BayesianNetworkType
of this Bayesian network.nodes – List of node names.
arcs – Arcs of the Bayesian network.
__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 giventype
,nodes
andarcs
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
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.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.Dag) -> None
Initializes the
BayesianNetwork
with a giventype
, andgraph
- Parameters
type –
BayesianNetworkType
of this Bayesian network.graph –
Dag
of the Bayesian network.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
BayesianNetwork
with a giventype
, andgraph
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
of this Bayesian network.graph –
Dag
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:
pybnesian.BayesianNetwork
This class implements a
BayesianNetwork
with the typeGaussianNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.GaussianNetwork, nodes: List[str]) -> None
Initializes the
GaussianNetwork
with the givennodes
.- Parameters
nodes – List of node names.
__init__(self: pybnesian.GaussianNetwork, arcs: List[Tuple[str, str]]) -> None
Initializes the
GaussianNetwork
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
arcs – Arcs of the
GaussianNetwork
.
__init__(self: pybnesian.GaussianNetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
GaussianNetwork
with the givennodes
andarcs
.- Parameters
nodes – List of node names.
arcs – Arcs of the
GaussianNetwork
.
__init__(self: pybnesian.GaussianNetwork, graph: pybnesian.Dag) -> None
Initializes the
GaussianNetwork
with the givengraph
.- Parameters
graph –
Dag
of the Bayesian network.
- class pybnesian.SemiparametricBN
Bases:
pybnesian.BayesianNetwork
This class implements a
BayesianNetwork
with the typeSemiparametricBNType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.SemiparametricBN, nodes: List[str]) -> None
Initializes the
SemiparametricBN
with the givennodes
.- Parameters
nodes – List of node names.
__init__(self: pybnesian.SemiparametricBN, arcs: List[Tuple[str, str]]) -> None
Initializes the
SemiparametricBN
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
arcs – Arcs of the
SemiparametricBN
.
__init__(self: pybnesian.SemiparametricBN, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
SemiparametricBN
with the givennodes
andarcs
.- Parameters
nodes – List of node names.
arcs – Arcs of the
SemiparametricBN
.
__init__(self: pybnesian.SemiparametricBN, graph: pybnesian.Dag) -> None
Initializes the
SemiparametricBN
with the givengraph
.- Parameters
graph –
Dag
of the Bayesian network.
__init__(self: pybnesian.SemiparametricBN, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
SemiparametricBN
with the givennodes
. It specifies thenode_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.
__init__(self: pybnesian.SemiparametricBN, arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
SemiparametricBN
with the givenarcs
(the nodes are extracted from the arcs). It specifies thenode_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.
__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 givennodes
andarcs
. It specifies thenode_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.
__init__(self: pybnesian.SemiparametricBN, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
SemiparametricBN
with the givengraph
. It specifies thenode_types
for the nodes.- Parameters
graph –
Dag
of the Bayesian network.node_types – List of node type tuples (
node
,FactorType
) that specifies the type for each node.
- class pybnesian.KDENetwork
Bases:
pybnesian.BayesianNetwork
This class implements a
BayesianNetwork
with the typeKDENetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.KDENetwork, nodes: List[str]) -> None
Initializes the
KDENetwork
with the givennodes
.- Parameters
nodes – List of node names.
__init__(self: pybnesian.KDENetwork, arcs: List[Tuple[str, str]]) -> None
Initializes the
KDENetwork
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
arcs – Arcs of the
KDENetwork
.
__init__(self: pybnesian.KDENetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
KDENetwork
with the givennodes
andarcs
.- Parameters
nodes – List of node names.
arcs – Arcs of the
KDENetwork
.
__init__(self: pybnesian.KDENetwork, graph: pybnesian.Dag) -> None
Initializes the
KDENetwork
with the givengraph
.- Parameters
graph –
Dag
of the Bayesian network.
- class pybnesian.DiscreteBN
Bases:
pybnesian.BayesianNetwork
This class implements a
BayesianNetwork
with the typeDiscreteBNType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DiscreteBN, nodes: List[str]) -> None
Initializes the
DiscreteBN
with the givennodes
.- Parameters
nodes – List of node names.
__init__(self: pybnesian.DiscreteBN, arcs: List[Tuple[str, str]]) -> None
Initializes the
DiscreteBN
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
arcs – Arcs of the
DiscreteBN
.
__init__(self: pybnesian.DiscreteBN, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
DiscreteBN
with the givennodes
andarcs
.- Parameters
nodes – List of node names.
arcs – Arcs of the
DiscreteBN
.
__init__(self: pybnesian.DiscreteBN, graph: pybnesian.Dag) -> None
Initializes the
DiscreteBN
with the givengraph
.- Parameters
graph –
Dag
of the Bayesian network.
- class pybnesian.HomogeneousBN
Bases:
pybnesian.BayesianNetwork
This class implements an homogeneous Bayesian network. This Bayesian network can be used with any
FactorType
. You can set theFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str]) -> None
Initializes the
HomogeneousBN
offactor_type
with the givennodes
.- Parameters
factor_type –
FactorType
for all the nodes.nodes – List of node names.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, arcs: List[Tuple[str, str]]) -> None
Initializes the
HomogeneousBN
offactor_type
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
factor_type –
FactorType
for all the nodes.arcs – Arcs of the
HomogeneousBN
.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
HomogeneousBN
offactor_type
with the givennodes
andarcs
.- Parameters
factor_type –
FactorType
for all the nodes.nodes – List of node names.
arcs – Arcs of the
HomogeneousBN
.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, graph: pybnesian.Dag) -> None
Initializes the
HomogeneousBN
offactor_type
with the givengraph
.- Parameters
factor_type –
FactorType
for all the nodes.graph –
Dag
of the Bayesian network.
- class pybnesian.HeterogeneousBN
Bases:
pybnesian.BayesianNetwork
This class implements an heterogeneous Bayesian network. This Bayesian network accepts a different
FactorType
for each node. You can set the defaultFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str]) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givennodes
.- Parameters
factor_type – List of default
FactorType
for the Bayesian network.nodes – List of node names.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givennodes
andnode_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.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], arcs: List[Tuple[str, str]]) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
factor_type – List of default
FactorType
for the Bayesian network.arcs – Arcs of the
HeterogeneousBN
.
__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 defaultfactor_type
with the givenarcs
(the nodes are extracted from the arcs) andnode_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.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givennodes
andarcs
.- Parameters
factor_type – List of default
FactorType
for the Bayesian network.nodes – List of node names.
arcs – Arcs of the
HeterogeneousBN
.
__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 defaultfactor_type
with the givennodes
,arcs
andnode_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.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.Dag) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givengraph
.- Parameters
factor_type – Default
FactorType
for the Bayesian network.graph –
Dag
of the Bayesian network.
__init__(self: pybnesian.HeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
HeterogeneousBN
of defaultfactor_type
with the givengraph
andnode_types
.- Parameters
factor_type – Default
FactorType
for the Bayesian network.graph –
Dag
of the Bayesian network.node_types – List of node type tuples (
node
,FactorType
) that specifies the type for each node.
__init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], nodes: List[str]) -> None
Initializes the
HeterogeneousBN
of different defaultfactor_types
, with the givennodes
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.nodes – List of node names.
__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 defaultfactor_types
, with the givennodes
andnode_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.
__init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], arcs: List[Tuple[str, str]]) -> None
Initializes the
HeterogeneousBN
of different defaultfactor_types
with the givenarcs
(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
.
__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 defaultfactor_types
with the givenarcs
(the nodes are extracted from the arcs) andnode_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.
__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 defaultfactor_types
with the givennodes
andarcs
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.nodes – List of node names.
arcs – Arcs of the
HeterogeneousBN
.
__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 defaultfactor_types
with the givennodes
,arcs
andnode_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.
__init__(self: pybnesian.HeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.Dag) -> None
Initializes the
HeterogeneousBN
of different defaultfactor_types
with the givengraph
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.graph –
Dag
of the Bayesian network.
__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 defaultfactor_types
with the givengraph
andnode_types
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.graph –
Dag
of the Bayesian network.node_types – List of node type tuples (
node
,FactorType
) that specifies the type for each node.
- class pybnesian.CLGNetwork
Bases:
pybnesian.BayesianNetwork
This class implements a
BayesianNetwork
with the typeCLGNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.CLGNetwork, nodes: List[str]) -> None
Initializes the
CLGNetwork
with the givennodes
.- Parameters
nodes – List of node names.
__init__(self: pybnesian.CLGNetwork, arcs: List[Tuple[str, str]]) -> None
Initializes the
CLGNetwork
with the givenarcs
(the nodes are extracted from the arcs).- Parameters
arcs – Arcs of the
CLGNetwork
.
__init__(self: pybnesian.CLGNetwork, nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
CLGNetwork
with the givennodes
andarcs
.- Parameters
nodes – List of node names.
arcs – Arcs of the
CLGNetwork
.
__init__(self: pybnesian.CLGNetwork, graph: pybnesian.Dag) -> None
Initializes the
CLGNetwork
with the givengraph
.- Parameters
graph –
Dag
of the Bayesian network.
__init__(self: pybnesian.CLGNetwork, nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
CLGNetwork
with the givennodes
. It specifies thenode_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.
__init__(self: pybnesian.CLGNetwork, arcs: List[Tuple[str, str]], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
CLGNetwork
with the givenarcs
(the nodes are extracted from the arcs). It specifies thenode_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.
__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 givennodes
andarcs
. It specifies thenode_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.
__init__(self: pybnesian.CLGNetwork, graph: pybnesian.Dag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
CLGNetwork
with the givengraph
. It specifies thenode_types
for the nodes.- Parameters
graph –
Dag
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:
pybnesian.ConditionalBayesianNetworkBase
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalBayesianNetwork
with a giventype
,nodes
andinterface_nodes
.- Parameters
type –
BayesianNetworkType
of this conditional Bayesian network.nodes – List of node names.
interface_nodes – List of interface node names.
__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 giventype
,nodes
andinterface_nodes
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
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.
__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 giventype
,nodes
,interface_nodes
andarcs
.- Parameters
type –
BayesianNetworkType
of this conditional Bayesian network.nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the conditional Bayesian network.
__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 giventype
,nodes
,interface_nodes
andarcs
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
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.
__init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalBayesianNetwork
with a giventype
, andgraph
- Parameters
type –
BayesianNetworkType
of this conditional Bayesian network.graph –
ConditionalDag
of the conditional Bayesian network.
__init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalBayesianNetwork
with a giventype
, andgraph
. It specifies thenode_types
for the nodes.- Parameters
type –
BayesianNetworkType
of this conditional Bayesian network.graph –
ConditionalDag
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:
pybnesian.ConditionalBayesianNetwork
This class implements a
ConditionalBayesianNetwork
with the typeGaussianNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalGaussianNetwork, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalGaussianNetwork
with the givennodes
andinterface_nodes
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalGaussianNetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalGaussianNetwork
with the givennodes
,interface_nodes
andarcs
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalGaussianNetwork
.
__init__(self: pybnesian.ConditionalGaussianNetwork, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalGaussianNetwork
with the givengraph
.- Parameters
graph –
ConditionalDag
of the conditional Bayesian network.
- class pybnesian.ConditionalSemiparametricBN
Bases:
pybnesian.ConditionalBayesianNetwork
This class implements a
ConditionalBayesianNetwork
with the typeSemiparametricBNType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalSemiparametricBN
with the givennodes
andinterface_nodes
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalSemiparametricBN
with the givennodes
,interface_nodes
andarcs
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalSemiparametricBN
.
__init__(self: pybnesian.ConditionalSemiparametricBN, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalSemiparametricBN
with the givengraph
.- Parameters
graph –
ConditionalDag
of the conditional Bayesian network.
__init__(self: pybnesian.ConditionalSemiparametricBN, nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalSemiparametricBN
with the givennodes
andinterface_nodes
. It specifies thenode_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.
__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 givennodes
,interface_nodes
andarcs
. It specifies thenode_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.
__init__(self: pybnesian.ConditionalSemiparametricBN, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalSemiparametricBN
with the givengraph
. It specifies thenode_types
for the nodes.- Parameters
graph –
ConditionalDag
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:
pybnesian.ConditionalBayesianNetwork
This class implements a
ConditionalBayesianNetwork
with the typeKDENetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalKDENetwork, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalKDENetwork
with the givennodes
andinterface_nodes
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalKDENetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalKDENetwork
with the givennodes
,interface_nodes
andarcs
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalKDENetwork
.
__init__(self: pybnesian.ConditionalKDENetwork, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalKDENetwork
with the givengraph
.- Parameters
graph –
ConditionalDag
of the conditional Bayesian network.
- class pybnesian.ConditionalDiscreteBN
Bases:
pybnesian.ConditionalBayesianNetwork
This class implements a
ConditionalBayesianNetwork
with the typeDiscreteBNType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalDiscreteBN, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalDiscreteBN
with the givennodes
andinterface_nodes
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalDiscreteBN, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalDiscreteBN
with the givennodes
,interface_nodes
andarcs
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalDiscreteBN
.
__init__(self: pybnesian.ConditionalDiscreteBN, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalDiscreteBN
with the givengraph
.- Parameters
graph –
ConditionalDag
of the conditional Bayesian network.
- class pybnesian.ConditionalHomogeneousBN
Bases:
pybnesian.ConditionalBayesianNetwork
This class implements an homogeneous conditional Bayesian network. This conditional Bayesian network can be used with any
FactorType
. You can set theFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalHomogeneousBN
offactor_type
with the givennodes
andinterface_nodes
.- Parameters
factor_type –
FactorType
for all the nodes.nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalHomogeneousBN
offactor_type
with the givennodes
,interface_nodes
andarcs
.- Parameters
factor_type –
FactorType
for all the nodes.nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalHomogeneousBN
.
__init__(self: pybnesian.ConditionalHomogeneousBN, factor_type: pybnesian.FactorType, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalHomogeneousBN
offactor_type
with the givengraph
.- Parameters
factor_type –
FactorType
for all the nodes.graph –
ConditionalDag
of the conditional Bayesian network.
- class pybnesian.ConditionalHeterogeneousBN
Bases:
pybnesian.ConditionalBayesianNetwork
This class implements an heterogeneous conditional Bayesian network. This conditional Bayesian network accepts a different
FactorType
for each node. You can set the defaultFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalHeterogeneousBN
of defaultfactor_type
with the givennodes
andinterface_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.
__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 defaultfactor_type
with the givennodes
,interface_nodes
andnode_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.
__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 defaultfactor_type
with the givennodes
,interface_nodes
andarcs
.- 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
.
__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 defaultfactor_type
with the givennodes
,interface_nodes
,arcs
andnode_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.
__init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalHeterogeneousBN
of defaultfactor_type
with the givengraph
.- Parameters
factor_type – List of default
FactorType
for the conditional Bayesian network.graph –
ConditionalDag
of the conditional Bayesian network.
__init__(self: pybnesian.ConditionalHeterogeneousBN, factor_type: List[pybnesian.FactorType], graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalHeterogeneousBN
of defaultfactor_type
with the givengraph
andnode_types
.- Parameters
factor_type – List of default
FactorType
for the conditional Bayesian network.graph –
ConditionalDag
of the conditional Bayesian network.node_types – List of node type tuples (
node
,FactorType
) that specifies the type for each node.
__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 defaultfactor_types
with the givennodes
andinterface_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.
__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 defaultfactor_types
with the givennodes
,interface_nodes
andnode_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.
__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 defaultfactor_types
with the givennodes
,interface_nodes
andarcs
.- 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
.
__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 defaultfactor_types
with the givennodes
,interface_nodes
,arcs
andnode_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.
__init__(self: pybnesian.ConditionalHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalHeterogeneousBN
of different defaultfactor_types
with the givengraph
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.graph –
ConditionalDag
of the conditional Bayesian network.
__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 defaultfactor_types
with the givengraph
andnode_types
.- Parameters
factor_types – Default
FactorType
for the Bayesian network for each different data type.graph –
ConditionalDag
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:
pybnesian.ConditionalBayesianNetwork
This class implements a
ConditionalBayesianNetwork
with the typeCLGNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str]) -> None
Initializes the
ConditionalCLGNetwork
with the givennodes
andinterface_nodes
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
__init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str], arcs: List[Tuple[str, str]]) -> None
Initializes the
ConditionalCLGNetwork
with the givennodes
,interface_nodes
andarcs
.- Parameters
nodes – List of node names.
interface_nodes – List of interface node names.
arcs – Arcs of the
ConditionalCLGNetwork
.
__init__(self: pybnesian.ConditionalCLGNetwork, graph: pybnesian.ConditionalDag) -> None
Initializes the
ConditionalCLGNetwork
with the givengraph
.- Parameters
graph –
ConditionalDag
of the conditional Bayesian network.
__init__(self: pybnesian.ConditionalCLGNetwork, nodes: List[str], interface_nodes: List[str], node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalCLGNetwork
with the givennodes
andinterface_nodes
. It specifies thenode_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.
__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 givennodes
,interface_nodes
andarcs
. It specifies thenode_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.
__init__(self: pybnesian.ConditionalCLGNetwork, graph: pybnesian.ConditionalDag, node_types: List[Tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalCLGNetwork
with the givengraph
. It specifies thenode_types
for the nodes.- Parameters
graph –
ConditionalDag
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:
pybnesian.DynamicBayesianNetworkBase
- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicBayesianNetwork, type: pybnesian.BayesianNetworkType, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicBayesianNetwork
with the givenvariables
andmarkovian_order
. It creates empty the static and transition Bayesian networks with the giventype
.- Parameters
type –
BayesianNetworkType
of the static and transition Bayesian networks.variables – List of node names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicBayesianNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicBayesianNetwork
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition
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:
pybnesian.DynamicBayesianNetwork
This class implements a
DynamicBayesianNetwork
with the typeGaussianNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicGaussianNetwork, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicGaussianNetwork
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicGaussianNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicGaussianNetwork
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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:
pybnesian.DynamicBayesianNetwork
This class implements a
DynamicBayesianNetwork
with the typeSemiparametricBNType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicSemiparametricBN, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicSemiparametricBN
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicSemiparametricBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicSemiparametricBN
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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:
pybnesian.DynamicBayesianNetwork
This class implements a
DynamicBayesianNetwork
with the typeKDENetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicKDENetwork, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicKDENetwork
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicKDENetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicKDENetwork
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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:
pybnesian.DynamicBayesianNetwork
This class implements a
DynamicBayesianNetwork
with the typeDiscreteBN
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicDiscreteBN, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicDiscreteBN
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicDiscreteBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicDiscreteBN
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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:
pybnesian.DynamicBayesianNetwork
This class implements an homogeneous dynamic Bayesian network. This dynamic Bayesian network can be used with any
FactorType
. You can set theFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicHomogeneousBN, factor_type: pybnesian.FactorType, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicHomogeneousBN
offactor_type
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
factor_type –
FactorType
for all the nodes.variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicHomogeneousBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicHomogeneousBN
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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
andtransition_bn
must beHomogeneousBNType
.- 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:
pybnesian.DynamicBayesianNetwork
This class implements an heterogeneous dynamic Bayesian network. This dynamic Bayesian network accepts a different
FactorType
for each node. You can set the defaultFactorType
in the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicHeterogeneousBN, factor_type: List[pybnesian.FactorType], variables: List[str], markovian_order: int) -> None
Initializes the
DynamicHeterogeneousBN
of defaultfactor_type
with the givenvariables
andmarkovian_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.
__init__(self: pybnesian.DynamicHeterogeneousBN, factor_types: Dict[pyarrow.DataType, List[pybnesian.FactorType]], variables: List[str], markovian_order: int) -> None
Initializes the
DynamicHeterogeneousBN
of different defaultfactor_types
with the givenvariables
andmarkovian_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.
__init__(self: pybnesian.DynamicHeterogeneousBN, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicHeterogeneousBN
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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
andtransition_bn
must beHeterogeneousBNType
.- 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:
pybnesian.DynamicBayesianNetwork
This class implements a
DynamicBayesianNetwork
with the typeCLGNetworkType
.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicCLGNetwork, variables: List[str], markovian_order: int) -> None
Initializes the
DynamicCLGNetwork
with the givenvariables
andmarkovian_order
. It creates empty static and transition Bayesian networks.- Parameters
variables – List of variable names.
markovian_order – Markovian order of the dynamic Bayesian network.
__init__(self: pybnesian.DynamicCLGNetwork, variables: List[str], markovian_order: int, static_bn: pybnesian.BayesianNetworkBase, transition_bn: pybnesian.ConditionalBayesianNetworkBase) -> None
Initializes the
DynamicCLGNetwork
with the givenvariables
andmarkovian_order
. The static and transition Bayesian networks are initialized withstatic_bn
andtransition_bn
respectively.Both
static_bn
andtransition_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.