2 #ifndef OPENGM_VIEW_CONVERT_FUNCTION_HXX
3 #define OPENGM_VIEW_CONVERT_FUNCTION_HXX
10 namespace detail_convert_function {
11 template<
class OPERATOR,
class ACCUMULATOR,
class PROBABILITY>
12 struct ValueToProbability;
14 template<
class PROBABILITY>
15 struct ValueToProbability<Multiplier, Maximizer, PROBABILITY>
17 typedef PROBABILITY ProbabilityType;
19 static ProbabilityType convert(
const T x)
20 {
return static_cast<ProbabilityType
>(x); }
23 template<
class PROBABILITY>
24 struct ValueToProbability<Multiplier, Minimizer, PROBABILITY>
26 typedef PROBABILITY ProbabilityType;
28 static ProbabilityType convert(
const T x)
29 {
return static_cast<ProbabilityType
>(1) / static_cast<ProbabilityType>(x); }
32 template<
class PROBABILITY>
33 struct ValueToProbability<Adder, Maximizer, PROBABILITY>
35 typedef PROBABILITY ProbabilityType;
37 static ProbabilityType convert(
const T x)
38 {
return static_cast<ProbabilityType
>(std::exp(x)); }
41 template<
class PROBABILITY>
42 struct ValueToProbability<Adder, Minimizer, PROBABILITY>
44 typedef PROBABILITY ProbabilityType;
46 static ProbabilityType convert(
const T x)
47 {
return static_cast<ProbabilityType
>(std::exp(-x)); }
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>
70 template<
class Iterator> ValueType
operator()(Iterator begin)
const;
71 IndexType
shape(
const IndexType)
const;
73 IndexType
size()
const;
76 FactorType
const* factor_;
79 template<
class GM,
class ACC,
class VALUE_TYPE>
85 template<
class GM,
class ACC,
class VALUE_TYPE>
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()
101 return detail_convert_function::ValueToProbability<OperatorType,ACC,ValueType>::convert(factor_->operator()(begin));
104 template<
class GM,
class ACC,
class VALUE_TYPE>
110 return factor_->numberOfLabels(index);
113 template<
class GM,
class ACC,
class VALUE_TYPE>
116 return factor_->numberOfVariables();
119 template<
class GM,
class ACC,
class VALUE_TYPE>
122 return factor_->size( );
127 #endif // #ifndef OPENGM_VIEW_CONVERT_FUNCTION_HXX
IndexType dimension() const
Fallback implementation of member functions of OpenGM functions.
ValueType operator()(Iterator begin) const
ViewConvertFunction convert semi-ring in a lazy fashion.
GM::FactorType FactorType
GM::OperatorType OperatorType
IndexType shape(const IndexType) const