2 #ifndef OPENGM_TRUNCATED_SQUARED_DIFFERENCE_FUNCTION_HXX
3 #define OPENGM_TRUNCATED_SQUARED_DIFFERENCE_FUNCTION_HXX
14 template<
class T,
class I =
size_t,
class L =
size_t>
16 :
public FunctionBase<TruncatedSquaredDifferenceFunction<T, I, L>, T, I, L> {
24 size_t shape(
const IndexType)
const;
27 template<
class ITERATOR> T
operator()(ITERATOR)
const;
30 size_t numberOfLabels1_;
31 size_t numberOfLabels2_;
32 ValueType parameter1_;
33 ValueType parameter2_;
40 template <
class T,
class I,
class L>
48 template <
class T,
class I,
class L>
49 class FunctionSerialization<TruncatedSquaredDifferenceFunction<T, I, L> > {
51 typedef typename TruncatedSquaredDifferenceFunction<T, I, L>::ValueType ValueType;
52 static size_t indexSequenceSize(
const TruncatedSquaredDifferenceFunction<T, I, L>&);
53 static size_t valueSequenceSize(
const TruncatedSquaredDifferenceFunction<T, I, L>&);
54 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR >
55 static void serialize(
const TruncatedSquaredDifferenceFunction<T, I, L>&, INDEX_OUTPUT_ITERATOR,VALUE_OUTPUT_ITERATOR);
56 template<
class INDEX_INPUT_ITERATOR ,
class VALUE_INPUT_ITERATOR>
57 static void deserialize( INDEX_INPUT_ITERATOR,VALUE_INPUT_ITERATOR,TruncatedSquaredDifferenceFunction<T, I, L>&);
64 template <
class T,
class I,
class L>
68 const LabelType numberOfLabels1,
69 const LabelType numberOfLabels2,
70 const ValueType truncation,
71 const ValueType weight
73 : numberOfLabels1_(numberOfLabels1),
74 numberOfLabels2_(numberOfLabels2),
75 parameter1_(truncation),
79 template <
class T,
class I,
class L>
80 template <
class ITERATOR>
86 ValueType value = begin[0];
88 return value * value > parameter1_ ? parameter1_* parameter2_ : value * value * parameter2_;
94 template <
class T,
class I,
class L>
100 return i==0 ? numberOfLabels1_ : numberOfLabels2_;
104 template <
class T,
class I,
class L>
111 template <
class T,
class I,
class L>
114 return numberOfLabels1_ * numberOfLabels2_;
117 template <
class T,
class I,
class L>
126 template <
class T,
class I,
class L>
128 FunctionSerialization<TruncatedSquaredDifferenceFunction<T, I, L> >::valueSequenceSize
130 const TruncatedSquaredDifferenceFunction<T, I, L>& src
135 template <
class T,
class I,
class L>
136 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR >
138 FunctionSerialization<TruncatedSquaredDifferenceFunction<T, I, L> >::serialize
140 const TruncatedSquaredDifferenceFunction<T, I, L>& src,
141 INDEX_OUTPUT_ITERATOR indexOutIterator,
142 VALUE_OUTPUT_ITERATOR valueOutIterator
144 *indexOutIterator = src.shape(0);
146 *indexOutIterator = src.shape(1);
148 *valueOutIterator = src.parameter1_;
150 *valueOutIterator = src.parameter2_;
153 template <
class T,
class I,
class L>
154 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR >
156 FunctionSerialization< TruncatedSquaredDifferenceFunction<T, I, L> >::deserialize
158 INDEX_INPUT_ITERATOR indexInIterator,
159 VALUE_INPUT_ITERATOR valueInIterator,
160 TruncatedSquaredDifferenceFunction<T, I, L>& dst
162 const size_t shape1=*indexInIterator;
164 const size_t shape2=*indexInIterator;
165 const ValueType param1=*valueInIterator;
167 const ValueType param2=*valueInIterator;
168 dst=TruncatedSquaredDifferenceFunction<T, I, L>(shape1,shape2,param1,param2);
173 #endif // OPENGM_TRUNCATED_SQUARED_DIFFERENCE_FUNCTION_HXX
Fallback implementation of member functions of OpenGM functions.
#define OPENGM_ASSERT(expression)
T operator()(ITERATOR) const
size_t shape(const IndexType) const
extension a value table encoding this function would have
size_t size() const
number of entries a value table encoding this function would have (used for I/O)
TruncatedSquaredDifferenceFunction(const LabelType=2, const LabelType=2, const ValueType=ValueType(), const ValueType=ValueType())
Constructor.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
truncated squared difference of the labels of two variables