OpenGM  2.3.x
Discrete Graphical Model Library
Public Types | Public Member Functions | Protected Attributes | List of all members
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > Class Template Reference

A label cost function class penalizing the usage of labels. More...

#include <label_cost_function.hxx>

+ Inheritance diagram for opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >:
+ Collaboration diagram for opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >:

Public Types

typedef VALUE_TYPE ValueType
 Typedef of the VALUE_TYPE template parameter type from the class LabelCostFunction. More...
 
typedef INDEX_TYPE IndexType
 Typedef of the INDEX_TYPE template parameter type from the class LabelCostFunction. More...
 
typedef LABEL_TYPE LabelType
 Typedef of the LABEL_TYPE template parameter type from the class LabelCostFunction. More...
 
- Public Types inherited from opengm::FunctionBase< LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >
typedef AccessorIterator< FunctionShapeAccessorType, true > FunctionShapeIteratorType
 

Public Member Functions

 LabelCostFunction ()
 LabelCostFunction constructor. More...
 
template<class SHAPE_ITERATOR_TYPE , class COST_ITERATOR_TYPE >
 LabelCostFunction (SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, COST_ITERATOR_TYPE costsBegin, COST_ITERATOR_TYPE costsEnd)
 LabelCostFunction constructor. More...
 
template<class SHAPE_ITERATOR_TYPE >
 LabelCostFunction (SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, const LabelType label, const ValueType cost)
 LabelCostFunction constructor. More...
 
template<class COST_ITERATOR_TYPE >
 LabelCostFunction (const IndexType numVariables, const LabelType numLabels, COST_ITERATOR_TYPE costsBegin, COST_ITERATOR_TYPE costsEnd)
 LabelCostFunction constructor. More...
 
 LabelCostFunction (const IndexType numVariables, const LabelType numLabels, const LabelType label, const ValueType cost)
 LabelCostFunction constructor. More...
 
 ~LabelCostFunction ()
 LabelCostFunction destructor. More...
 
template<class Iterator >
ValueType operator() (Iterator statesBegin) const
 Function evaluation. More...
 
size_t shape (const size_t i) const
 Number of labels of the indicated input variable. More...
 
size_t dimension () const
 Number of input variables. More...
 
size_t size () const
 Number of parameters. More...
 
- Public Member Functions inherited from opengm::FunctionBase< LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >, VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >
bool isPotts () const
 
bool isGeneralizedPotts () const
 
bool isSubmodular () const
 
bool isSquaredDifference () const
 
bool isTruncatedSquaredDifference () const
 
bool isAbsoluteDifference () const
 
bool isTruncatedAbsoluteDifference () const
 
bool isLinearConstraint () const
 
MinMaxFunctor< VALUE_TYPE > minMax () const
 find minimum and maximum of the function in a single sweep More...
 
ReturnType min () const
 
ReturnType max () const
 
ReturnType sum () const
 
ReturnType product () const
 
ReturnType accumulate () const
 accumulate all values of the function More...
 
void forAllValuesInOrder (FUNCTOR &functor) const
 call a functor for each value of the function (in lexicographical order of the variable indices) More...
 
void forAllValuesInSwitchedOrder (FUNCTOR &functor) const
 
void forAllValuesInAnyOrder (FUNCTOR &functor) const
 call a functor for each value of the function (in un-specified order) More...
 
void forAtLeastAllUniqueValues (FUNCTOR &functor) const
 call a functor for at least all unique values of the function More...
 
void forAllValuesInOrderWithCoordinate (COORDINATE_FUNCTOR &functor) const
 
void forAllValuesInAnyOrderWithCoordinate (COORDINATE_FUNCTOR &functor) const
 
void forAtLeastAllUniqueValuesWithCoordinate (COORDINATE_FUNCTOR &functor) const
 
bool operator== (const LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE > &) const
 
FunctionShapeIteratorType functionShapeBegin () const
 
FunctionShapeIteratorType functionShapeEnd () const
 
size_t numberOfParameters () const
 
INDEX_TYPE parameterIndex (const size_t paramNumber) const
 

Protected Attributes

std::vector< LabelTypeshape_
 Storage for the shape of the function which is used if all variables can have different numbers of labels. More...
 
IndexType numVariables_
 Storage for the number of variables of the function. More...
 
LabelType maxNumLabels_
 Storage for the maximum number of labels of the function. More...
 
bool useSameNumLabels_
 Indicator to tell if all variables have the same number of labels. More...
 
size_t size_
 Stores the size of the label cost function. More...
 
std::vector< ValueTypecosts_
 Storage for the label costs which is used if all labels can have label costs. More...
 
bool useSingleCost_
 Indicator to tell if only a single label has label costs. More...
 
LabelType singleLabel_
 Storage for the single label which has label costs. Is only used when useSingleCost_ is set to true. More...
 
ValueType singleCost_
 Storage for cost of the single label which has label costs. Is only used when useSingleCost_ is set to true. More...
 

Detailed Description

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
class opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >

A label cost function class penalizing the usage of labels.

This class implements a label cost function which penalizes the usage of labels.

\[ f(x) = \sum_{l = 0}^{ l < n} c_{l}(x), \]

where $c_{l}(x)$ is the cost of label $l$ if $l$ is used in $x$ and zero otherwise. The function supports to assign each label a different cost or to set a cost for one label while all other costs are treated as zero.

Template Parameters
VALUE_TYPEValue type.
INDEX_TYPEIndex type.
LABEL_TYPELabel type.

Definition at line 20 of file label_cost_function.hxx.

Member Typedef Documentation

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::IndexType

Typedef of the INDEX_TYPE template parameter type from the class LabelCostFunction.

