aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::LinearApproximationPolicy< GUM_SCALAR > Class Template Reference

Class implementing linear approximation policy (meaning possible value are split out in interval). More...

#include <linearApproximationPolicy.h>

Inheritance diagram for gum::LinearApproximationPolicy< GUM_SCALAR >:
Collaboration diagram for gum::LinearApproximationPolicy< GUM_SCALAR >:

Public Member Functions

Constructors / Destructors
 LinearApproximationPolicy (GUM_SCALAR low=(GUM_SCALAR) 0.0, GUM_SCALAR high=(GUM_SCALAR) 1.0, GUM_SCALAR eps=(GUM_SCALAR) 0.1)
 Default constructor.
 LinearApproximationPolicy (const LinearApproximationPolicy< GUM_SCALAR > *md)
 Copy constructor.
Accessors/Modifiers
GUM_SCALAR fromExact (const GUM_SCALAR &value) const
 Convert value to his approximation.
void combineAdd (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using addition with the given gum::ApproximationPolicy.
void combineSub (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using substraction with the given gum::ApproximationPolicy.
void combineMult (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using multiplication with the given gum::ApproximationPolicy.
void combineDiv (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using division with the given gum::ApproximationPolicy.
void combineMax (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using max with the given gum::ApproximationPolicy.
void combineMin (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using min with the given gum::ApproximationPolicy.
GUM_SCALAR safeFromExact (const GUM_SCALAR &value)
 Convert value to his approximation.
Idx encode (const GUM_SCALAR &value) const
 Encode a given value into its approximation representation.
GUM_SCALAR decode (Idx representation) const
 Convert approximation representation to value.
virtual void setEpsilon (const GUM_SCALAR &e)
 Sets approximation factor.
virtual void setLimits (const GUM_SCALAR &newLowLimit, const GUM_SCALAR &newHighLimit)
 Set bounds in a whole.
virtual void setLowLimit (const GUM_SCALAR &newLowLimit)
 Sets lowest possible value.
const GUM_SCALAR & lowLimit () const
 Gets lowest possible value.
virtual void setHighLimit (const GUM_SCALAR &newHighLimit)
 Sets Highest possible value.
const GUM_SCALAR & highLimit () const
 Gets Highest possible value.

Protected Member Functions

Idx _encode_ (const GUM_SCALAR &value) const
 Concretely computes the approximate representation.
GUM_SCALAR _decode_ (const GUM_SCALAR &representation) const
 Concretely computes the approximate value from representation.
void computeNbInterval_ ()
 Get the number of interval.

Protected Attributes

GUM_SCALAR lowLimit_
 Lowest value possible.
GUM_SCALAR highLimit_
 Highest value possible.
GUM_SCALAR epsilon_
 Approximation factor.
Idx nbInterval_
 The number of interval.

Detailed Description

template<typename GUM_SCALAR>
class gum::LinearApproximationPolicy< GUM_SCALAR >

Class implementing linear approximation policy (meaning possible value are split out in interval).

Warning
Doxygen does not like spanning command on multiple line, so we could not configure it with the correct include directive. Use the following code snippet to include this file.
Classes used to practice approximation on value.
Template Parameters
GUM_SCALARThe type used for computations.

Definition at line 76 of file linearApproximationPolicy.h.

Constructor & Destructor Documentation

◆ LinearApproximationPolicy() [1/2]

template<typename GUM_SCALAR>
gum::LinearApproximationPolicy< GUM_SCALAR >::LinearApproximationPolicy ( GUM_SCALAR low = (GUM_SCALAR)0.0,
GUM_SCALAR high = (GUM_SCALAR)1.0,
GUM_SCALAR eps = (GUM_SCALAR)0.1 )

Default constructor.

Parameters
lowThe lower limit.
highThe higher limit.
epsThe epsilon.
Exceptions
OutOfBoundsif out of bounds (low<high, eps>0)

Definition at line 58 of file linearApproximationPolicy_tpl.h.

60 :
62 if (eps <= 0) { GUM_ERROR(OutOfBounds, "Epsilon must be >0") }
63
65 }
ApproximationPolicy()
Default constructor.
Class implementing linear approximation policy (meaning possible value are split out in interval).
GUM_SCALAR highLimit_
Highest value possible.
void computeNbInterval_()
Get the number of interval.
GUM_SCALAR lowLimit_
Lowest value possible.
GUM_SCALAR epsilon_
Approximation factor.
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), computeNbInterval_(), epsilon_, GUM_ERROR, highLimit_, and lowLimit_.

Referenced by LinearApproximationPolicy(), combineAdd(), combineDiv(), combineMax(), combineMin(), combineMult(), and combineSub().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LinearApproximationPolicy() [2/2]

template<typename GUM_SCALAR>
gum::LinearApproximationPolicy< GUM_SCALAR >::LinearApproximationPolicy ( const LinearApproximationPolicy< GUM_SCALAR > * md)

Copy constructor.

Parameters
mdThe gum::LinearApproximationPolicy to copy.

Definition at line 69 of file linearApproximationPolicy_tpl.h.

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), epsilon_, and nbInterval_.

Here is the call graph for this function:

Member Function Documentation

◆ _decode_()

template<typename GUM_SCALAR>
INLINE GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::_decode_ ( const GUM_SCALAR & representation) const
protected

Concretely computes the approximate value from representation.

Parameters
representationThe approximate value to decode.
Returns
The decoded value.

Definition at line 376 of file linearApproximationPolicy_tpl.h.

376 {
377 if (representation == 0) return this->lowLimit_;
378
379 if (representation == nbInterval_) return this->highLimit_;
380
381 return (GUM_SCALAR)(((representation * this->epsilon_) - (this->epsilon_ / 2))
382 + this->lowLimit_);
383 }

References epsilon_, highLimit_, lowLimit_, and nbInterval_.

Referenced by decode(), and fromExact().

Here is the caller graph for this function:

◆ _encode_()

template<typename GUM_SCALAR>
INLINE Idx gum::LinearApproximationPolicy< GUM_SCALAR >::_encode_ ( const GUM_SCALAR & value) const
protected

Concretely computes the approximate representation.

Warning
We accept value smaller or higher than limits : please
See also
gum::ApproximationPolicy::safeFromExact(const GUM_SCALAR&).
Parameters
valueThe value to encode.
Returns
The encoded value.

Definition at line 365 of file linearApproximationPolicy_tpl.h.

365 {
366 if (value <= this->lowLimit_) return 0;
367
368 if (value >= this->highLimit_) return nbInterval_;
369
370 return 1 + Idx(((value - this->lowLimit_) / this->epsilon_));
371 }
Size Idx
Type for indexes.
Definition types.h:79

References epsilon_, highLimit_, lowLimit_, and nbInterval_.

Referenced by encode().

Here is the caller graph for this function:

◆ combineAdd()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineAdd ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using addition with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 82 of file linearApproximationPolicy_tpl.h.

83 {
84 try {
86 = dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
87
90
92
94
96
98
100
102
104
106
108 } catch (const std::bad_cast&) {}
109 }
const GUM_SCALAR & highLimit() const
Gets Highest possible value.
const GUM_SCALAR & lowLimit() const
Gets lowest possible value.
LinearApproximationPolicy(GUM_SCALAR low=(GUM_SCALAR) 0.0, GUM_SCALAR high=(GUM_SCALAR) 1.0, GUM_SCALAR eps=(GUM_SCALAR) 0.1)
Default constructor.

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineDiv()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineDiv ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using division with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 172 of file linearApproximationPolicy_tpl.h.

173 {
174 try {
176 = dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
177
180
182
184
186
188
190
192
194
196
198 } catch (const std::bad_cast&) {}
199 }

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMax()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineMax ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using max with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 202 of file linearApproximationPolicy_tpl.h.

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMin()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineMin ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using min with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 232 of file linearApproximationPolicy_tpl.h.

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMult()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineMult ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using multiplication with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 142 of file linearApproximationPolicy_tpl.h.

143 {
144 try {
146 = dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
147
150
152
154
156
158
160
162
164
166
168 } catch (const std::bad_cast&) {}
169 }

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineSub()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::combineSub ( const ApproximationPolicy< GUM_SCALAR > * ap)
virtual

Combine using substraction with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 112 of file linearApproximationPolicy_tpl.h.

113 {
114 try {
116 = dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
117
120
122
124
126
128
130
132
134
136
138 } catch (const std::bad_cast&) {}
139 }

References gum::ApproximationPolicy< GUM_SCALAR >::ApproximationPolicy(), LinearApproximationPolicy(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ computeNbInterval_()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::computeNbInterval_ ( )
protected

Get the number of interval.

Definition at line 387 of file linearApproximationPolicy_tpl.h.

387 {
388 nbInterval_ = 1 + Idx((this->highLimit_ - this->lowLimit_) / this->epsilon_);
389 }

References epsilon_, highLimit_, lowLimit_, and nbInterval_.

Referenced by LinearApproximationPolicy(), setEpsilon(), setHighLimit(), setLimits(), and setLowLimit().

Here is the caller graph for this function:

◆ decode()

template<typename GUM_SCALAR>
INLINE GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::decode ( Idx representation) const

Convert approximation representation to value.

Parameters
representationThe approximation representation to decode.
Returns
Returns the value decoded from its approximation reprensentation.

Definition at line 298 of file linearApproximationPolicy_tpl.h.

298 {
300 GUM_ERROR(OutOfBounds, "Interval Number asked is higher than total number of interval")
301 }
302
304 }
GUM_SCALAR _decode_(const GUM_SCALAR &representation) const
Concretely computes the approximate value from representation.

References _decode_(), GUM_ERROR, and nbInterval_.

Here is the call graph for this function:

◆ encode()

template<typename GUM_SCALAR>
INLINE Idx gum::LinearApproximationPolicy< GUM_SCALAR >::encode ( const GUM_SCALAR & value) const

Encode a given value into its approximation representation.

Parameters
valueThe to encode.
Returns
Returns the encoded value.
Exceptions
OutOfBoundsRaised if value is out of bounds.
OutOfBoundsRaised if value is out of bounds.

Definition at line 277 of file linearApproximationPolicy_tpl.h.

277 {
278// we keep the bounds checked in debug mode
279#ifdef GUM_DEBUG_MODE
280 if (value > this->highLimit_) {
282 "Value asked is higher than High limit : not in (" << this->lowLimit_ << "-"
283 << this->highLimit_ << ")")
284 }
285
288 "Value asked is lower than low limit : not in (" << this->lowLimit_ << "-"
289 << this->highLimit_ << ")")
290 }
291
292#endif // GUM_DEBUG_MODE
293 return _encode_(value);
294 }
Idx _encode_(const GUM_SCALAR &value) const
Concretely computes the approximate representation.

