Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnTableFactorOps.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: drwnTableFactorOps.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 
19 #include "drwnBase.h"
20 #include "drwnTableFactor.h"
21 #include "drwnTableFactorMapping.h"
22 
23 // drwnFactorOperation class -----------------------------------------------
27 
29  protected:
30  drwnTableFactor *_target;
31 
32  public:
35  virtual ~drwnFactorOperation();
36 
38  virtual void execute() = 0;
39 
41  inline drwnTableFactor *target() const { return _target; }
42 
43  protected:
46  virtual void initialize() { /* default: do nothing */ };
49  virtual bool checkTarget() { /* default: true */ return true; }
50 };
51 
52 // drwnFactorUnaryOp class -------------------------------------------------
54 
56  protected:
57  const drwnTableFactor * const _operandA;
58  drwnTableFactorMapping _mappingA;
59 
60  public:
64 
65  protected:
66  void initialize();
67  bool checkTarget();
68 };
69 
70 // drwnFactorBinaryOp class ------------------------------------------------
72 
74  protected:
75  const drwnTableFactor * const _operandA;
76  const drwnTableFactor * const _operandB;
77 
78  drwnTableFactorMapping _mappingA;
79  drwnTableFactorMapping _mappingB;
80 
81  public:
83  const drwnTableFactor *A, const drwnTableFactor *B);
86 
87  protected:
88  void initialize();
89  bool checkTarget();
90 };
91 
92 // drwnFactorNAryOp class --------------------------------------------------
94 
96  protected:
97  std::vector<const drwnTableFactor *> _factors;
98  std::vector<drwnTableFactorMapping> _mappings;
99 
100  public:
102  const drwnTableFactor *A, const drwnTableFactor *B);
104  const std::vector<const drwnTableFactor *>& A);
106  ~drwnFactorNAryOp();
107 
108  protected:
109  void initialize();
110  bool checkTarget();
111 };
112 
113 // drwnFactorAtomicOp class ------------------------------------------------
115 
117  protected:
120  std::vector<drwnFactorOperation *> _computations;
121 
122  public:
124  drwnFactorAtomicOp(const std::vector<drwnFactorOperation *>& ops);
126 
127  void execute();
128 
129  void addOperation(drwnFactorOperation *op);
130 };
131 
132 // drwnFactorCopyOp class --------------------------------------------------
134 
136  protected:
137  const drwnTableFactor * const _operandA;
138  drwnTableFactorMapping _mappingA;
139 
140  public:
143  ~drwnFactorCopyOp();
144 
145  void execute();
146 
147  protected:
148  void initialize();
149  bool checkTarget();
150 };
151 
152 // drwnFactorProductOp class -----------------------------------------------
154 
156  public:
158  const drwnTableFactor *A, const drwnTableFactor *B);
160  const std::vector<const drwnTableFactor *>& A);
163 
164  void execute();
165 };
166 
167 // drwnFactorDivideOp class ------------------------------------------------
169 
171  public:
173  const drwnTableFactor *A, const drwnTableFactor *B);
176 
177  void execute();
178 };
179 
180 // drwnFactorAdditionOp class ----------------------------------------------
182 
184  public:
186  const drwnTableFactor *A, const drwnTableFactor *B);
188  const std::vector<const drwnTableFactor *>& A);
191 
192  void execute();
193 };
194 
195 // drwnFactorSubtractOp class -----------------------------------------------
197 
199  public:
201  const drwnTableFactor *A, const drwnTableFactor *B);
204 
205  void execute();
206 };
207 
208 // drwnFactorWeightedSumOp class --------------------------------------------
210 
212  protected:
213  double _weightA;
214  double _weightB;
215 
216  public:
218  const drwnTableFactor *B, double wA = 1.0, double wB = 1.0);
221 
222  void execute();
223 };
224 
225 // drwnFactorPlusEqualsOp class ---------------------------------------------
227 
229  protected:
230  double _weightA;
231 
232  public:
234  double wA = 1.0);
237 
238  void execute();
239 };
240 
241 // drwnFactorMinusEqualsOp class ---------------------------------------------
243 
245  protected:
246  double _weightA;
247 
248  public:
250  double wA = 1.0);
253 
254  void execute();
255 };
256 
257 // drwnFactorTimesEqualsOp class --------------------------------------------
259 
261  public:
265 
266  void execute();
267 };
268 
269 // drwnFactorMarginalizeOp class --------------------------------------------
271 
273  protected:
274  const drwnTableFactor * const _operandA;
275  drwnTableFactorMapping _mappingA;
276 
277  public:
279  const drwnTableFactor *A);
281  const drwnTableFactor *A, int v);
283  const drwnTableFactor *A, const std::set<int>& v);
286 
287  void execute();
288 
289  protected:
290  bool checkTarget();
291 };
292 
293 // drwnFactorMaximizeOp class -----------------------------------------------
295 
297  protected:
298  const drwnTableFactor * const _operandA;
299  drwnTableFactorMapping _mappingA;
300 
301  public:
303  const drwnTableFactor *A);
305  const drwnTableFactor *A, int v);
307  const drwnTableFactor *A, const std::set<int>& v);
310 
311  void execute();
312 
313  protected:
314  bool checkTarget();
315 };
316 
317 // drwnFactorMinimizeOp class ----------------------------------------------
319 
321  protected:
322  const drwnTableFactor * const _operandA;
323  drwnTableFactorMapping _mappingA;
324 
325  public:
327  const drwnTableFactor *A);
329  const drwnTableFactor *A, int v);
331  const drwnTableFactor *A, const std::set<int>& v);
334 
335  void execute();
336 
337  protected:
338  bool checkTarget();
339 };
340 
341 // drwnFactorReduceOp class ------------------------------------------------
343 
345  protected:
346  const drwnTableFactor * const _operandA;
347  drwnPartialAssignment _assignment;
348 
349  public:
351  const drwnTableFactor *A, int var, int val);
353  const drwnTableFactor *A, const drwnPartialAssignment& assignment);
356 
357  void execute();
358 
359  protected:
360  bool checkTarget();
361 };
362 
363 // drwnFactorNormalizeOp class ---------------------------------------------
366 
368  public:
371 
372  void execute();
373 
374  protected:
375  bool checkTarget();
376 };
377 
378 // drwnFactorExpAndNormalizeOp class ---------------------------------------
380 
382  public:
385 
386  void execute();
387 
388  protected:
389  bool checkTarget();
390 };
391 
392 // drwnFactorLogNormalizeOp class -------------------------------------------
394 
396  public:
399 
400  void execute();
401 
402  protected:
403  bool checkTarget();
404 };
405 
Base class for implementing unary factor operations.
Definition: drwnTableFactorOps.h:55
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:79
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:358
Minimize over one or more variables in a factor.
Definition: drwnTableFactorOps.h:320
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:513
virtual bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.h:49
void initialize()
initialize mappings and target factor (with right set of variables, unless given, e...
Definition: drwnTableFactorOps.cpp:201
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:1049
std::vector< drwnFactorOperation * > _computations
factor operations are owned by object (i.e., they will be deleted when the object is destroyed) ...
Definition: drwnTableFactorOps.h:120
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:1178
void initialize()
initialize mappings and target factor (with right set of variables, unless given, e...
Definition: drwnTableFactorOps.cpp:117
Shift all the entries in a factor so that the maximum is zero.
Definition: drwnTableFactorOps.h:395
Base class for implementing various operations on table factors. The derived classes store mappings b...
Definition: drwnTableFactorOps.h:28
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:134
Normalize all the entries in a factor to sum to one. Assumes non-negative entries.
Definition: drwnTableFactorOps.h:367
Add one (weighted) factor to another inline.
Definition: drwnTableFactorOps.h:228
Base class for implementing binary factor operations.
Definition: drwnTableFactorOps.h:73
Subtract one factor from another.
Definition: drwnTableFactorOps.h:198
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:854
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:1098
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:405
Base class for implementing n-ary factor operations.
Definition: drwnTableFactorOps.h:95
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:1033
virtual void initialize()
initialize mappings and target factor (with right set of variables, unless given, e...
Definition: drwnTableFactorOps.h:46
Divide one factor by another.
Definition: drwnTableFactorOps.h:170
Subtract one (weighted) factor from another inline.
Definition: drwnTableFactorOps.h:244
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:1117
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:588
Maximize over one or more variables in a factor.
Definition: drwnTableFactorOps.h:296
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:450
void initialize()
initialize mappings and target factor (with right set of variables, unless given, e...
Definition: drwnTableFactorOps.cpp:65
Factor which stores the value of each assignment explicitly in table form.
Definition: drwnTableFactor.h:144
virtual void execute()=0
peform the factor operation on the target
Add a weighted combination of factors.
Definition: drwnTableFactorOps.h:211
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:296
Multiply two or more factors together.
Definition: drwnTableFactorOps.h:155
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:1141
drwnTableFactor * target() const
return a pointer to the target factor
Definition: drwnTableFactorOps.h:41
defines an assignment to a subset of the variables
Definition: drwnVarAssignment.h:41
void initialize()
initialize mappings and target factor (with right set of variables, unless given, e...
Definition: drwnTableFactorOps.cpp:308
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:870
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:680
Creates a mapping between entries in two tables.
Definition: drwnTableFactorMapping.h:39
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:641
Marginalize out one or more variables in a factor.
Definition: drwnTableFactorOps.h:272
Reduce factor by oberving the value of one or more variables.
Definition: drwnTableFactorOps.h:344
Multiply one factor by another inline.
Definition: drwnTableFactorOps.h:260
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:556
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:1070
Exponentiate and normalize all the entries in a factor to sum to one.
Definition: drwnTableFactorOps.h:381
Executes an atomic operation by executing a sequence of factor operations.
Definition: drwnTableFactorOps.h:116
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:778
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:1160
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:320
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:765
Add two or more factors together.
Definition: drwnTableFactorOps.h:183
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:262
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:220
bool checkTarget()
check that the target is not empty and has the right set of variables for this operation ...
Definition: drwnTableFactorOps.cpp:972
Copy one factor onto another.
Definition: drwnTableFactorOps.h:135
void execute()
peform the factor operation on the target
Definition: drwnTableFactorOps.cpp:948