/usr/include/opengm/functions/l_potts.hxx is in libopengm-dev 2.3.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | #pragma once
#ifndef OPENGM_L_POTTS_FUNCTION_HXX
#define OPENGM_L_POTTS_FUNCTION_HXX
#include <algorithm>
#include <vector>
#include <cmath>
#include "opengm/opengm.hxx"
#include "opengm/functions/function_registration.hxx"
#include "opengm/functions/function_properties_base.hxx"
namespace opengm {
/// Potts function for two variables
///
/// \ingroup functions
template<class T, class I = size_t, class L = size_t>
class LPottsFunction
: public FunctionBase<LPottsFunction<T, I, L>, T, I, L>
{
public:
typedef T ValueType;
typedef L LabelType;
typedef I IndexType;
LPottsFunction(
const LabelType,
const LabelType,
const Parameters<ValueType,IndexType> & parameters,
const IndexType valueNotEqual
);
LabelType shape(const size_t) const;
size_t size() const;
size_t dimension() const;
template<class ITERATOR> ValueType operator()(ITERATOR) const;
bool operator==(const LPottsFunction& ) const;
// specializations
bool isPotts() const;
bool isGeneralizedPotts() const;
ValueType min() const;
ValueType max() const;
ValueType sum() const;
ValueType product() const;
MinMaxFunctor<ValueType> minMax() const;
// parameters
size_t numberOfParameters()const{
return 1;
}
IndexType parameterIndex(const size_t paramNumber)const{
return piValueNotEqual_;
}
private:
LabelType numberOfLabels1_;
LabelType numberOfLabels2_;
const Parameters<ValueType,IndexType> * params_;
IndexType piValueNotEqual_;
friend class FunctionSerialization<LPottsFunction<T, I, L> > ;
};
template<class T, class I, class L>
struct FunctionRegistration<LPottsFunction<T, I, L> > {
enum ID {
Id = opengm::FUNCTION_TYPE_ID_OFFSET + 100 + 6
};
};
template <class T, class I, class L>
inline
LPottsFunction<T, I, L>::LPottsFunction
(
const L numberOfLabels1,
const L numberOfLabels2,
const Parameters<ValueType,IndexType> & parameters,
const IndexType valueNotEqual
)
: numberOfLabels1_(numberOfLabels1),
numberOfLabels2_(numberOfLabels2),
params_(¶meters),
piValueNotEqual_(valueNotEqual)
{}
template <class T, class I, class L>
template <class ITERATOR>
inline T
LPottsFunction<T, I, L>::operator()
(
ITERATOR begin
) const {
return (begin[0]==begin[1] ?
static_cast<ValueType>(0.0) : params_->getParameter(piValueNotEqual_) );
}
template <class T, class I, class L>
inline L
LPottsFunction<T, I, L>::shape
(
const size_t i
) const {
OPENGM_ASSERT(i < 2);
return (i==0 ? numberOfLabels1_ : numberOfLabels2_);
}
template <class T, class I, class L>
inline size_t
LPottsFunction<T, I, L>::dimension() const {
return 2;
}
template <class T, class I, class L>
inline size_t
LPottsFunction<T, I, L>::size() const {
return numberOfLabels1_*numberOfLabels2_;
}
template<class T, class I, class L>
inline bool
LPottsFunction<T, I, L>::operator==
(
const LPottsFunction & fb
)const{
return numberOfLabels1_ == fb.numberOfLabels1_ &&
numberOfLabels2_ == fb.numberOfLabels2_ &&
piValueNotEqual_ == fb.piValueNotEqual_;
}
template<class T, class I, class L>
inline bool
LPottsFunction<T, I, L>::isPotts() const
{
return true;
}
template<class T, class I, class L>
inline bool
LPottsFunction<T, I, L>::isGeneralizedPotts() const
{
return true;
}
template<class T, class I, class L>
inline typename LPottsFunction<T, I, L>::ValueType
LPottsFunction<T, I, L>::min() const
{
const T val = params_->getParameter(piValueNotEqual_);
return 0.0<val ? 0.0 :val;
}
template<class T, class I, class L>
inline typename LPottsFunction<T, I, L>::ValueType
LPottsFunction<T, I, L>::max() const
{
const T val = params_->getParameter(piValueNotEqual_);
return 0.0>val ? 0.0 :val;
}
template<class T, class I, class L>
inline typename LPottsFunction<T, I, L>::ValueType
LPottsFunction<T, I, L>::sum() const
{
const T val = params_->getParameter(piValueNotEqual_);
const LabelType minLabels = std::min(numberOfLabels1_, numberOfLabels2_);
return val * static_cast<T>(numberOfLabels1_ * numberOfLabels2_ - minLabels);
}
template<class T, class I, class L>
inline typename LPottsFunction<T, I, L>::ValueType
LPottsFunction<T, I, L>::product() const
{
return static_cast<ValueType>(0);
}
template<class T, class I, class L>
inline MinMaxFunctor<typename LPottsFunction<T, I, L>::ValueType>
LPottsFunction<T, I, L>::minMax() const
{
if(static_cast<ValueType>(0) < piValueNotEqual_) {
return MinMaxFunctor<T>(static_cast<ValueType>(0), params_[piValueNotEqual_]);
}
else {
return MinMaxFunctor<T>(params_[piValueNotEqual_], static_cast<ValueType>(0));
}
}
} // namespace opengm
#endif // #ifndef OPENGM_L_POTTS_FUNCTION_HXX
|