mrftools.GibbsSampler module

Gibbs sampling class

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

Bases: object

Object that can run Gibbs sampling on a MarkovNet

burn_in(iters)[source]

Run the state update procedure until mixed. :param iters: number of iterations for mixing

count_occurrences(var)[source]

Count the number of times in our samples the variable was in each state.

Parameters:var (object) – variable to count the states of
Returns:count array of state occurrences
Return type:arraylike
static generate_state(weight)[source]

Generate state according to the given weight

gibbs_sampling(burn_in, num)[source]

Run Gibbs sampling

Parameters:
  • burn_in (int) – number of burn-in samples to discard
  • num (int) – number of samples to collect once burn-in phase is done
init_states(seed=None)[source]

Initialize the state of each node.

Parameters:seed – random seed
sampling(num)[source]

Run sampling

Parameters:num – number of samples to collect
update_states()[source]

Update the state of each node based on neighbor states.