Darwin  1.10(beta)
drwnSparseFactor.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-2017, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnSparseFactor.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 ** Albert Chen <chenay@student.unimelb.edu.au>
11 **
12 *****************************************************************************/
13 
14 #pragma once
15 
16 #include "drwnBase.h"
17 #include "drwnIO.h"
18 
19 #include "drwnVarUniverse.h"
20 #include "drwnVarAssignment.h"
21 #include "drwnTableFactor.h"
22 #include "drwnTableFactorMapping.h"
23 
24 using namespace std;
25 
26 // drwnSparseFactor --------------------------------------------------------
32 
34 {
35  protected:
36  std::map<drwnLocalAssignment, double> _assignments;
37 
38  public:
41  ~drwnSparseFactor() { }
42 
43  // access functions
44  const char *type() const { return "drwnSparseFactor"; }
45  drwnSparseFactor* clone(void) const { DRWN_TODO; return NULL; }
46 
49 
50  int entries() const { return _assignments.size(); }
51  const std::map<drwnLocalAssignment, double>& getAssignments() const { return _assignments; }
52 
54  double getValueOf(const drwnFullAssignment& y) const;
56  double getValueOf(const drwnPartialAssignment& y) const;
58  void setValueOf(const drwnFullAssignment& y, double val);
60  void setValueOf(const drwnPartialAssignment& y, double val);
61 
62  private:
64  void dfaToVals(const drwnFullAssignment& y, drwnLocalAssignment& vals) const;
65 };
virtual void addVariable(int var)
add variable by id
Definition: drwnTableFactor.cpp:98
std::vector< int > drwnLocalAssignment
defines an assignment to a subset of variables in the universe relative to some local scope (and fixe...
Definition: drwnVarAssignment.h:42
drwnSparseFactor(const drwnVarUniversePtr &ptr)
create an empty sparse factor
Definition: drwnSparseFactor.h:40
std::vector< int > drwnFullAssignment
defines a complete assignment to all variables in the universe
Definition: drwnVarAssignment.h:36
defines an assignment to a subset of the variables
Definition: drwnVarAssignment.h:47
Generic interface for a factor. Currently only inherited by drwnTableFactor.
Definition: drwnTableFactor.h:40
Data structures and utilities for encoding assignments to variables.
drwnSparseFactor * clone(void) const
returns a copy of the class usually implemented as virtual Foo* clone() { return new Foo(*this); } ...
Definition: drwnSparseFactor.h:45
const char * type() const
returns object type as a string (e.g., Foo::type() { return "Foo"; })
Definition: drwnSparseFactor.h:44
Encapsulates variables that the represented function is a function of. Allows user to add variables...
Definition: drwnSparseFactor.h:33
std::map< drwnLocalAssignment, double > _assignments
maps variable values to costs
Definition: drwnSparseFactor.h:36