sumu.bnet module
Module for representation and basic functionalities for Bayesian networks.
- class sumu.bnet.DiscreteBNet(nodes)
Bases:
objectRepresents a Bayesian network.
- classmethod from_dag(dag, *, data=None, arity=2, ess=0.5, params='MP')
- classmethod read_file(path_to_dsc_file)
Read and parse a .dsc file in the input path into a object of type
DiscreteBNet.- Parameters:
load. (filepath path to the .dsc file to) –
- Returns:
a fully specified Bayesian network.
- Return type:
- sample(N=1)
- class sumu.bnet.DiscreteNode(*, name=None, arity=None, cpt=None, parents=[])
Bases:
object- sample(config=None)
- class sumu.bnet.GaussianBNet(dag, *, data=None)
Bases:
object- classmethod random(n, *, enb=4)
- sample(N=1)
- sample_params(data=None)
- sumu.bnet.adj_mat_to_family_sequence(adj_mat, row_parents=False)
- sumu.bnet.family_sequence_to_adj_mat(dag, row_parents=False)
Format a sequence of families representing a DAG into an adjacency matrix.
- Parameters:
dag (iterable) – iterable like [(0, {}), (1, {2}), (2, {0, 1}), …] where first int is the node and the second item is a set of the parents.
row_parents (bool) – If true A[i,j] == 1 if \(i\) is parent of \(j\), otherwise a transpose.
- Returns:
adjacency matrix
- sumu.bnet.nodes_to_family_list(nodes)
- sumu.bnet.partition(dag)
- sumu.bnet.random_dag_with_expected_neighbourhood_size(n, *, enb=4)
- sumu.bnet.topological_sort(dag)
Sort the nodes in a DAG in a topological order.
The algorithm is from [1].
- sumu.bnet.transitive_closure(dag, R=None, mat=False)