alex.ml.lbp package

Submodules

alex.ml.lbp.node module

class alex.ml.lbp.node.DiscreteFactor(name, desc, prob_table)[source]

Bases: alex.ml.lbp.node.Factor

This is a base class for discrete factor nodes in the Bayesian Network.

It can works with full conditional table defined by the provided prob_table function.

The variables must be attached in the same order as are the parameters in the prob_table function.

get_output_message(variable)[source]

Returns output messages from this factor to the given variable node.

update_input_messages()[source]

Updates all input messages from connected variable nodes.

class alex.ml.lbp.node.DiscreteNode(name, desc, card, observed=False)[source]

Bases: alex.ml.lbp.node.VariableNode

This is a class for all nodes with discrete/enumerable values.

The probabilities are stored in log format.

copy_node(node)[source]
explain(full=False, linear_prob=False)[source]

This function prints the values and their probabilities for this node.

get_most_probable_value()[source]

The function returns the most probable value and its probability in a tuple.

get_output_message(factor)[source]

Returns output messages from this node to the given factor.

This is done by subtracting the input log message from the given factor node from the current estimate log probabilities in this node.

get_two_most_probable_values()[source]

This function returns two most probable values and their probabilities.

The function returns a tuple consisting of two tuples (value, probability).

get_values()[source]
normalise()[source]

This function normalise the sum of all probabilities to 1.0

update_backward_messages()[source]
update_forward_messages()[source]
update_marginals()[source]

Update the marginal probabilities in the node by collecting all input messages and summing them in the log domain.

Finally, probabilities are normalised to sum to 1.0.

class alex.ml.lbp.node.Factor(name, desc)[source]

Bases: alex.ml.lbp.node.GenericNode

This is a base class for all factor nodes in the Bayesian Network.

attach_variable(variable)[source]
detach_variable(variable)[source]
get_variables()[source]
class alex.ml.lbp.node.GenericNode(name, desc)[source]

Bases: object

This is a base class for all nodes in the Bayesian Network.

class alex.ml.lbp.node.VariableNode(name, desc)[source]

Bases: alex.ml.lbp.node.GenericNode

This is a base class for all variable nodes in the Bayesian Network.

attach_factor(factor, forward=False)[source]
detach_factor(factor)[source]
get_factors()[source]

Module contents