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
BayesianNetworkthat 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
FactorTypefornode.- 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
BayesianNetworkTypeallows an arcsource->targetin 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->targetis allowed inmodel, False otherwise.
- compatible_node_type(model: BayesianNetworkBase or ConditionalBayesianNetworkBase, node: str, node_type: pybnesian.FactorType) bool
Checks whether the
FactorTypenode_typeis allowed fornodeby thisBayesianNetworkType.- Parameters:
model – BayesianNetwork model.
node – Name of the node to check.
node_type –
FactorTypefornode.
- Returns:
True if the current
FactorTypeis allowed, False otherwise.
- data_default_node_type(self: pybnesian.BayesianNetworkType, datatype: pyarrow.DataType) list[pybnesian.FactorType]
Returns a list of default
FactorTypefor 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 differentFactorTypefor the givendatatype. If aFactorTypeis 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.DataTypedefining the type of data for a node.- Returns:
List of default
FactorTypefor a node given thedatatype.
- default_node_type(self: pybnesian.BayesianNetworkType) pybnesian.FactorType
Returns the default
FactorTypeof each node in this Bayesian network type. This method is only needed for homogeneous Bayesian networks and returns the unique possibleFactorType.- Returns:
default
FactorTypefor the nodes.
- is_homogeneous(self: pybnesian.BayesianNetworkType) bool
Checks whether the Bayesian network is homogeneous.
A Bayesian network is homogeneous if the
FactorTypeof all the nodes are forced to be the same: for example, a Gaussian network is homogeneous because theFactorTypetype 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
nodesandinterface_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
sourceandtarget. 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
sourceandtargetcan 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
sourceandtargetcan 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
selfis not conditional, it returns a conditional version of the Bayesian network where the graph is transformed usingDag.conditional_graph.If
selfis 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
selfis not conditional, it returns a conditional version of the Bayesian network where the graph is transformed usingDag.conditional_graphusing the given set of nodes and interface nodes.If
selfis 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 aFactortype.- Parameters:
node – A node name.
- Returns:
The
Factorassociated tonode- Raises:
ValueError – If
nodedo not have an associatedFactoryet.
- fit(self: pybnesian.BayesianNetworkBase, df: DataFrame, construction_args: pybnesian.Arguments = Arguments) None
Fit all the unfitted
Factorwith 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
sourceandtarget. 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
sourceandtargetexists.- 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
n1andn2.- Parameters:
n1 – A node name.
n2 – A node name.
- Returns:
True if there is an directed path between
n1andn2, 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.ndarrayvector 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
FactorTypefornode.- Parameters:
node – A node name.
- Returns:
The
FactorTypeofnode.
- node_types(self: pybnesian.BayesianNetworkBase) dict[str, pybnesian.FactorType]
Gets the
FactorTypefor all the nodes.- Returns:
The corresponding
FactorTypefor 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
sourceandtarget. 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: int | None = None, ordered: bool = False) DataFrame
Samples
nvalues from this BayesianNetwork. This method returns apyarrow.RecordBatchwithninstances.If
orderedis 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
ninstances 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_cpdis 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_typeFactorTypefornode.- Parameters:
node – A node name.
new_type – The new
FactorTypefornode.
- 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 aFactorTypeis 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
BayesianNetworkTypeofself.
- unconditional_bn(self: pybnesian.BayesianNetworkBase) pybnesian.BayesianNetworkBase
Returns the unconditional Bayesian network version of this Bayesian network.
If
selfis not conditional, it returns a copy ofself.If
selfis 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
FactorTypefor 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
FactorTypefor each node.
- class pybnesian.ConditionalBayesianNetworkBase
Bases:
BayesianNetworkBaseThis class defines an interface of base operations for the conditional Bayesian networks.
It includes some methods of the
ConditionalDagto 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
nodeis an interface node.- Parameters:
node – A node name.
- Returns:
True if
nodeis 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: int | None = None, concat_evidence: bool = False, ordered: bool = False) DataFrame
Samples
nvalues from this conditional BayesianNetwork conditioned onevidence.evidencemust contain a column for each interface node. This method returns apyarrow.RecordBatchwithninstances.If
concatis True, it concatenatesevidencein the result.If
orderedis 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
ninstances 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
ninstances 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_nameis the name of each variable, andtemporal_indexis 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 wayDynamicDataFramegenerates the columns.The dynamic Bayesian is composed of two Bayesian networks:
a static Bayesian network that defines the probability distribution of the first
markovian_orderinstances. 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_orderinstances. 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
Factorwith the datadfin 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.ndarrayvector 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: int | None = None) DataFrame
Samples
nvalues from this dynamic Bayesian network. This method returns apyarrow.RecordBatchwithninstances.- 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_cpdis 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
BayesianNetworkTypeofself.
- 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:
BayesianNetworkTypeThis
BayesianNetworkTyperepresents a Gaussian network: homogeneous withLinearGaussianCPDfactors.- __init__(self: pybnesian.GaussianNetworkType) None
- class pybnesian.SemiparametricBNType
Bases:
BayesianNetworkTypeThis
BayesianNetworkTyperepresents a semiparametric Bayesian network: non-homogeneous withLinearGaussianCPDandCKDEfactors 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:
BayesianNetworkTypeThis
BayesianNetworkTyperepresents a KDE Bayesian network: homogeneous withCKDEfactors.- __init__(self: pybnesian.KDENetworkType) None
- class pybnesian.DiscreteBNType
Bases:
BayesianNetworkTypeThis
BayesianNetworkTyperepresents a discrete Bayesian network: homogeneous withDiscreteFactorfactors.- __init__(self: pybnesian.DiscreteBNType) None
- class pybnesian.HomogeneousBNType
Bases:
BayesianNetworkType- __init__(self: pybnesian.HomogeneousBNType, default_factor_type: pybnesian.FactorType) None
Initializes an
HomogeneousBNTypewith 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.
__init__(self: pybnesian.HeterogeneousBNType, default_factor_type: list[pybnesian.FactorType]) -> None
Initializes an
HeterogeneousBNTypewith 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
HeterogeneousBNTypewith 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
FactorTypefor each data type.- Returns:
dict of default
FactorTypefor each data type.
- single_default(self: pybnesian.HeterogeneousBNType) bool
Checks whether the
HeterogeneousBNTypedefines only a defaultFactorTypefor all the data types.- Returns:
True if it defines a single
FactorTypefor all the data types. False if different defaultFactorTypeis defined for different data types.
- class pybnesian.CLGNetworkType
Bases:
BayesianNetworkTypeThis
BayesianNetworkTyperepresents a conditional linear Gaussian (CLG) network: heterogeneous withLinearGaussianCPDfactors for the continuous data andDiscreteFactorfor 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.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: list[str]) -> None
Initializes the
BayesianNetworkwith a giventypeandnodes.- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventypeandnodes. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventypeandarcs(the nodes are extracted from the arcs).- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventypeandarcs(the nodes are extracted from the arcs). It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventype,nodesandarcs.- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventype,nodesandarcs. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof 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
BayesianNetworkwith a giventype, andgraph- Parameters:
type –
BayesianNetworkTypeof this Bayesian network.graph –
Dagof the Bayesian network.
__init__(self: pybnesian.BayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.Dag, node_types: list[tuple[str, pybnesian.FactorType]]) -> None
Initializes the
BayesianNetworkwith a giventype, andgraph. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof this Bayesian network.graph –
Dagof 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
cpdis 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:
BayesianNetworkThis class implements a
BayesianNetworkwith the typeGaussianNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.GaussianNetwork, nodes: list[str]) -> None
Initializes the
GaussianNetworkwith the givennodes.- Parameters:
nodes – List of node names.
__init__(self: pybnesian.GaussianNetwork, arcs: list[tuple[str, str]]) -> None
Initializes the
GaussianNetworkwith 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
GaussianNetworkwith the givennodesandarcs.- Parameters:
nodes – List of node names.
arcs – Arcs of the
GaussianNetwork.
__init__(self: pybnesian.GaussianNetwork, graph: pybnesian.Dag) -> None
Initializes the
GaussianNetworkwith the givengraph.- Parameters:
graph –
Dagof the Bayesian network.
- class pybnesian.SemiparametricBN
Bases:
BayesianNetworkThis class implements a
BayesianNetworkwith the typeSemiparametricBNType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.SemiparametricBN, nodes: list[str]) -> None
Initializes the
SemiparametricBNwith the givennodes.- Parameters:
nodes – List of node names.
__init__(self: pybnesian.SemiparametricBN, arcs: list[tuple[str, str]]) -> None
Initializes the
SemiparametricBNwith 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
SemiparametricBNwith the givennodesandarcs.- Parameters:
nodes – List of node names.
arcs – Arcs of the
SemiparametricBN.
__init__(self: pybnesian.SemiparametricBN, graph: pybnesian.Dag) -> None
Initializes the
SemiparametricBNwith the givengraph.- Parameters:
graph –
Dagof the Bayesian network.
__init__(self: pybnesian.SemiparametricBN, nodes: list[str], node_types: list[tuple[str, pybnesian.FactorType]]) -> None
Initializes the
SemiparametricBNwith the givennodes. It specifies thenode_typesfor 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
SemiparametricBNwith the givenarcs(the nodes are extracted from the arcs). It specifies thenode_typesfor 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
SemiparametricBNwith the givennodesandarcs. It specifies thenode_typesfor 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
SemiparametricBNwith the givengraph. It specifies thenode_typesfor the nodes.- Parameters:
graph –
Dagof the Bayesian network.node_types – List of node type tuples (
node,FactorType) that specifies the type for each node.
- class pybnesian.KDENetwork
Bases:
BayesianNetworkThis class implements a
BayesianNetworkwith the typeKDENetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.KDENetwork, nodes: list[str]) -> None
Initializes the
KDENetworkwith the givennodes.- Parameters:
nodes – List of node names.
__init__(self: pybnesian.KDENetwork, arcs: list[tuple[str, str]]) -> None
Initializes the
KDENetworkwith 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
KDENetworkwith the givennodesandarcs.- Parameters:
nodes – List of node names.
arcs – Arcs of the
KDENetwork.
__init__(self: pybnesian.KDENetwork, graph: pybnesian.Dag) -> None
Initializes the
KDENetworkwith the givengraph.- Parameters:
graph –
Dagof the Bayesian network.
- class pybnesian.DiscreteBN
Bases:
BayesianNetworkThis class implements a
BayesianNetworkwith the typeDiscreteBNType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DiscreteBN, nodes: list[str]) -> None
Initializes the
DiscreteBNwith the givennodes.- Parameters:
nodes – List of node names.
__init__(self: pybnesian.DiscreteBN, arcs: list[tuple[str, str]]) -> None
Initializes the
DiscreteBNwith 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
DiscreteBNwith the givennodesandarcs.- Parameters:
nodes – List of node names.
arcs – Arcs of the
DiscreteBN.
__init__(self: pybnesian.DiscreteBN, graph: pybnesian.Dag) -> None
Initializes the
DiscreteBNwith the givengraph.- Parameters:
graph –
Dagof the Bayesian network.
- class pybnesian.HomogeneousBN
Bases:
BayesianNetworkThis class implements an homogeneous Bayesian network. This Bayesian network can be used with any
FactorType. You can set theFactorTypein the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, nodes: list[str]) -> None
Initializes the
HomogeneousBNoffactor_typewith the givennodes.- Parameters:
factor_type –
FactorTypefor all the nodes.nodes – List of node names.
__init__(self: pybnesian.HomogeneousBN, factor_type: pybnesian.FactorType, arcs: list[tuple[str, str]]) -> None
Initializes the
HomogeneousBNoffactor_typewith the givenarcs(the nodes are extracted from the arcs).- Parameters:
factor_type –
FactorTypefor 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
HomogeneousBNoffactor_typewith the givennodesandarcs.- Parameters:
factor_type –
FactorTypefor 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
HomogeneousBNoffactor_typewith the givengraph.- Parameters:
factor_type –
FactorTypefor all the nodes.graph –
Dagof the Bayesian network.
- class pybnesian.HeterogeneousBN
Bases:
BayesianNetworkThis class implements an heterogeneous Bayesian network. This Bayesian network accepts a different
FactorTypefor each node. You can set the defaultFactorTypein the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.HeterogeneousBN, factor_type: list[pybnesian.FactorType], nodes: list[str]) -> None
Initializes the
HeterogeneousBNof defaultfactor_typewith the givennodes.- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givennodesandnode_types.- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givenarcs(the nodes are extracted from the arcs).- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givenarcs(the nodes are extracted from the arcs) andnode_types.- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givennodesandarcs.- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givennodes,arcsandnode_types.- Parameters:
factor_type – List of default
FactorTypefor 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
HeterogeneousBNof defaultfactor_typewith the givengraph.- Parameters:
factor_type – Default
FactorTypefor the Bayesian network.graph –
Dagof 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
HeterogeneousBNof defaultfactor_typewith the givengraphandnode_types.- Parameters:
factor_type – Default
FactorTypefor the Bayesian network.graph –
Dagof 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
HeterogeneousBNof different defaultfactor_types, with the givennodes.- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_types, with the givennodesandnode_types.- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_typeswith the givenarcs(the nodes are extracted from the arcs).- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_typeswith the givenarcs(the nodes are extracted from the arcs) andnode_types.- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_typeswith the givennodesandarcs.- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_typeswith the givennodes,arcsandnode_types.- Parameters:
factor_types – Default
FactorTypefor 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
HeterogeneousBNof different defaultfactor_typeswith the givengraph.- Parameters:
factor_types – Default
FactorTypefor the Bayesian network for each different data type.graph –
Dagof 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
HeterogeneousBNof different defaultfactor_typeswith the givengraphandnode_types.- Parameters:
factor_types – Default
FactorTypefor the Bayesian network for each different data type.graph –
Dagof the Bayesian network.node_types – List of node type tuples (
node,FactorType) that specifies the type for each node.
- class pybnesian.CLGNetwork
Bases:
BayesianNetworkThis class implements a
BayesianNetworkwith the typeCLGNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.CLGNetwork, nodes: list[str]) -> None
Initializes the
CLGNetworkwith the givennodes.- Parameters:
nodes – List of node names.
__init__(self: pybnesian.CLGNetwork, arcs: list[tuple[str, str]]) -> None
Initializes the
CLGNetworkwith 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
CLGNetworkwith the givennodesandarcs.- Parameters:
nodes – List of node names.
arcs – Arcs of the
CLGNetwork.
__init__(self: pybnesian.CLGNetwork, graph: pybnesian.Dag) -> None
Initializes the
CLGNetworkwith the givengraph.- Parameters:
graph –
Dagof the Bayesian network.
__init__(self: pybnesian.CLGNetwork, nodes: list[str], node_types: list[tuple[str, pybnesian.FactorType]]) -> None
Initializes the
CLGNetworkwith the givennodes. It specifies thenode_typesfor 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
CLGNetworkwith the givenarcs(the nodes are extracted from the arcs). It specifies thenode_typesfor 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
CLGNetworkwith the givennodesandarcs. It specifies thenode_typesfor 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
CLGNetworkwith the givengraph. It specifies thenode_typesfor the nodes.- Parameters:
graph –
Dagof 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.
__init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalBayesianNetworkwith a giventype,nodesandinterface_nodes.- Parameters:
type –
BayesianNetworkTypeof 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
ConditionalBayesianNetworkwith a giventype,nodesandinterface_nodes. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof 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
ConditionalBayesianNetworkwith a giventype,nodes,interface_nodesandarcs.- Parameters:
type –
BayesianNetworkTypeof 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
ConditionalBayesianNetworkwith a giventype,nodes,interface_nodesandarcs. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof 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
ConditionalBayesianNetworkwith a giventype, andgraph- Parameters:
type –
BayesianNetworkTypeof this conditional Bayesian network.graph –
ConditionalDagof the conditional Bayesian network.
__init__(self: pybnesian.ConditionalBayesianNetwork, type: pybnesian.BayesianNetworkType, graph: pybnesian.ConditionalDag, node_types: list[tuple[str, pybnesian.FactorType]]) -> None
Initializes the
ConditionalBayesianNetworkwith a giventype, andgraph. It specifies thenode_typesfor the nodes.- Parameters:
type –
BayesianNetworkTypeof this conditional Bayesian network.graph –
ConditionalDagof 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
cpdis 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:
ConditionalBayesianNetworkThis class implements a
ConditionalBayesianNetworkwith the typeGaussianNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalGaussianNetwork, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalGaussianNetworkwith the givennodesandinterface_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
ConditionalGaussianNetworkwith the givennodes,interface_nodesandarcs.- 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
ConditionalGaussianNetworkwith the givengraph.- Parameters:
graph –
ConditionalDagof the conditional Bayesian network.
- class pybnesian.ConditionalSemiparametricBN
Bases:
ConditionalBayesianNetworkThis class implements a
ConditionalBayesianNetworkwith the typeSemiparametricBNType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalSemiparametricBN, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalSemiparametricBNwith the givennodesandinterface_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
ConditionalSemiparametricBNwith the givennodes,interface_nodesandarcs.- 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
ConditionalSemiparametricBNwith the givengraph.- Parameters:
graph –
ConditionalDagof 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
ConditionalSemiparametricBNwith the givennodesandinterface_nodes. It specifies thenode_typesfor 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
ConditionalSemiparametricBNwith the givennodes,interface_nodesandarcs. It specifies thenode_typesfor 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
ConditionalSemiparametricBNwith the givengraph. It specifies thenode_typesfor the nodes.- Parameters:
graph –
ConditionalDagof the conditional Bayesian network.node_types – List of node type tuples (
node,FactorType) that specifies the type for each node.
- class pybnesian.ConditionalKDENetwork
Bases:
ConditionalBayesianNetworkThis class implements a
ConditionalBayesianNetworkwith the typeKDENetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalKDENetwork, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalKDENetworkwith the givennodesandinterface_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
ConditionalKDENetworkwith the givennodes,interface_nodesandarcs.- 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
ConditionalKDENetworkwith the givengraph.- Parameters:
graph –
ConditionalDagof the conditional Bayesian network.
- class pybnesian.ConditionalDiscreteBN
Bases:
ConditionalBayesianNetworkThis class implements a
ConditionalBayesianNetworkwith the typeDiscreteBNType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalDiscreteBN, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalDiscreteBNwith the givennodesandinterface_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
ConditionalDiscreteBNwith the givennodes,interface_nodesandarcs.- 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
ConditionalDiscreteBNwith the givengraph.- Parameters:
graph –
ConditionalDagof the conditional Bayesian network.
- class pybnesian.ConditionalHomogeneousBN
Bases:
ConditionalBayesianNetworkThis class implements an homogeneous conditional Bayesian network. This conditional Bayesian network can be used with any
FactorType. You can set theFactorTypein 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
ConditionalHomogeneousBNoffactor_typewith the givennodesandinterface_nodes.- Parameters:
factor_type –
FactorTypefor 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
ConditionalHomogeneousBNoffactor_typewith the givennodes,interface_nodesandarcs.- Parameters:
factor_type –
FactorTypefor 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
ConditionalHomogeneousBNoffactor_typewith the givengraph.- Parameters:
factor_type –
FactorTypefor all the nodes.graph –
ConditionalDagof the conditional Bayesian network.
- class pybnesian.ConditionalHeterogeneousBN
Bases:
ConditionalBayesianNetworkThis class implements an heterogeneous conditional Bayesian network. This conditional Bayesian network accepts a different
FactorTypefor each node. You can set the defaultFactorTypein 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givennodesandinterface_nodes.- Parameters:
factor_type – List of default
FactorTypefor 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givennodes,interface_nodesandnode_types.- Parameters:
factor_type – List of default
FactorTypefor 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givennodes,interface_nodesandarcs.- Parameters:
factor_type – List of default
FactorTypefor 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givennodes,interface_nodes,arcsandnode_types.- Parameters:
factor_type – List of default
FactorTypefor 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givengraph.- Parameters:
factor_type – List of default
FactorTypefor the conditional Bayesian network.graph –
ConditionalDagof 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
ConditionalHeterogeneousBNof defaultfactor_typewith the givengraphandnode_types.- Parameters:
factor_type – List of default
FactorTypefor the conditional Bayesian network.graph –
ConditionalDagof 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givennodesandinterface_nodes.- Parameters:
factor_types – Default
FactorTypefor 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givennodes,interface_nodesandnode_types.- Parameters:
factor_types – Default
FactorTypefor 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givennodes,interface_nodesandarcs.- Parameters:
factor_types – Default
FactorTypefor 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givennodes,interface_nodes,arcsandnode_types.- Parameters:
factor_types – Default
FactorTypefor 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givengraph.- Parameters:
factor_types – Default
FactorTypefor the Bayesian network for each different data type.graph –
ConditionalDagof 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
ConditionalHeterogeneousBNof different defaultfactor_typeswith the givengraphandnode_types.- Parameters:
factor_types – Default
FactorTypefor the Bayesian network for each different data type.graph –
ConditionalDagof the conditional Bayesian network.node_types – List of node type tuples (
node,FactorType) that specifies the type for each node.
- class pybnesian.ConditionalCLGNetwork
Bases:
ConditionalBayesianNetworkThis class implements a
ConditionalBayesianNetworkwith the typeCLGNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.ConditionalCLGNetwork, nodes: list[str], interface_nodes: list[str]) -> None
Initializes the
ConditionalCLGNetworkwith the givennodesandinterface_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
ConditionalCLGNetworkwith the givennodes,interface_nodesandarcs.- 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
ConditionalCLGNetworkwith the givengraph.- Parameters:
graph –
ConditionalDagof 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
ConditionalCLGNetworkwith the givennodesandinterface_nodes. It specifies thenode_typesfor 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
ConditionalCLGNetworkwith the givennodes,interface_nodesandarcs. It specifies thenode_typesfor 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
ConditionalCLGNetworkwith the givengraph. It specifies thenode_typesfor the nodes.- Parameters:
graph –
ConditionalDagof 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.
__init__(self: pybnesian.DynamicBayesianNetwork, type: pybnesian.BayesianNetworkType, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicBayesianNetworkwith the givenvariablesandmarkovian_order. It creates empty the static and transition Bayesian networks with the giventype.- Parameters:
type –
BayesianNetworkTypeof 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
DynamicBayesianNetworkwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransitionmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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:
DynamicBayesianNetworkThis class implements a
DynamicBayesianNetworkwith the typeGaussianNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicGaussianNetwork, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicGaussianNetworkwith the givenvariablesandmarkovian_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
DynamicGaussianNetworkwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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:
DynamicBayesianNetworkThis class implements a
DynamicBayesianNetworkwith the typeSemiparametricBNType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicSemiparametricBN, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicSemiparametricBNwith the givenvariablesandmarkovian_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
DynamicSemiparametricBNwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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:
DynamicBayesianNetworkThis class implements a
DynamicBayesianNetworkwith the typeKDENetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicKDENetwork, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicKDENetworkwith the givenvariablesandmarkovian_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
DynamicKDENetworkwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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:
DynamicBayesianNetworkThis class implements a
DynamicBayesianNetworkwith the typeDiscreteBN.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicDiscreteBN, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicDiscreteBNwith the givenvariablesandmarkovian_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
DynamicDiscreteBNwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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:
DynamicBayesianNetworkThis class implements an homogeneous dynamic Bayesian network. This dynamic Bayesian network can be used with any
FactorType. You can set theFactorTypein the constructor.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicHomogeneousBN, factor_type: pybnesian.FactorType, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicHomogeneousBNoffactor_typewith the givenvariablesandmarkovian_order. It creates empty static and transition Bayesian networks.- Parameters:
factor_type –
FactorTypefor 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
DynamicHomogeneousBNwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[variable_name]_t_[markovian_order].
The type of
static_bnandtransition_bnmust 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:
DynamicBayesianNetworkThis class implements an heterogeneous dynamic Bayesian network. This dynamic Bayesian network accepts a different
FactorTypefor each node. You can set the defaultFactorTypein 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
DynamicHeterogeneousBNof defaultfactor_typewith the givenvariablesandmarkovian_order. It creates empty static and transition Bayesian networks.- Parameters:
factor_type – Default
FactorTypefor 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
DynamicHeterogeneousBNof different defaultfactor_typeswith the givenvariablesandmarkovian_order. It creates empty static and transition Bayesian networks.- Parameters:
factor_types – Default
FactorTypefor 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
DynamicHeterogeneousBNwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[variable_name]_t_[markovian_order].
The type of
static_bnandtransition_bnmust 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:
DynamicBayesianNetworkThis class implements a
DynamicBayesianNetworkwith the typeCLGNetworkType.- __init__(*args, **kwargs)
Overloaded function.
__init__(self: pybnesian.DynamicCLGNetwork, variables: list[str], markovian_order: int) -> None
Initializes the
DynamicCLGNetworkwith the givenvariablesandmarkovian_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
DynamicCLGNetworkwith the givenvariablesandmarkovian_order. The static and transition Bayesian networks are initialized withstatic_bnandtransition_bnrespectively.Both
static_bnandtransition_bnmust contain the expected nodes:For the static network, it must contain the nodes from
[variable_name]_t_1to[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_1to[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.