References _encode_(), GUM_ERROR, highLimit_, and lowLimit_.

Referenced by fromExact().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromExact()

template<typename GUM_SCALAR>
INLINE GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::fromExact ( const GUM_SCALAR & value) const
virtual

Convert value to his approximation.

Parameters
valueThe converted value.
Returns
The value approximation representation.

Implements gum::ApproximationPolicy< GUM_SCALAR >.

Definition at line 76 of file linearApproximationPolicy_tpl.h.

76 {
78 }
Idx encode(const GUM_SCALAR &value) const
Encode a given value into its approximation representation.

References _decode_(), and encode().

Referenced by safeFromExact().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ highLimit()

template<typename GUM_SCALAR>
INLINE const GUM_SCALAR & gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit ( ) const

Gets Highest possible value.

Returns
Returns the highest possible value.

Definition at line 359 of file linearApproximationPolicy_tpl.h.

359 {
360 return highLimit_;
361 }

References highLimit_.

Referenced by combineAdd(), combineDiv(), combineMax(), combineMin(), combineMult(), and combineSub().

Here is the caller graph for this function:

◆ lowLimit()

template<typename GUM_SCALAR>
INLINE const GUM_SCALAR & gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit ( ) const

Gets lowest possible value.

Returns
Returns the lowest possible value.

