OpenGM  2.3.x
Discrete Graphical Model Library
Public Types | Public Member Functions | List of all members
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE > Class Template Reference

Base class for linear constraint functions. More...

#include <linear_constraint_function_base.hxx>

+ Inheritance diagram for opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >:
+ Collaboration diagram for opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >:

Public Types

typedef LINEAR_CONSTRAINT_FUNCTION_TYPE LinearConstraintFunctionType
 Typedef of the LINEAR_CONSTRAINT_FUNCTION_TYPE template parameter from the class LinearConstraintFunctionBase. More...
 
typedef LinearConstraintFunctionTraits< LinearConstraintFunctionTypeLinearConstraintFunctionTraitsType
 Typedef of the LinearConstraintFunctionTraits class with appropriate template parameter. More...
 
typedef LinearConstraintFunctionTraitsType::ValueType ValueType
 Typedef of the value type used by the linear constraint function. More...
 
typedef LinearConstraintFunctionTraitsType::IndexType IndexType
 Typedef of the index type used by the linear constraint function. More...
 
typedef LinearConstraintFunctionTraitsType::LabelType LabelType
 Typedef of the label type used by the linear constraint function. More...
 
typedef LinearConstraintFunctionTraitsType::LinearConstraintType LinearConstraintType
 Typedef of the linear constraint type used by the linear constraint function. More...
 
typedef LinearConstraintFunctionTraitsType::LinearConstraintsIteratorType LinearConstraintsIteratorType
 Typedef of the linear constraints iterator type used by the linear constraint function to iterate over the set of linear constraints. More...
 
typedef LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsIteratorType ViolatedLinearConstraintsIteratorType
 Typedef of the violated linear constraints iterator type used by the linear constraint function to iterate over the set of violated linear constraints. More...
 
typedef LinearConstraintFunctionTraitsType::ViolatedLinearConstraintsWeightsIteratorType ViolatedLinearConstraintsWeightsIteratorType
 Typedef of the violated linear constraints weights iterator type used by the linear constraint function to iterate over the weights of the violated linear constraints. More...
 
typedef LinearConstraintFunctionTraitsType::IndicatorVariablesIteratorType IndicatorVariablesIteratorType
 Typedef of the indicator variables iterator type used by the linear constraint function to iterate over the indicator variables. More...
 
- Public Types inherited from opengm::FunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndexType, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LabelType >
typedef AccessorIterator< FunctionShapeAccessorType, true > FunctionShapeIteratorType
 

Public Member Functions

LinearConstraintsIteratorType linearConstraintsBegin () const
 Get the begin iterator to the set of linear constraints represented by the linear constraint function. More...
 
LinearConstraintsIteratorType linearConstraintsEnd () const
 Get the end iterator to the set of linear constraints represented by the linear constraint function. More...
 
IndicatorVariablesIteratorType indicatorVariablesOrderBegin () const
 Get the begin iterator to the set of indicator variables used by the linear constraint function. More...
 
IndicatorVariablesIteratorType indicatorVariablesOrderEnd () const
 Get the end iterator to the set of indicator variables used by the linear constraint function. More...
 
template<class LABEL_ITERATOR >
void challenge (ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
 Challenge the linear constraint function and get all linear constraints which are violated by a given labeling. More...
 
template<class LABEL_ITERATOR >
void challengeRelaxed (ViolatedLinearConstraintsIteratorType &violatedConstraintsBegin, ViolatedLinearConstraintsIteratorType &violatedConstraintsEnd, ViolatedLinearConstraintsWeightsIteratorType &violatedConstraintsWeightsBegin, LABEL_ITERATOR labelingBegin, const ValueType tolerance=0.0) const
 Challenge the linear constraint function and get all linear constraints which are violated by a given labeling. More...
 
bool isLinearConstraint () const
 Function specialization for each linear constraint function. More...
 
- Public Member Functions inherited from opengm::FunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndexType, LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LabelType >
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< LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType > 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 LINEAR_CONSTRAINT_FUNCTION_TYPE &) const
 
FunctionShapeIteratorType functionShapeBegin () const
 
FunctionShapeIteratorType functionShapeEnd () const
 
size_t numberOfWeights () const
 
LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndexType weightIndex (const size_t weightNumber) const
 
void setWeights (const opengm::learning::Weights< LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType > &) const
 
LinearConstraintFunctionTraits< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType weightGradient (size_t, ITERATOR) const
 

Detailed Description

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
class opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >

Base class for linear constraint functions.

This class defines a base class for all linear constraint functions. It uses the curiously recurring template pattern (CRTP) to provide static polymorphism. It defines the interface which can be used to access the linear constraints which are defined by a linear constraint function.

Template Parameters
LINEAR_CONSTRAINT_FUNCTION_TYPEThe child class which inherits from LinearConstraintFunctionBase and thus defines a linear constraint function.
Note
A template specialization of class LinearConstraintFunctionTraits has to be defined for each class which inherits from LinearConstraintFunctionBase.

Definition at line 22 of file linear_constraint_function_base.hxx.

Member Typedef Documentation

§ IndexType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndexType

Typedef of the index type used by the linear constraint function.

Definition at line 28 of file linear_constraint_function_base.hxx.

§ IndicatorVariablesIteratorType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndicatorVariablesIteratorType

Typedef of the indicator variables iterator type used by the linear constraint function to iterate over the indicator variables.

Definition at line 34 of file linear_constraint_function_base.hxx.

§ LabelType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LabelType

Typedef of the label type used by the linear constraint function.

Definition at line 29 of file linear_constraint_function_base.hxx.

§ LinearConstraintFunctionTraitsType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintFunctionTraitsType

Typedef of the LinearConstraintFunctionTraits class with appropriate template parameter.

Definition at line 26 of file linear_constraint_function_base.hxx.

§ LinearConstraintFunctionType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintFunctionType

Typedef of the LINEAR_CONSTRAINT_FUNCTION_TYPE template parameter from the class LinearConstraintFunctionBase.

Definition at line 25 of file linear_constraint_function_base.hxx.

§ LinearConstraintsIteratorType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintsIteratorType

Typedef of the linear constraints iterator type used by the linear constraint function to iterate over the set of linear constraints.

Definition at line 31 of file linear_constraint_function_base.hxx.

§ LinearConstraintType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintType

Typedef of the linear constraint type used by the linear constraint function.

Definition at line 30 of file linear_constraint_function_base.hxx.

§ ValueType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ValueType

Typedef of the value type used by the linear constraint function.

Definition at line 27 of file linear_constraint_function_base.hxx.

§ ViolatedLinearConstraintsIteratorType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ViolatedLinearConstraintsIteratorType

Typedef of the violated linear constraints iterator type used by the linear constraint function to iterate over the set of violated linear constraints.

Definition at line 32 of file linear_constraint_function_base.hxx.

§ ViolatedLinearConstraintsWeightsIteratorType

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE>
opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::ViolatedLinearConstraintsWeightsIteratorType

Typedef of the violated linear constraints weights iterator type used by the linear constraint function to iterate over the weights of the violated linear constraints.

Definition at line 33 of file linear_constraint_function_base.hxx.

Member Function Documentation

§ challenge()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
template<class LABEL_ITERATOR >
void opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::challenge ( ViolatedLinearConstraintsIteratorType violatedConstraintsBegin,
ViolatedLinearConstraintsIteratorType violatedConstraintsEnd,
ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin,
LABEL_ITERATOR  labelingBegin,
const ValueType  tolerance = 0.0 
) const
inline

Challenge the linear constraint function and get all linear constraints which are violated by a given labeling.

This function returns all linear constraints which are violated by a given labeling, furthermore it returns the weights telling how much each constraint is violated. It uses only the labeling for the first order variables of the function to evaluate the indicator variables of the function. Hence it is not qualified to challenge the liner function against a relaxed labeling where each indicator variable can take values in the range [0.0, 1.0]. Use LinearConstraintFunctionBase::challengeRelaxed for this case.

Template Parameters
LABEL_ITERATORIterator type to iterate over the labels for the variables.
Parameters
[out]violatedConstraintsBeginIterator pointing to the begin of the set of violated constraints.
[out]violatedConstraintsEndIterator pointing to the end of the set of violated constraints.
[out]violatedConstraintsWeightsBeginIterator pointing to the begin of the weights for the set of violated constraints.
[in]labelingBeginIterator pointing to the begin of the labeling for the first order variables.
[in]toleranceThe tolerance value defines how much a constraint is allowed to be violated without returning it as a violated constraint.
Warning
All iterators returned by this function are only guaranteed to be valid until the next call to the functions LinearConstraintFunctionBase::challenge or LinearConstraintFunctionBase::challengeRelaxed.

Definition at line 279 of file linear_constraint_function_base.hxx.

§ challengeRelaxed()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
template<class LABEL_ITERATOR >
void opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::challengeRelaxed ( ViolatedLinearConstraintsIteratorType violatedConstraintsBegin,
ViolatedLinearConstraintsIteratorType violatedConstraintsEnd,
ViolatedLinearConstraintsWeightsIteratorType violatedConstraintsWeightsBegin,
LABEL_ITERATOR  labelingBegin,
const ValueType  tolerance = 0.0 
) const
inline

Challenge the linear constraint function and get all linear constraints which are violated by a given labeling.

This function returns all linear constraints which are violated by a given labeling, furthermore it returns the weights telling how much each constraint is violated. Unlike the LinearConstraintFunctionBase::challenge function it takes the labeling for all indicator variables into account and therefore is capable of dealing with a relaxed labeling where each indicator variable can take values in the range [0.0, 1.0]. The order of the relaxed labeling for the indicator variables has to follow the order which is given by the iterators returned from indicatorVariablesOrderBegin() and indicatorVariablesOrderEnd().

Template Parameters
LABEL_ITERATORIterator type to iterate over the relaxed labeling for the indicator variables.
Parameters
[out]violatedConstraintsBeginIterator pointing to the begin of the set of violated constraints.
[out]violatedConstraintsEndIterator pointing to the end of the set of violated constraints.
[out]violatedConstraintsWeightsBeginIterator pointing to the begin of the weights for the set of violated constraints.
[in]labelingBeginIterator pointing to the begin of the relaxed labeling for each indicator variable.
[in]toleranceThe tolerance value defines how much a constraint is allowed to be violated without returning it as a violated constraint.
Warning
All iterators returned by this function are only guaranteed to be valid until the next call to the functions LinearConstraintFunctionBase::challenge or LinearConstraintFunctionBase::challengeRelaxed.

Definition at line 285 of file linear_constraint_function_base.hxx.

§ indicatorVariablesOrderBegin()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndicatorVariablesIteratorType opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::indicatorVariablesOrderBegin ( ) const
inline

Get the begin iterator to the set of indicator variables used by the linear constraint function.

Returns
The const iterator pointing to the begin of the set of indicator variables.

Definition at line 268 of file linear_constraint_function_base.hxx.

§ indicatorVariablesOrderEnd()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::IndicatorVariablesIteratorType opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::indicatorVariablesOrderEnd ( ) const
inline

Get the end iterator to the set of indicator variables used by the linear constraint function.

Returns
The const iterator pointing to the end of the set of indicator variables.

Definition at line 273 of file linear_constraint_function_base.hxx.

§ isLinearConstraint()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
bool opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::isLinearConstraint ( ) const
inline

Function specialization for each linear constraint function.

Returns
Returns always true as every function which inherits from LinearConstraintFunctionBase is a linear constraint function.

Definition at line 290 of file linear_constraint_function_base.hxx.

§ linearConstraintsBegin()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintsIteratorType opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::linearConstraintsBegin ( ) const
inline

Get the begin iterator to the set of linear constraints represented by the linear constraint function.

Returns
The const iterator pointing to the begin of the set of linear constraints.

Definition at line 258 of file linear_constraint_function_base.hxx.

§ linearConstraintsEnd()

template<class LINEAR_CONSTRAINT_FUNCTION_TYPE >
LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::LinearConstraintsIteratorType opengm::LinearConstraintFunctionBase< LINEAR_CONSTRAINT_FUNCTION_TYPE >::linearConstraintsEnd ( ) const
inline

Get the end iterator to the set of linear constraints represented by the linear constraint function.

Returns
The const iterator pointing to the end of the set of linear constraints.

Definition at line 263 of file linear_constraint_function_base.hxx.