Definition at line 24 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelType

Typedef of the LABEL_TYPE template parameter type from the class LabelCostFunction.

Definition at line 25 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::ValueType

Typedef of the VALUE_TYPE template parameter type from the class LabelCostFunction.

Definition at line 23 of file label_cost_function.hxx.

Constructor & Destructor Documentation

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelCostFunction ( )
inline

LabelCostFunction constructor.

This constructor will create an empty LabelCostFunction.

Definition at line 285 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class SHAPE_ITERATOR_TYPE , class COST_ITERATOR_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelCostFunction ( SHAPE_ITERATOR_TYPE  shapeBegin,
SHAPE_ITERATOR_TYPE  shapeEnd,
COST_ITERATOR_TYPE  costsBegin,
COST_ITERATOR_TYPE  costsEnd 
)
inline

LabelCostFunction constructor.

This constructor will create a LabelCostFunction where each variable can have a different number of labels and where a cost value is set for each label.

Template Parameters
SHAPE_ITERATOR_TYPEIterator type used to iterate over the shape of the function.
COST_ITERATOR_TYPEIterator type used to iterate over the costs for each label.
Parameters
[in]shapeBeginIterator pointing to the begin of the sequence which defines the shape of the function.
[in]shapeEndIterator pointing to the end of the sequence which defines the shape of the function.
[in]costsBeginIterator pointing to the begin of the sequence of the costs for each label.
[in]costsEndIterator pointing to the end of the sequence of the costs for each label.

Definition at line 293 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class SHAPE_ITERATOR_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelCostFunction ( SHAPE_ITERATOR_TYPE  shapeBegin,
SHAPE_ITERATOR_TYPE  shapeEnd,
const LabelType  label,
const ValueType  cost 
)
inline

LabelCostFunction constructor.

This constructor will create a LabelCostFunction where each variable can have a different number of labels and where a cost value is set for exactly one label while the costs for each other label will be treated as zero.

Template Parameters
SHAPE_ITERATOR_TYPEIterator type used to iterate over the shape of the function.
Parameters
[in]shapeBeginIterator pointing to the begin of the sequence which defines the shape of the function.
[in]shapeEndIterator pointing to the end of the sequence which defines the shape of the function.
[in]labelThe label for which a cost is set.
[in]costThe cost which is used for the selected label.

Definition at line 305 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class COST_ITERATOR_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelCostFunction ( const IndexType  numVariables,
const LabelType  numLabels,
COST_ITERATOR_TYPE  costsBegin,
COST_ITERATOR_TYPE  costsEnd 
)
inline

LabelCostFunction constructor.

This constructor will create a LabelCostFunction where each variable has the same number of labels and where a cost value is set for each label.

Template Parameters
COST_ITERATOR_TYPEIterator type used to iterate over the costs for each label.
Parameters
[in]numVariablesThe number of variables of the function.
[in]numLabelsThe number of labels for each variable of the function.
[in]costsBeginIterator pointing to the begin of the sequence of the costs for each label.
[in]costsEndIterator pointing to the end of the sequence of the costs for each label.

Definition at line 316 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::LabelCostFunction ( const IndexType  numVariables,
const LabelType  numLabels,
const LabelType  label,
const ValueType  cost 
)
inline

LabelCostFunction constructor.

This constructor will create a LabelCostFunction where each variable has the same number of labels and where a cost value is set for exactly one label while the costs for each other label will be treated as zero.

Parameters
[in]numVariablesThe number of variables of the function.
[in]numLabelsThe number of labels for each variable of the function.
[in]labelThe label for which a cost is set.
[in]costThe cost which is used for the selected label.

Definition at line 326 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::~LabelCostFunction ( )
inline

LabelCostFunction destructor.

Definition at line 335 of file label_cost_function.hxx.

Member Function Documentation

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
size_t opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::dimension ( ) const
inline

Number of input variables.

Returns
Returns the number of variables.

Definition at line 381 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class Iterator >
LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::ValueType opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::operator() ( Iterator  statesBegin) const
inline

Function evaluation.

Template Parameters
IteratorIterator type
Parameters
[in]statesBeginIterator pointing to the begin of a sequence of labels for the variables of the function.
Returns
The sum of the costs of the labels which are used in the states sequence.

Definition at line 341 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
size_t opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::shape ( const size_t  i) const
inline

Number of labels of the indicated input variable.

Parameters
[in]iIndex of the variable.
Returns
Returns the number of labels of the i-th variable.

Definition at line 371 of file label_cost_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
size_t opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::size ( ) const
inline

Number of parameters.

Returns
Returns the number of parameters.

Definition at line 386 of file label_cost_function.hxx.

Member Data Documentation

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::costs_
protected

Storage for the label costs which is used if all labels can have label costs.

Definition at line 52 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::maxNumLabels_
protected

Storage for the maximum number of labels of the function.

Definition at line 49 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::numVariables_
protected

Storage for the number of variables of the function.

Definition at line 48 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::shape_
protected

Storage for the shape of the function which is used if all variables can have different numbers of labels.

Definition at line 47 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::singleCost_
protected

Storage for cost of the single label which has label costs. Is only used when useSingleCost_ is set to true.

Definition at line 55 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::singleLabel_
protected

Storage for the single label which has label costs. Is only used when useSingleCost_ is set to true.

Definition at line 54 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::size_
protected

Stores the size of the label cost function.

Definition at line 51 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::useSameNumLabels_
protected

Indicator to tell if all variables have the same number of labels.

Definition at line 50 of file label_cost_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::LabelCostFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::useSingleCost_
protected

Indicator to tell if only a single label has label costs.

Definition at line 53 of file label_cost_function.hxx.