1 #ifndef OPENGM_LABEL_COST_FUNCTION_HXX_ 2 #define OPENGM_LABEL_COST_FUNCTION_HXX_ 16 template<
class FUNCTION_TYPE,
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
19 template<
class VALUE_TYPE,
class INDEX_TYPE =
size_t,
class LABEL_TYPE =
size_t>
29 template <
class SHAPE_ITERATOR_TYPE,
class COST_ITERATOR_TYPE>
30 LabelCostFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, COST_ITERATOR_TYPE costsBegin, COST_ITERATOR_TYPE costsEnd);
31 template <
class SHAPE_ITERATOR_TYPE>
32 LabelCostFunction(SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd,
const LabelType label,
const ValueType cost);
33 template <
class COST_ITERATOR_TYPE>
34 LabelCostFunction(
const IndexType numVariables,
const LabelType numLabels, COST_ITERATOR_TYPE costsBegin, COST_ITERATOR_TYPE costsEnd);
35 LabelCostFunction(
const IndexType numVariables,
const LabelType numLabels,
const LabelType label,
const ValueType cost);
39 template<
class Iterator>
40 ValueType
operator()(Iterator statesBegin)
const;
41 size_t shape(
const size_t i)
const;
64 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
73 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
80 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
82 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
284 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
291 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
292 template <
class SHAPE_ITERATOR_TYPE,
class COST_ITERATOR_TYPE>
297 size_(
std::
accumulate(shapeBegin, shapeEnd, 1,
std::multiplies<typename
std::iterator_traits<SHAPE_ITERATOR_TYPE>::value_type>())),
303 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
304 template <
class SHAPE_ITERATOR_TYPE>
309 size_(
std::
accumulate(shapeBegin, shapeEnd, 1,
std::multiplies<typename
std::iterator_traits<SHAPE_ITERATOR_TYPE>::value_type>())),
314 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
315 template <
class COST_ITERATOR_TYPE>
325 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
334 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
339 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
340 template<
class Iterator>
353 while(statesBegin != statesEnd) {
354 const LabelType currentLabel = *statesBegin;
356 if(!labelIsUsed[currentLabel]) {
357 labelIsUsed[currentLabel] =
true;
359 result +=
costs_[currentLabel];
370 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
380 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
385 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
391 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
393 const size_t dimensionSize = 1;
394 const size_t useSameNumLabelsSize = 1;
396 const size_t useSingleCostSize = 1;
397 const size_t costsSize = 1;
399 const size_t totalIndexSize = dimensionSize + useSameNumLabelsSize +
400 shapeSize + useSingleCostSize + costsSize;
401 return totalIndexSize;
404 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
408 const size_t totalValueSize = costsSize;
409 return totalValueSize;
412 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
413 template<
class INDEX_OUTPUT_ITERATOR,
class VALUE_OUTPUT_ITERATOR>
429 for(
size_t i = 0; i < src.
dimension(); ++i) {
430 *indexOutIterator = src.
shape_[i];
441 *indexOutIterator = src.
costs_.size();
449 for(
size_t i = 0; i < src.
costs_.size(); ++i) {
450 *valueOutIterator = src.
costs_[i];
456 template<
class VALUE_TYPE,
class INDEX_TYPE,
class LABEL_TYPE>
457 template<
class INDEX_INPUT_ITERATOR,
class VALUE_INPUT_ITERATOR>
461 const size_t dimension = *indexInIterator;
465 const bool useSameNumLabels = *indexInIterator == 1 ?
true :
false;
469 INDEX_INPUT_ITERATOR shapeBegin = indexInIterator;
470 INDEX_INPUT_ITERATOR shapeEnd = indexInIterator + (useSameNumLabels ? 1 :
dimension);
471 indexInIterator += (useSameNumLabels ? 1 :
dimension);
474 const bool useSingleCost = *indexInIterator == 1 ?
true :
false;
476 const size_t costsSize = *indexInIterator;
480 VALUE_INPUT_ITERATOR costsBegin = valueInIterator;
481 VALUE_INPUT_ITERATOR costsEnd = valueInIterator + costsSize;
483 if(useSameNumLabels) {
LABEL_TYPE LabelType
Typedef of the LABEL_TYPE template parameter type from the class LabelCostFunction.
Fallback implementation of member functions of OpenGM functions.
Provides implementation for the power function of unsigned integer values.
size_t unsignedIntegerPow(size_t base, size_t exponent)
Unsigned integer power function.
#define OPENGM_ASSERT(expression)
A label cost function class penalizing the usage of labels.
IndexType numVariables_
Storage for the number of variables of the function.
std::vector< LabelType > shape_
Storage for the shape of the function which is used if all variables can have different numbers of la...
ValueType singleCost_
Storage for cost of the single label which has label costs. Is only used when useSingleCost_ is set t...
Default implementation for class opengm::LPFunctionTransfer.
~LabelCostFunction()
LabelCostFunction destructor.
INDEX_TYPE IndexType
Typedef of the INDEX_TYPE template parameter type from the class LabelCostFunction.
ReturnType accumulate() const
accumulate all values of the function
std::vector< ValueType > costs_
Storage for the label costs which is used if all labels can have label costs.
bool useSameNumLabels_
Indicator to tell if all variables have the same number of labels.
size_t shape(const size_t i) const
Number of labels of the indicated input variable.
const size_t FUNCTION_TYPE_ID_OFFSET
User-defined function have ids smaller than FUNCTION_TYPE_ID_OFFSET.
LabelCostFunction()
LabelCostFunction constructor.
bool useSingleCost_
Indicator to tell if only a single label has label costs.
LabelType maxNumLabels_
Storage for the maximum number of labels of the function.
VALUE_TYPE ValueType
Typedef of the VALUE_TYPE template parameter type from the class LabelCostFunction.
ValueType operator()(Iterator statesBegin) const
Function evaluation.
size_t size_
Stores the size of the label cost function.
LabelType singleLabel_
Storage for the single label which has label costs. Is only used when useSingleCost_ is set to true...
size_t dimension() const
Number of input variables.
size_t size() const
Number of parameters.