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

A sum constraint function class penalizing the violation of a given linear equality constraint. More...

#include <sum_constraint_function.hxx>

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

Public Types

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

Public Member Functions

 SumConstraintFunction ()
 SumConstraintFunction constructor. More...
 
template<class SHAPE_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
 SumConstraintFunction (SHAPE_ITERATOR_TYPE shapeBegin, SHAPE_ITERATOR_TYPE shapeEnd, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, COEFFICIENTS_ITERATOR_TYPE coefficientsEnd, const bool shareCoefficients, const ValueType lambda=1.0, const ValueType bound=0.0)
 SumConstraintFunction constructor. More...
 
template<class COEFFICIENTS_ITERATOR_TYPE >
 SumConstraintFunction (const IndexType numVariables, const LabelType numLabels, COEFFICIENTS_ITERATOR_TYPE coefficientsBegin, COEFFICIENTS_ITERATOR_TYPE coefficientsEnd, const bool shareCoefficients, const ValueType lambda=1.0, const ValueType bound=0.0)
 SumConstraintFunction constructor. More...
 
 ~SumConstraintFunction ()
 SumConstraintFunction 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< SumConstraintFunction< 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 SumConstraintFunction< 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_
 The shape of the function. Only valid if SumConstraintFunction::useSameNumLabels_ is set to false. More...
 
size_t numVariables_
 The number of variables of the function. More...
 
bool useSameNumLabels_
 Tell if each variable of the function has the same number of labels. More...
 
LabelType maxNumLabels_
 The maximum number of labels of the variables. More...
 
size_t size_
 Stores the size of the function. More...
 
std::vector< ValueTypecoefficients_
 The coefficients of the equality constraint. More...
 
bool shareCoefficients_
 Tell if the labels of the variables share the same coefficients. More...
 
std::vector< size_tcoefficientsOffsets_
 The Offsets of the SumConstraintFunction::coefficients_ indices for each variable. Only valid if SumConstraintFunction::shareCoefficients_ is set to false. More...
 
ValueType lambda_
 The scaling factor for the violation of the equality constraint. More...
 
ValueType bound_
 The bound for the equality constraint. More...
 

Detailed Description

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

A sum constraint function class penalizing the violation of a given linear equality constraint.

This class implements a sum constraint function which penalizes the violation of a linear equality constraint. The function evaluates to

\[ f(x) = |\sum c_i(x_i) - b| * \lambda \]

where $c_i(x_i)$ is the coefficient value of variable $i$ if the variable takes the label $x_i$.

Template Parameters
VALUE_TYPEValue type.
INDEX_TYPEIndex type.
LABEL_TYPELabel type.

Definition at line 20 of file sum_constraint_function.hxx.

Member Typedef Documentation

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

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

Definition at line 24 of file sum_constraint_function.hxx.

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

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

Definition at line 25 of file sum_constraint_function.hxx.

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

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

Definition at line 23 of file sum_constraint_function.hxx.

Constructor & Destructor Documentation

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

SumConstraintFunction constructor.

This constructor will create an empty SumConstraintFunction.

Definition at line 301 of file sum_constraint_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class SHAPE_ITERATOR_TYPE , class COEFFICIENTS_ITERATOR_TYPE >
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::SumConstraintFunction ( SHAPE_ITERATOR_TYPE  shapeBegin,
SHAPE_ITERATOR_TYPE  shapeEnd,
COEFFICIENTS_ITERATOR_TYPE  coefficientsBegin,
COEFFICIENTS_ITERATOR_TYPE  coefficientsEnd,
const bool  shareCoefficients,
const ValueType  lambda = 1.0,
const ValueType  bound = 0.0 
)
inline

SumConstraintFunction constructor.

This constructor will create a SumConstraintFunction where each variable can have a different number of labels.

Template Parameters
SHAPE_ITERATOR_TYPEIterator type used to iterate over the shape of the function.
COEFFICIENTS_ITERATOR_TYPEIterator type used to iterate over the coefficients 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]coefficientsBeginIterator pointing to the begin of the sequence which defines the coefficients of the linear constraint. There are two possibilities for the coefficients.
  1. For each label of each variable there has to be one coefficient. The coefficients are expected to be in the following order: $c_{0,0},...,c_{0,l_{0}-1},c_{1,0},..., c_{n-1,l_{n-1}-1}$, where $c_{i,j}$ is the coefficient for variable $i$ assigned to label $j$, $l_{i}$ is the number of labels of variable $i$ and $n$ is the number of variables of the function.
  2. The coefficients for the labels are the same for each variable. Hence there has to be one coefficient for every possible label and $c_l$ is the coefficient for label $l$.
[in]coefficientsEndIterator pointing to the end of the sequence which defines the coefficients of the linear constraint.
[in]shareCoefficientsTell if the variables share the coefficients for the labels.
[in]lambdaThe factor by which the violation of the equality constraint will be penalized.
[in]boundThe bound of the equality constraint.

Definition at line 310 of file sum_constraint_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class COEFFICIENTS_ITERATOR_TYPE >
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::SumConstraintFunction ( const IndexType  numVariables,
const LabelType  numLabels,
COEFFICIENTS_ITERATOR_TYPE  coefficientsBegin,
COEFFICIENTS_ITERATOR_TYPE  coefficientsEnd,
const bool  shareCoefficients,
const ValueType  lambda = 1.0,
const ValueType  bound = 0.0 
)
inline

SumConstraintFunction constructor.

This constructor will create a SumConstraintFunction where each variable has the same number of labels.

Template Parameters
COEFFICIENTS_ITERATOR_TYPEIterator type used to iterate over the coefficients of the function.
Parameters
[in]numVariablesThe number of variables of the SumConstraintFunction.
[in]numLabelsThe number of labels of each variable.
[in]coefficientsBeginIterator pointing to the begin of the sequence which defines the coefficients of the linear constraint. There are two possibilities for the coefficients.
  1. For each label of each variable there has to be one coefficient. The coefficients are expected to be in the following order: $c_{0,0},...,c_{0,l_{0}-1},c_{1,0},..., c_{n-1,l_{n-1}-1}$, where $c_{i,j}$ is the coefficient for variable $i$ assigned to label $j$, $l_{i}$ is the number of labels of variable $i$ and $n$ is the number of variables of the function.
  2. The coefficients for the labels are the same for each variable. Hence there has to be one coefficient for every possible label and $c_l$ is the coefficient for label $l$.
[in]coefficientsEndIterator pointing to the end of the sequence which defines the coefficients of the linear constraint.
[in]shareCoefficientsTell if the variables share the coefficients for the labels.
[in]lambdaThe factor by which the violation of the equality constraint will be penalized.
[in]boundThe bound of the equality constraint.

Definition at line 334 of file sum_constraint_function.hxx.

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

SumConstraintFunction destructor.

Definition at line 356 of file sum_constraint_function.hxx.

Member Function Documentation

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

Number of input variables.

Returns
Returns the number of variables.

Definition at line 387 of file sum_constraint_function.hxx.

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
template<class Iterator >
SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::ValueType opengm::SumConstraintFunction< 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 absolute value by which the equality constraint is violated scaled with the factor lambda ( $f(x) = |\sum c_i(x_i) - b| * \lambda$).

Definition at line 362 of file sum_constraint_function.hxx.

+ Here is the call graph for this function:

template<class VALUE_TYPE , class INDEX_TYPE , class LABEL_TYPE >
size_t opengm::SumConstraintFunction< 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 377 of file sum_constraint_function.hxx.

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

Number of parameters.

Returns
Returns the number of parameters.

Definition at line 392 of file sum_constraint_function.hxx.

Member Data Documentation

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::bound_
protected

The bound for the equality constraint.

Definition at line 53 of file sum_constraint_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::coefficients_
protected

The coefficients of the equality constraint.

Definition at line 49 of file sum_constraint_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::coefficientsOffsets_
protected

The Offsets of the SumConstraintFunction::coefficients_ indices for each variable. Only valid if SumConstraintFunction::shareCoefficients_ is set to false.

Definition at line 51 of file sum_constraint_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::lambda_
protected

The scaling factor for the violation of the equality constraint.

Definition at line 52 of file sum_constraint_function.hxx.

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

The maximum number of labels of the variables.

Definition at line 47 of file sum_constraint_function.hxx.

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

The number of variables of the function.

Definition at line 45 of file sum_constraint_function.hxx.

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

The shape of the function. Only valid if SumConstraintFunction::useSameNumLabels_ is set to false.

Definition at line 44 of file sum_constraint_function.hxx.

template<class VALUE_TYPE, class INDEX_TYPE = size_t, class LABEL_TYPE = size_t>
opengm::SumConstraintFunction< VALUE_TYPE, INDEX_TYPE, LABEL_TYPE >::shareCoefficients_
protected

Tell if the labels of the variables share the same coefficients.

Definition at line 50 of file sum_constraint_function.hxx.

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

Stores the size of the function.

Definition at line 48 of file sum_constraint_function.hxx.

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

Tell if each variable of the function has the same number of labels.

Definition at line 46 of file sum_constraint_function.hxx.