OpenGM  2.3.x
Discrete Graphical Model Library
view_convert_function.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_VIEW_CONVERT_FUNCTION_HXX
3 #define OPENGM_VIEW_CONVERT_FUNCTION_HXX
4 
6 
7 namespace opengm {
8 
10 namespace detail_convert_function {
11  template<class OPERATOR, class ACCUMULATOR, class PROBABILITY>
12  struct ValueToProbability;
13 
14  template<class PROBABILITY>
15  struct ValueToProbability<Multiplier, Maximizer, PROBABILITY>
16  {
17  typedef PROBABILITY ProbabilityType;
18  template<class T>
19  static ProbabilityType convert(const T x)
20  { return static_cast<ProbabilityType>(x); }
21  };
22 
23  template<class PROBABILITY>
24  struct ValueToProbability<Multiplier, Minimizer, PROBABILITY>
25  {
26  typedef PROBABILITY ProbabilityType;
27  template<class T>
28  static ProbabilityType convert(const T x)
29  { return static_cast<ProbabilityType>(1) / static_cast<ProbabilityType>(x); }
30  };
31 
32  template<class PROBABILITY>
33  struct ValueToProbability<Adder, Maximizer, PROBABILITY>
34  {
35  typedef PROBABILITY ProbabilityType;
36  template<class T>
37  static ProbabilityType convert(const T x)
38  { return static_cast<ProbabilityType>(std::exp(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 
55 template<class GM,class ACC,class VALUE_TYPE>
57 : public FunctionBase<ViewConvertFunction<GM,ACC,VALUE_TYPE>,
58  typename GM::ValueType, typename GM::IndexType, typename GM::LabelType>
59 {
60 public:
61  typedef VALUE_TYPE ValueType;
62  typedef VALUE_TYPE value_type;
63  typedef typename GM::FactorType FactorType;
64  typedef typename GM::OperatorType OperatorType;
65  typedef typename GM::IndexType IndexType;
66  typedef typename GM::LabelType LabelType;
67 
69  ViewConvertFunction(const FactorType &);
70  template<class Iterator> ValueType operator()(Iterator begin) const;
71  IndexType shape(const IndexType) const;
72  IndexType dimension() const;
73  IndexType size() const;
74 
75 private:
76  FactorType const* factor_;
77 };
78 
79 template<class GM,class ACC,class VALUE_TYPE>
80 inline
82 : factor_(NULL)
83 {}
84 
85 template<class GM,class ACC,class VALUE_TYPE>
86 inline
88 (
90 )
91 : factor_(&factor)
92 {}
93 
94 template<class GM,class ACC,class VALUE_TYPE>
95 template<class Iterator>
96 inline typename ViewConvertFunction<GM,ACC,VALUE_TYPE>::ValueType
97 ViewConvertFunction<GM,ACC,VALUE_TYPE>::operator()
98 (
99  Iterator begin
100 ) const {
101  return detail_convert_function::ValueToProbability<OperatorType,ACC,ValueType>::convert(factor_->operator()(begin));
102 }
103 
104 template<class GM,class ACC,class VALUE_TYPE>
107 (
109 ) const{
110  return factor_->numberOfLabels(index);
111 }
112 
113 template<class GM,class ACC,class VALUE_TYPE>
116  return factor_->numberOfVariables();
117 }
118 
119 template<class GM,class ACC,class VALUE_TYPE>
122  return factor_->size( );
123 }
124 
125 } // namespace opengm
126 
127 #endif // #ifndef OPENGM_VIEW_CONVERT_FUNCTION_HXX
The OpenGM namespace.
Definition: config.hxx:43
Fallback implementation of member functions of OpenGM functions.
ValueType operator()(Iterator begin) const
ViewConvertFunction convert semi-ring in a lazy fashion.
IndexType shape(const IndexType) const