Definition at line 340 of file linearApproximationPolicy_tpl.h.

340 {
341 return lowLimit_;
342 }

References lowLimit_.

Referenced by combineAdd(), combineDiv(), combineMax(), combineMin(), combineMult(), and combineSub().

Here is the caller graph for this function:

◆ safeFromExact()

template<typename GUM_SCALAR>
INLINE GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::safeFromExact ( const GUM_SCALAR & value)

Convert value to his approximation.

This method is slower than fromExact since it verifies the bounds.

Exceptions
OutOfBoundsRaised if value is out of bounds.
OutOfBoundsRaised if value is out of bounds.

Definition at line 265 of file linearApproximationPolicy_tpl.h.

265 {
266 if (value > this->highLimit_) {
267 GUM_ERROR(OutOfBounds, "Value asked is higher than high limit")
268 }
269
270 if (value < this->lowLimit_) { GUM_ERROR(OutOfBounds, "Value asked is lower than low limit") }
271
272 return fromExact(value);
273 }
GUM_SCALAR fromExact(const GUM_SCALAR &value) const
Convert value to his approximation.

References fromExact(), GUM_ERROR, highLimit_, and lowLimit_.

Here is the call graph for this function:

◆ setEpsilon()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::setEpsilon ( const GUM_SCALAR & e)
virtual

