OpenGM  2.3.x
Discrete Graphical Model Library
swendsenwang.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_SWENDSENWANG_HXX
3 #define OPENGM_SWENDSENWANG_HXX
4 
5 #include <vector>
6 #include <set>
7 #include <stack>
8 #include <cmath>
9 #include <algorithm>
10 #include <iostream>
11 
12 #include "opengm/opengm.hxx"
22 #include "opengm/inference/visitors/visitor.hxx"
24 
25 namespace opengm {
26 
28 namespace detail_swendsenwang {
29  template<class OPERATOR, class ACCUMULATOR, class PROBABILITY>
30  struct ValueToProbability;
31 
32  template<class PROBABILITY>
33  struct ValueToProbability<Multiplier, Maximizer, PROBABILITY>
34  {
35  typedef PROBABILITY ProbabilityType;
36  template<class T>
37  static ProbabilityType convert(const T x)
38  { return static_cast<ProbabilityType>(x); }
39  };
40 
41  template<class PROBABILITY>
42  struct ValueToProbability<Adder, Minimizer, PROBABILITY>
43  {
44  typedef PROBABILITY ProbabilityType;
45  template<class T>
46  static ProbabilityType convert(const T x)
47  { return static_cast<ProbabilityType>(std::exp(-x)); }
48  };
49 }
51 
53 template<class SW>
55 public:
56  typedef SW SwendsenWangType;
57 
58  void operator()(const SwendsenWangType&, const size_t, const size_t,
59  const bool, const bool) const;
60 };
61 
63 template<class SW>
65  {
66 public:
67  typedef SW SwendsenWangType;
68 
69  void operator()(const SwendsenWangType&, const size_t, const size_t,
70  const bool, const bool) const;
71 };
72 
74 template<class SW>
76 public:
77  typedef SW SwendsenWangType;
78  typedef typename SwendsenWangType::ValueType ValueType;
79  typedef typename SwendsenWangType::GraphicalModelType GraphicalModelType;
80  typedef typename GraphicalModelType::IndependentFactorType IndependentFactorType;
81 
82  // construction
84  SwendsenWangMarginalVisitor(const GraphicalModelType&);
85  void assign(const GraphicalModelType&);
86 
87  // manipulation
88  template<class VariableIndexIterator>
89  size_t addMarginal(VariableIndexIterator, VariableIndexIterator);
90  size_t addMarginal(const size_t);
91  void operator()(const SwendsenWangType&, const size_t, const size_t,
92  const bool, const bool);
93 
94  // query
95  size_t numberOfSamples() const;
96  size_t numberOfAcceptedSamples() const;
97  size_t numberOfRejectedSamples() const;
98  size_t numberOfMarginals() const;
99  const IndependentFactorType& marginal(const size_t) const;
100 
101 private:
102  const GraphicalModelType* gm_;
103  size_t numberOfSamples_;
104  size_t numberOfAcceptedSamples_;
105  size_t numberOfRejectedSamples_;
106  std::vector<IndependentFactorType> marginals_;
107  std::vector<typename GraphicalModelType::LabelType> stateCache_;
108 };
109 
114 template<class GM, class ACC>
116 : public Inference<GM, ACC> {
117 public:
118  typedef GM GraphicalModelType;
119  typedef ACC AccumulationType;
121  typedef double ProbabilityType;
124  typedef TimingVisitor<SwendsenWang<GM, ACC> > TimingVisitorType;
125 
126  struct Parameter
127  {
128  Parameter
129  (
130  const size_t maxNumberOfSamplingSteps = 1e5,
131  const size_t numberOfBurnInSteps = 1e5,
132  ProbabilityType lowestAllowedProbability = 1e-6,
133  const std::vector<LabelType>& initialState = std::vector<LabelType>()
134  )
135  : maxNumberOfSamplingSteps_(maxNumberOfSamplingSteps),
136  numberOfBurnInSteps_(numberOfBurnInSteps),
137  lowestAllowedProbability_(lowestAllowedProbability),
138  initialState_(initialState)
139  {}
140 
143  ProbabilityType lowestAllowedProbability_;
144  std::vector<LabelType> initialState_;
145  };
146 
147  SwendsenWang(const GraphicalModelType&, const Parameter& param = Parameter());
148  virtual std::string name() const;
149  virtual const GraphicalModelType& graphicalModel() const;
150  virtual void reset();
151  virtual InferenceTermination infer();
152  template<class VISITOR>
153  InferenceTermination infer(VISITOR&);
154  virtual InferenceTermination arg(std::vector<LabelType>&, const size_t = 1) const;
155 
156  LabelType markovState(const size_t) const;
157  ValueType markovValue() const;
158  LabelType currentBestState(const size_t) const;
159  ValueType currentBestValue() const;
160 
161 private:
162  void computeEdgeProbabilities();
163  void cluster(Partition<size_t>&) const;
164  template<bool BURNED_IN, class VARIABLE_ITERATOR, class STATE_ITERATOR>
165  bool move(VARIABLE_ITERATOR, VARIABLE_ITERATOR, STATE_ITERATOR);
166 
167  Parameter parameter_;
168  const GraphicalModelType& gm_;
170  std::vector<RandomAccessSet<size_t> > variableAdjacency_;
171  std::vector<std::vector<ProbabilityType> > edgeProbabilities_;
172  std::vector<LabelType> currentBestState_;
173  ValueType currentBestValue_;
174 };
175 
176 template<class GM, class ACC>
177 inline
179 (
181  const typename SwendsenWang<GM, ACC>::Parameter& param
182 )
183 : parameter_(param),
184  gm_(gm),
185  movemaker_(param.initialState_.size() == gm.numberOfVariables() ? Movemaker<GM>(gm, param.initialState_.begin()) : Movemaker<GM>(gm)),
186  variableAdjacency_(gm.numberOfVariables()),
187  edgeProbabilities_(gm.numberOfVariables()),
188  currentBestState_(gm.numberOfVariables()),
189  currentBestValue_(movemaker_.value())
190 {
191  if(parameter_.initialState_.size() != 0 && parameter_.initialState_.size() != gm.numberOfVariables()) {
192  throw RuntimeError("The size of the initial state does not match the number of variables.");
193  }
194  gm.variableAdjacencyList(variableAdjacency_);
195  for(size_t j=0; j<gm_.numberOfVariables(); ++j) {
196  edgeProbabilities_[j].resize(variableAdjacency_[j].size());
197  }
198  computeEdgeProbabilities();
199 }
200 
201 template<class GM, class ACC>
202 inline void
204 {
205  if(parameter_.initialState_.size() == gm_.numberOfVariables()) {
206  movemaker_.initialize(parameter_.initialState_.begin());
207  currentBestState_.assign(parameter_.initialState_.begin(),parameter_.initialState_.end());
208  }
209  else if(parameter_.initialState_.size() != 0) {
210  throw RuntimeError("The size of the initial state does not match the number of variables.");
211  }
212  else{
213  movemaker_.reset();
214  std::fill(currentBestState_.begin(),currentBestState_.end(),0);
215  }
216  currentBestValue_ = movemaker_.value();
217  computeEdgeProbabilities();
218 }
219 
220 template<class GM, class ACC>
221 inline std::string
223 {
224  return "SwendsenWang";
225 }
226 
227 template<class GM, class ACC>
228 inline const typename SwendsenWang<GM, ACC>::GraphicalModelType&
230 {
231  return gm_;
232 }
233 
234 template<class GM, class ACC>
235 template<class VISITOR>
238 (
239  VISITOR& visitor
240 )
241 {
242  Partition<size_t> partition(gm_.numberOfVariables());
243  std::vector<size_t> representatives(gm_.numberOfVariables());
244  std::vector<bool> visited(gm_.numberOfVariables());
245  std::stack<size_t> stack;
246  std::vector<size_t> variablesInCluster;
247  std::vector<size_t> variablesAroundCluster;
248  for(size_t j=0; j<parameter_.numberOfBurnInSteps_ + parameter_.maxNumberOfSamplingSteps_; ++j) {
249  // cluster the variable adjacency graph by randomly removing edges
250  cluster(partition);
251 
252  // draw one cluster at random
253  partition.representatives(representatives.begin());
254  RandomUniform<size_t> randomNumberGeneratorCluster(0, partition.numberOfSets());
255  const size_t representative = representatives[randomNumberGeneratorCluster()];
256  // collect all variables in and around the drawn cluster
257  variablesInCluster.clear();
258  variablesAroundCluster.clear();
259  visited[representative] = true;
260  stack.push(representative);
261  while(!stack.empty()) {
262  const size_t variable = stack.top();
263  stack.pop();
264  variablesInCluster.push_back(variable);
265  for(size_t k=0; k<variableAdjacency_[variable].size(); ++k) {
266  const size_t adjacentVariable = variableAdjacency_[variable][k];
267  if(!visited[adjacentVariable]) {
268  visited[adjacentVariable] = true;
269  if(partition.find(adjacentVariable) == representative) { // if in cluster
270  stack.push(adjacentVariable);
271  }
272  else {
273  variablesAroundCluster.push_back(adjacentVariable);
274  }
275  }
276  }
277  }
278 
279  // clean vector visited
280  for(size_t k=0; k<variablesInCluster.size(); ++k) {
281  visited[variablesInCluster[k]] = false;
282  }
283  for(size_t k=0; k<variablesAroundCluster.size(); ++k) {
284  visited[variablesAroundCluster[k]] = false;
285  }
286 
287  // assertion testing
288  if(!NO_DEBUG) {
289  for(size_t k=0; k<visited.size(); ++k) {
290  OPENGM_ASSERT(!visited[k]);
291  }
292  for(size_t k=0; k<variablesInCluster.size(); ++k) {
293  OPENGM_ASSERT(gm_.numberOfLabels(variablesInCluster[k]) == gm_.numberOfLabels(representative));
294  }
295  }
296 
297  // draw a new label at random
298  RandomUniform<size_t> randomNumberGeneratorState(0, gm_.numberOfLabels(representative));
299  size_t targetLabel = randomNumberGeneratorState();
300  std::vector<size_t> targetLabels(variablesInCluster.size(), targetLabel); // TODO add simpler function to movemaker
301 
302  if(j < parameter_.numberOfBurnInSteps_) {
303  move<false>(variablesInCluster.begin(), variablesInCluster.end(), targetLabels.begin());
304  visitor(*this, j, variablesInCluster.size(), true, true);
305  continue;
306  }
307 
308  // evaluate probability density function
309  const ProbabilityType currentPDF =
310  detail_swendsenwang::ValueToProbability<OperatorType, AccumulationType, ProbabilityType>::convert
311  (movemaker_.value());
312  const ProbabilityType targetPDF =
313  detail_swendsenwang::ValueToProbability<OperatorType, AccumulationType, ProbabilityType>::convert
314  (movemaker_.valueAfterMove(variablesInCluster.begin(), variablesInCluster.end(), targetLabels.begin()));
315 
316  // evaluate proposal density
317  ProbabilityType currentValueProposal = 1;
318  ProbabilityType targetValueProposal = 1;
319  for(std::vector<size_t>::const_iterator vi = variablesAroundCluster.begin(); vi != variablesAroundCluster.end(); ++vi) {
320  if(movemaker_.state(*vi) == movemaker_.state(representative)) { // *vi has old label
321  for(size_t k=0; k<variableAdjacency_[*vi].size(); ++k) {
322  const size_t nvi = variableAdjacency_[*vi][k];
323  if(partition.find(nvi) == representative) { // if *nvi is in cluster
324  currentValueProposal *= (1.0 - edgeProbabilities_[*vi][k]);
325  }
326  }
327  }
328  else if(movemaker_.state(*vi) == targetLabel) { // *vi has new label
329  for(size_t k=0; k<variableAdjacency_[*vi].size(); ++k) {
330  const size_t nvi = variableAdjacency_[*vi][k];
331  if(partition.find(nvi) == representative) { // if *nvi is in cluster
332  targetValueProposal *= (1.0 - edgeProbabilities_[*vi][k]);
333  }
334  }
335  }
336  }
337 
338  // accept or reject re-labeling
339  const ProbabilityType metropolisHastingsProbability = (targetValueProposal / currentValueProposal) * (targetPDF / currentPDF);
340  OPENGM_ASSERT(metropolisHastingsProbability > 0);
341  if(metropolisHastingsProbability >= 1) { // accept
342  move<true>(variablesInCluster.begin(), variablesInCluster.end(), targetLabels.begin());
343  visitor(*this, j, variablesInCluster.size(), true, false);
344  }
345  else {
346  RandomUniform<ProbabilityType> randomNumberGeneratorAcceptance(0, 1);
347  if(metropolisHastingsProbability >= randomNumberGeneratorAcceptance()) { // accept
348  move<true>(variablesInCluster.begin(), variablesInCluster.end(), targetLabels.begin());
349  visitor(*this, j, variablesInCluster.size(), true, false);
350  }
351  else { // reject
352  visitor(*this, j, variablesInCluster.size(), false, false);
353  }
354  }
355  }
356 
357  return NORMAL;
358 }
359 
360 template<class GM, class ACC>
363 {
364  EmptyVisitorType visitor;
365  return infer(visitor);
366 }
367 
368 template<class GM, class ACC>
371 (
372  std::vector<LabelType>& x,
373  const size_t N
374 ) const {
375  if(N == 1) {
376  x = currentBestState_;
377  return NORMAL;
378  }
379  else {
380  return UNKNOWN;
381  }
382 }
383 
384 template<class GM, class ACC>
385 inline typename SwendsenWang<GM, ACC>::LabelType
387 (
388  const size_t j
389 ) const
390 {
391  OPENGM_ASSERT(j < gm_.numberOfVariables());
392  return movemaker_.state(j);
393 }
394 
395 template<class GM, class ACC>
396 inline typename SwendsenWang<GM, ACC>::ValueType
398 {
399  return movemaker_.value();
400 }
401 
402 template<class GM, class ACC>
403 inline typename SwendsenWang<GM, ACC>::LabelType
405 (
406  const size_t j
407 ) const
408 {
409  OPENGM_ASSERT(j < gm_.numberOfVariables());
410  return currentBestState_[j];
411 }
412 
413 template<class GM, class ACC>
414 inline typename SwendsenWang<GM, ACC>::ValueType
416 {
417  return currentBestValue_;
418 }
419 
420 template<class GM, class ACC>
421 template<bool BURNED_IN, class VARIABLE_ITERATOR, class STATE_ITERATOR>
422 inline bool SwendsenWang<GM, ACC>::move
423 (
424  VARIABLE_ITERATOR begin,
425  VARIABLE_ITERATOR end,
426  STATE_ITERATOR it
427 )
428 {
429  movemaker_.move(begin, end, it);
430  if(BURNED_IN) {
431  if(ACC::bop(movemaker_.value(), currentBestValue_)) {
432  currentBestValue_ = movemaker_.value();
433  std::copy(movemaker_.stateBegin(), movemaker_.stateEnd(), currentBestState_.begin());
434  return true;
435  }
436  }
437  return false;
438 }
439 
440 template<class GM, class ACC>
441 void
442 SwendsenWang<GM, ACC>::computeEdgeProbabilities()
443 {
444  std::set<size_t> factors;
445  std::set<size_t> connectedVariables;
446  size_t variables[] = {0, 0};
447  for(variables[0] = 0; variables[0] < gm_.numberOfVariables(); ++variables[0]) {
448  for(size_t j = 0; j < variableAdjacency_[variables[0]].size(); ++j) {
449  variables[1] = variableAdjacency_[variables[0]][j];
450  if(gm_.numberOfLabels(variables[0]) == gm_.numberOfLabels(variables[1])) {
451  // for all pairs of connected variables, variables[0] and variables[1],
452  // that have the same number of states, identify
453  // - all factors connected to variables[0] or variables[1] (or both)
454  // - all variables connected to these factors
455  factors.clear();
456  connectedVariables.clear();
457 
458  // factors that depend on at least variables[0] OR variables[1]
459  for(size_t k = 0; k < 2; ++k) {
460  for(typename GraphicalModelType::ConstFactorIterator it = gm_.factorsOfVariableBegin(variables[k]);
461  it != gm_.factorsOfVariableEnd(variables[k]); ++it) {
462  factors.insert(*it);
463  for(size_t m = 0; m < gm_[*it].numberOfVariables(); ++m) {
464  connectedVariables.insert(gm_[*it].variableIndex(m));
465  }
466  }
467  }
468 
469  // factors that depend on at least variables[0] AND variables[1]
470  /*
471  for(typename GraphicalModelType::ConstFactorIterator it = gm_.factorsOfVariableBegin(variables[0]);
472  it != gm_.factorsOfVariableEnd(variables[0]); ++it) {
473  for(size_t k = 0; k<gm_[*it].numberOfVariables(); ++k) {
474  if(gm_[*it].variableIndex(k) == variables[1]) {
475  factors.insert(*it);
476  for(size_t m = 0; m < gm_[*it].numberOfVariables(); ++m) {
477  connectedVariables.insert(gm_[*it].variableIndex(m));
478  }
479  break;
480  }
481  }
482  }
483  */
484 
485  // operate all found factors up
486  IndependentFactorType localFactor(gm_,
487  connectedVariables.begin(),
488  connectedVariables.end(),
489  OperatorType::template neutral<ValueType>());
490  for(std::set<size_t>::const_iterator it = factors.begin(); it != factors.end(); ++it) {
491  OperatorType::op(gm_[*it], localFactor);
492  }
493 
494  // marginalize
495  size_t indices[] = {0, 0};
496  for(size_t k = 0; k < localFactor.numberOfVariables(); ++k) {
497  if(localFactor.variableIndex(k) == variables[0]) {
498  indices[0] = k;
499  }
500  else if(localFactor.variableIndex(k) == variables[1]) {
501  indices[1] = k;
502  }
503  }
504  ProbabilityType probEqual = 0;
505  ProbabilityType probUnequal = 0;
506  ShapeWalker< typename IndependentFactorType::ShapeIteratorType>
507  walker(localFactor.shapeBegin(), localFactor.numberOfVariables());
508  for(size_t k = 0; k < localFactor.size(); ++k, ++walker) {
509  const ValueType value = localFactor(walker.coordinateTuple().begin());
510  const ProbabilityType p = detail_swendsenwang::ValueToProbability<OperatorType, AccumulationType, ProbabilityType>::convert(value);
511  if(walker.coordinateTuple()[indices[0]] == walker.coordinateTuple()[indices[1]]) {
512  probEqual += p;
513  }
514  else {
515  probUnequal += p;
516  }
517  }
518 
519  // normalize
520  ProbabilityType sum = probEqual + probUnequal;
521  if(sum == 0.0) {
522  throw RuntimeError("Some local probabilities are exactly zero.");
523  }
524  probEqual /= sum;
525  probUnequal /= sum;
526  if(probEqual < parameter_.lowestAllowedProbability_ || probUnequal < parameter_.lowestAllowedProbability_) {
527  throw RuntimeError("Marginal probabilities are smaller than the allowed minimum.");
528  }
529 
530  edgeProbabilities_[variables[0]][j] = probUnequal;
531  }
532  }
533  }
534 }
535 
536 template<class GM, class ACC>
537 void
538 SwendsenWang<GM, ACC>::cluster
539 (
540  Partition<size_t>& out
541 ) const
542 {
543  // randomly merge variables
544  out.reset(gm_.numberOfVariables());
545  opengm::RandomUniform<ProbabilityType> randomNumberGenerator(0.0, 1.0);
546  size_t variables[] = {0, 0};
547  for(variables[0] = 0; variables[0] < gm_.numberOfVariables(); ++variables[0]) {
548  for(size_t j = 0; j < variableAdjacency_[variables[0]].size(); ++j) {
549  variables[1] = variableAdjacency_[variables[0]][j];
550  if(variables[0] < variables[1]) { // only once for each pair
551  if(movemaker_.state(variables[0]) == movemaker_.state(variables[1])) {
552  if(edgeProbabilities_[variables[0]][j] > randomNumberGenerator()) {
553  // turn edge on with probability edgeProbabilities_[variables[0]][variables[1]]
554  out.merge(variables[0], variables[1]);
555  }
556  }
557  }
558  }
559  }
560 }
561 
562 template<class SW>
563 inline void
566  const size_t iteration,
567  const size_t clusterSize,
568  const bool accepted,
569  const bool burningIn
570 ) const {
571 }
572 
573 template<class SW>
574 inline void
577  const size_t iteration,
578  const size_t clusterSize,
579  const bool accepted,
580  const bool burningIn
581 ) const {
582  std::cout << "Step " << iteration
583  << ": " << "V_opt=" << sw.currentBestValue()
584  << ", " << "V_markov=" << sw.markovValue()
585  << ", " << "cs=" << clusterSize
586  << ", " << (accepted ? "accepted" : "rejected")
587  << ", " << (burningIn ? "burning in" : "sampling")
588  << std::endl;
589  //std::cout << " arg_opt: ";
590  //for(size_t j=0; j<sw.graphicalModel().numberOfVariables(); ++j) {
591  // std::cout << sw.currentBestState(j) << ' ';
592  //}
593  //std::cout << std::endl;
594  //
595  //std::cout << " arg_markov: ";
596  //for(size_t j=0; j<sw.graphicalModel().numberOfVariables(); ++j) {
597  // std::cout << sw.markovState(j) << ' ';
598  //std::cout << std::endl;
599 }
600 
601 template<class SW>
602 inline
604 : gm_(NULL),
605  numberOfSamples_(0),
606  numberOfAcceptedSamples_(0),
607  numberOfRejectedSamples_(0),
608  marginals_(),
609  stateCache_()
610 {}
611 
612 template<class SW>
613 inline
616 )
617 : gm_(&gm),
618  numberOfSamples_(0),
619  numberOfAcceptedSamples_(0),
620  numberOfRejectedSamples_(0),
621  marginals_(),
622  stateCache_()
623 {}
624 
625 template<class SW>
626 inline void
629 )
630 {
631  gm_ = &gm;
632 }
633 
634 template<class SW>
635 inline void
638  const size_t iteration,
639  const size_t clusterSize,
640  const bool accepted,
641  const bool burningIn
642 ) {
643  if(!burningIn) {
644  ++numberOfSamples_;
645  if(accepted) {
646  ++numberOfAcceptedSamples_;
647  }
648  else {
649  ++numberOfRejectedSamples_;
650  }
651  for(size_t j = 0; j < marginals_.size(); ++j) {
652  for(size_t k = 0; k < marginals_[j].numberOfVariables(); ++k) {
653  stateCache_[k] = sw.markovState(marginals_[j].variableIndex(k));
654  }
655  ++marginals_[j](stateCache_.begin());
656  }
657  }
658 }
659 
660 template<class SW>
661 template<class VariableIndexIterator>
662 inline size_t
664  VariableIndexIterator begin,
665  VariableIndexIterator end
666 ) {
667  marginals_.push_back(IndependentFactorType(*gm_, begin, end));
668  if(marginals_.back().numberOfVariables() > stateCache_.size()) {
669  stateCache_.resize(marginals_.back().numberOfVariables());
670  }
671  return marginals_.size() - 1;
672 }
673 
674 template<class SW>
675 inline size_t
677  const size_t variableIndex
678 ) {
679  size_t variableIndices[] = {variableIndex};
680  return addMarginal(variableIndices, variableIndices + 1);
681 }
682 
683 template<class SW>
684 inline size_t
686  return numberOfSamples_;
687 }
688 
689 template<class SW>
690 inline size_t
692  return numberOfAcceptedSamples_;
693 }
694 
695 template<class SW>
696 inline size_t
698  return numberOfRejectedSamples_;
699 }
700 
701 template<class SW>
702 inline size_t
704  return marginals_.size();
705 }
706 
707 template<class SW>
710  const size_t setIndex
711 ) const {
712  return marginals_[setIndex];
713 }
714 
715 } // namespace opengm
716 
717 #endif // #ifndef OPENGM_SWENDSENWANG_HXX
void operator()(const SwendsenWangType &, const size_t, const size_t, const bool, const bool) const
The OpenGM namespace.
Definition: config.hxx:43
void operator()(const SwendsenWangType &, const size_t, const size_t, const bool, const bool) const
virtual std::string name() const
const IndependentFactorType & marginal(const size_t) const
virtual InferenceTermination infer()
TimingVisitor< SwendsenWang< GM, ACC > > TimingVisitorType
Generalized Swendsen-Wang sampling A. Barbu, S. Zhu, "Generalizing swendsen-wang to sampling arbitra...
std::vector< LabelType > initialState_
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77
ValueType currentBestValue() const
SwendsenWangType::GraphicalModelType GraphicalModelType
SwendsenWangType::ValueType ValueType
LabelType markovState(const size_t) const
SwendsenWangVerboseVisitor< SwendsenWang< GM, ACC > > VerboseVisitorType
LabelType currentBestState(const size_t) const
SwendsenWangEmptyVisitor< SwendsenWang< GM, ACC > > EmptyVisitorType
GraphicalModelType::ValueType ValueType
Definition: inference.hxx:41
Inference algorithm interface.
Definition: inference.hxx:34
GraphicalModelType::IndependentFactorType IndependentFactorType
virtual const GraphicalModelType & graphicalModel() const
size_t addMarginal(VariableIndexIterator, VariableIndexIterator)
ValueType markovValue() const
void assign(const GraphicalModelType &)
void operator()(const SwendsenWangType &, const size_t, const size_t, const bool, const bool)
const bool NO_DEBUG
Definition: config.hxx:64
SwendsenWang(const GraphicalModelType &, const Parameter &param=Parameter())
Disjoint set data structure with path compression.
Definition: partition.hxx:13
Parameter(const size_t maxNumberOfSamplingSteps=1e5, const size_t numberOfBurnInSteps=1e5, ProbabilityType lowestAllowedProbability=1e-6, const std::vector< LabelType > &initialState=std::vector< LabelType >())
GraphicalModelType::LabelType LabelType
Definition: inference.hxx:39
ProbabilityType lowestAllowedProbability_
OpenGM runtime error.
Definition: opengm.hxx:100
virtual void reset()
virtual InferenceTermination arg(std::vector< LabelType > &, const size_t=1) const
output a solution
InferenceTermination
Definition: inference.hxx:24