mrftools.BruteForce module

BruteForce class for exact inference of marginals and maximizing states.

class mrftools.BruteForce.BruteForce(markov_net)[source]

Bases: object

Object that can do inference via ugly brute force. Recommended only for sanity checking and debugging using tiny examples.

compute_z()[source]

Compute the partition function by explicitly summing energy of all possible states. This is extremely expensive for anything but tiny Markov nets.

Returns:the partition function (normalizing constant) of the distribution
Return type:float
entropy()[source]

Compute the entropy of the distribution by explicitly accounting for every possible state.

Returns:entropy
Return type:float
map_inference()[source]

Compute most probable state configurations, i.e., maximum a posteriori (MAP) inference by explicitly trying every possible state.

Returns:a matrix of one-hot indicator vectors for the maximizing states of all variables
Return type:ndarray
pairwise_marginal(var_i, var_j)[source]

Compute the joint marginal probabilities between two variables.

Parameters:
  • var_i (object) – first variable to marginalize over
  • var_j (object) – second variable to marginalize over
Returns:

matrix representing the marginal probabilities of the two variables

Return type:

ndarray

unary_marginal(var)[source]

Compute the marginal probabilities of a variable.

Parameters:var (object) – variable whose marginals will be computed
Returns:vector of marginal probabilities for var
Return type:array