Sets approximation factor.

Parameters
eThe new epsilon value.

Definition at line 308 of file linearApproximationPolicy_tpl.h.

308 {
309 epsilon_ = e;
311 }

References computeNbInterval_(), and epsilon_.

Here is the call graph for this function:

◆ setHighLimit()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::setHighLimit ( const GUM_SCALAR & newHighLimit)
virtual

Sets Highest possible value.

Parameters
newHighLimitNew higher bound.
Exceptions
OutOfBoundsRaised if out of bound.

Definition at line 347 of file linearApproximationPolicy_tpl.h.

347 {
349 GUM_ERROR(OutOfBounds, "Value asked is lower than low limit")
350 }
351
353
355 }

References computeNbInterval_(), GUM_ERROR, highLimit_, and lowLimit_.

Here is the call graph for this function:

◆ setLimits()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::setLimits ( const GUM_SCALAR & newLowLimit,
const GUM_SCALAR & newHighLimit )
virtual

Set bounds in a whole.

Parameters
newLowLimitNew lower bound.
newHighLimitNew higher bound.
Exceptions
OutOfBoundsRaised if new bounds are not legit.

Definition at line 315 of file linearApproximationPolicy_tpl.h.

316 {
318 GUM_ERROR(OutOfBounds, "Asked low value is higher than asked high value")
319 }
320
324 }

References computeNbInterval_(), GUM_ERROR, highLimit_, and lowLimit_.

Here is the call graph for this function:

◆ setLowLimit()

template<typename GUM_SCALAR>
INLINE void gum::LinearApproximationPolicy< GUM_SCALAR >::setLowLimit ( const GUM_SCALAR & newLowLimit)
virtual

Sets lowest possible value.

Parameters
newLowLimitNew lower bound.
Exceptions
OutOfBoundsRaised if out of bound.

Definition at line 328 of file linearApproximationPolicy_tpl.h.

328 {
329 if (newLowLimit > this->highLimit_) {
330 GUM_ERROR(OutOfBounds, "Value asked is higher than High limit")
331 }
332
334
336 }

References computeNbInterval_(), GUM_ERROR, highLimit_, and lowLimit_.

Here is the call graph for this function:

Member Data Documentation

◆ epsilon_

template<typename GUM_SCALAR>
GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::epsilon_
protected

◆ highLimit_

template<typename GUM_SCALAR>
GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit_
protected

◆ lowLimit_

template<typename GUM_SCALAR>
GUM_SCALAR gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit_
protected

◆ nbInterval_

template<typename GUM_SCALAR>
Idx gum::LinearApproximationPolicy< GUM_SCALAR >::nbInterval_
protected

The number of interval.

Definition at line 256 of file linearApproximationPolicy.h.

Referenced by LinearApproximationPolicy(), _decode_(), _encode_(), computeNbInterval_(), and decode().


The documentation for this class was generated from the following files: