Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnMapInference.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnMapInference.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <vector>
16 #include <set>
17 #include <map>
18 #include <list>
19 
20 #include "drwnBase.h"
21 #include "drwnVarUniverse.h"
22 #include "drwnVarAssignment.h"
23 #include "drwnFactorGraph.h"
24 #include "drwnTableFactorOps.h"
25 
26 // drwnMAPInference class --------------------------------------------------
37 
39  protected:
41 
42  public:
43  drwnMAPInference(const drwnFactorGraph& graph);
45  virtual ~drwnMAPInference();
46 
48  virtual void clear() { /* do nothing */ };
54  virtual std::pair<double, double> inference(drwnFullAssignment& mapAssignment) = 0;
55 };
56 
57 // drwnICMInference class --------------------------------------------------
60 
62  public:
63  drwnICMInference(const drwnFactorGraph& graph);
65 
66  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
67 };
68 
69 // drwnMessagePassingMAPInference class -------------------------------------
72 
74 {
75  public:
76  static unsigned MAX_ITERATIONS;
77  static double DAMPING_FACTOR;
78 
79  protected:
80  // forward and backward messages during each iteration
81  std::vector<drwnTableFactor *> _forwardMessages;
82  std::vector<drwnTableFactor *> _backwardMessages;
83  std::vector<drwnTableFactor *> _oldForwardMessages;
84  std::vector<drwnTableFactor *> _oldBackwardMessages;
85 
86  // computation tree: intermediate factors, and (atomic) factor operations
87  std::vector<drwnTableFactor *> _intermediateFactors;
88  std::vector<drwnFactorOperation *> _computations;
89 
90  // shared storage for intermediate factors
91  std::vector<drwnTableFactorStorage *> _sharedStorage;
92 
93  public:
95  //drwnMessagePassingMAPInference(const drwnMessagePassingMAPInference& inf);
97 
98  void clear();
99  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
100 
101  protected:
102  virtual void initializeMessages();
103  virtual void buildComputationGraph() = 0;
104  virtual void decodeBeliefs(drwnFullAssignment& mapAssignment);
105 };
106 
107 // drwnMaxProductInference class --------------------------------------------
113 
115  public:
118 
119  protected:
120  void buildComputationGraph();
121  void decodeBeliefs(drwnFullAssignment& mapAssignment);
122 };
123 
124 // drwnAsyncMaxProductInference class ---------------------------------------
130 
132  public:
135 
136  protected:
137  void buildComputationGraph();
138  void decodeBeliefs(drwnFullAssignment& mapAssignment);
139 };
140 
141 // drwnJunctionTreeInference class ------------------------------------------
144 
146  public:
149 
150  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
151 };
152 
153 // drwnGEMPLPInference class ------------------------------------------------
156 
158  protected:
159  std::vector<drwnClique> _separators; // list of all separators, S
160  std::vector<drwnEdge> _edges; // list of edges (c,s)
161  std::vector<std::set<int> > _cliqueEdges; // mapping from c to _edges
162  std::vector<std::set<int> > _separatorEdges; // mapping from s to _edges
163  double _lastDualObjective; // previous dual objecive value
164  unsigned _maxIterations; // maximum number of iterations
165 
166  public:
167  drwnGEMPLPInference(const drwnFactorGraph& graph);
169 
170  void clear();
171  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
172 
173  protected:
174  void initializeMessages();
175  void buildComputationGraph();
176  void decodeBeliefs(drwnFullAssignment& mapAssignment);
177 
178  // helper functions for building clique-to-separator mapping
179  int findSeparatorIndex(const drwnClique& cliqueA, const drwnClique& cliqueB);
180 
181  // computations for messages from clique \p cliqueId
182  void addMessageUpdate(int cliqueId, const drwnClique& cliqueVars,
183  const drwnTableFactor* psi = NULL);
184 };
185 
186 // drwnSontag08Inference class ----------------------------------------------
189 
191  public:
192  static unsigned WARMSTART_ITERATIONS;
193  static unsigned MAX_CLIQUES_TO_ADD;
195 
196  protected:
197  std::vector<drwnClique> _additionalCliques;
198 
199  public:
202 
203  void clear();
204  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
205 
206  protected:
207  void buildComputationGraph();
208 
212  virtual void findCliqueCandidates(std::map<drwnClique, std::vector<int> >& cliqueCandidateSet);
213 };
214 
215 // drwnDualDecompositionInference class ------------------------------------
219 
221  public:
222  static double INITIAL_ALPHA;
223  static bool USE_MIN_MARGINALS;
224 
225  public:
228 
229  std::pair<double, double> inference(drwnFullAssignment& mapAssignment);
230 };
static unsigned WARMSTART_ITERATIONS
maximum number of iterations < after adding clusters
Definition: drwnMapInference.h:192
Implements asynchronous max-product (min-sum) inference.
Definition: drwnMapInference.h:131
void clear()
Clear internally cached data (e.g., computation graph)
Definition: drwnMapInference.cpp:627
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:55
Implements iterated conditional modes (ICM) MAP inference. This method was first proposed in Besag...
Definition: drwnMapInference.h:61
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:639
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:966
virtual void findCliqueCandidates(std::map< drwnClique, std::vector< int > > &cliqueCandidateSet)
Generates the set of clique candidates to test after each GEMPLP iteration. Derived classes can overr...
Definition: drwnMapInference.cpp:1165
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:146
static unsigned MAX_ITERATIONS
maximum number of iterations
Definition: drwnMapInference.h:76
void clear()
Clear internally cached data (e.g., computation graph)
Definition: drwnMapInference.cpp:115
void clear()
Clear internally cached data (e.g., computation graph)
Definition: drwnMapInference.cpp:960
Container and utility functions for factor graphs.
Definition: drwnFactorGraph.h:40
Factor which stores the value of each assignment explicitly in table form.
Definition: drwnTableFactor.h:144
std::set< int > drwnClique
variable clique
Definition: drwnGraphUtils.h:37
Implements generic message-passing algorithms on factor graphs. See derived classes for specific algo...
Definition: drwnMapInference.h:73
Implements max-product inference.
Definition: drwnMapInference.h:114
std::vector< int > drwnFullAssignment
defines a complete assignment to all variables in the universe
Definition: drwnVarAssignment.h:36
Implements the generalized LP-based message passing algorithm of Globerson and Jaakkola, NIPS 2007.
Definition: drwnMapInference.h:157
const drwnFactorGraph & _graph
reference to initial clique potentials
Definition: drwnMapInference.h:40
Implements the incremental tightening of the LP MAP inference algorithm from Sontag et al...
Definition: drwnMapInference.h:190
virtual void clear()
Clear internally cached data (e.g., computation graph)
Definition: drwnMapInference.h:48
static double INITIAL_ALPHA
initial gradient step size
Definition: drwnMapInference.h:222
static bool USE_MIN_MARGINALS
use min-marginals for subgradients
Definition: drwnMapInference.h:223
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:1235
Interface for various MAP inference (energy minimization) algorithms.
Definition: drwnMapInference.h:38
Data structures and utilities for encoding assignments to variables.
std::pair< double, double > inference(drwnFullAssignment &mapAssignment)
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
Definition: drwnMapInference.cpp:597
Implements the junction tree algorithm for exact inference on a factor graph using drwnAsyncMaxProdIn...
Definition: drwnMapInference.h:145
Implements dual decomposition MAP inference (see Komodakis and Paragios, CVPR 2009 and works cited th...
Definition: drwnMapInference.h:220
static double DAMPING_FACTOR
damping factor for updating messages
Definition: drwnMapInference.h:77
void decodeBeliefs(drwnFullAssignment &mapAssignment)
Definition: drwnMapInference.cpp:510
static unsigned MAX_CLIQUES_TO_ADD
number of cliques to add per cycle
Definition: drwnMapInference.h:194
virtual std::pair< double, double > inference(drwnFullAssignment &mapAssignment)=0
Run inference (or resume for iterative algorithms). Algorithms may initialize from mapAssignment if n...
void decodeBeliefs(drwnFullAssignment &mapAssignment)
Definition: drwnMapInference.cpp:347