OpenGM  2.3.x
Discrete Graphical Model Library
function_properties.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_FUNCTION_PROPERTIES_HXX
3 #define OPENGM_FUNCTION_PROPERTIES_HXX
4 
5 #include <cmath>
6 
7 #include "opengm/opengm.hxx"
15 #include "opengm/operations/or.hxx"
21 
22 #define OPENGM_FUNCTION_TYPEDEF_MACRO typedef typename FunctionType::ValueType ValueType;\
23 typedef typename FunctionType::IndexType IndexType;\
24 typedef typename FunctionType::LabelType LabelType;\
25 typedef typename FunctionType::FunctionShapeIteratorType FunctionShapeIteratorType
26 
27 namespace opengm {
28 
30  enum Values{
34  };
35 };
36 
38  enum Values{
39  Sum=0,
44  };
45 };
46 
47 template<int PROPERTY_ID,class FUNCTION>
49 
50 template<int PROPERTY_ID,class FUNCTION>
52 
53 namespace detail_properties{
54  template<class FUNCTION,class ACCUMULATOR>
56  template<class FUNCTION,class ACCUMULATOR>
58 }
59 
60 // Fallback implementation(s) of binary properties
61 template<class FUNCTION>
62 class BinaryFunctionProperties<BinaryProperties::IsPotts, FUNCTION> {
63  typedef FUNCTION FunctionType;
65 public:
66  static bool op(const FunctionType & f) {
67  ShapeWalker<FunctionShapeIteratorType> shapeWalker(f.functionShapeBegin(), f.dimension());
68  ValueType vEqual = f(shapeWalker.coordinateTuple().begin());
69  ++shapeWalker;
70  ValueType vNotEqual = f(shapeWalker.coordinateTuple().begin());
71  ++shapeWalker;
72  for (IndexType i = 2; i < f.size(); ++i, ++shapeWalker) {
73  // all labels are equal
74  if (isEqualValueVector(shapeWalker.coordinateTuple())) {
75  if (vEqual != f(shapeWalker.coordinateTuple().begin()))
76  return false;
77  } // all labels are not equal
78  else {
79  if (vNotEqual != f(shapeWalker.coordinateTuple().begin()))
80  return false;
81  }
82  }
83  return true;
84  }
85 };
86 
87 
88 // Fallback implementation(s) of (real) value properties
89 // Some basic properties are derived from
90 // "AllValuesInAnyOrderFunctionProperties" and
91 // "AtLeastAllUniqueValuesFunctionProperties"
92 template<class FUNCTION>
93 class ValueFunctionProperties<ValueProperties::Product, FUNCTION>
95 };
96 
97 template<class FUNCTION>
100 };
101 
102 template<class FUNCTION>
103 class ValueFunctionProperties<ValueProperties::Minimum, FUNCTION>
105 };
106 
107 template<class FUNCTION>
108 class ValueFunctionProperties<ValueProperties::Maximum, FUNCTION>
110 };
111 
112 
113 namespace detail_properties{
114  template<class FUNCTION,class ACCUMULATOR>
115  class AllValuesInAnyOrderFunctionProperties{
116  typedef FUNCTION FunctionType;
118  public:
119  static ValueType op(const FunctionType & f) {
120  opengm::AccumulationFunctor<ACCUMULATOR,ValueType> functor;
121  f.forAllValuesInAnyOrder(functor);
122  return functor.value();
123  }
124  };
125  template<class FUNCTION,class ACCUMULATOR>
126  class AtLeastAllUniqueValuesFunctionProperties{
127  typedef FUNCTION FunctionType;
129  public:
130  static ValueType op(const FunctionType & f) {
131  opengm::AccumulationFunctor<ACCUMULATOR,ValueType> functor;
132  f.forAllValuesInAnyOrder(functor);
133  return functor.value();
134  }
135  };
136 }
137 
138 }// namespace opengm
139 
140 #endif //OPENGM_FUNCTION_PROPERTIES_HXX
The OpenGM namespace.
Definition: config.hxx:43
#define OPENGM_FUNCTION_TYPEDEF_MACRO