aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
gum::LinearApproximationPolicy< GUM_ELEMENT > Class Template Referenceabstract

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

#include <linearApproximationPolicy.h>

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

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Detailed Description

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

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_ELEMENTThe type used for computations.

Definition at line 76 of file linearApproximationPolicy.h.

Constructor & Destructor Documentation

◆ LinearApproximationPolicy() [1/2]

template<typename GUM_ELEMENT>
gum::LinearApproximationPolicy< GUM_ELEMENT >::LinearApproximationPolicy ( GUM_ELEMENT low = (GUM_ELEMENT)0.0,
GUM_ELEMENT high = (GUM_ELEMENT)1.0,
GUM_ELEMENT eps = (GUM_ELEMENT)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 59 of file linearApproximationPolicy_tpl.h.

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

References gum::ApproximationPolicy< GUM_ELEMENT >::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_ELEMENT>
gum::LinearApproximationPolicy< GUM_ELEMENT >::LinearApproximationPolicy ( const LinearApproximationPolicy< GUM_ELEMENT > * md)

Copy constructor.

Parameters
mdThe gum::LinearApproximationPolicy to copy.

Definition at line 70 of file linearApproximationPolicy_tpl.h.

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

Here is the call graph for this function:

Member Function Documentation

◆ _decode_()

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

Concretely computes the approximate value from representation.

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

Definition at line 400 of file linearApproximationPolicy_tpl.h.

400 {
401 if (representation == 0) return this->lowLimit_;
402
403 if (representation == nbInterval_) return this->highLimit_;
404
405 return (GUM_ELEMENT)(((representation * this->epsilon_) - (this->epsilon_ / 2))
406 + this->lowLimit_);
407 }

References epsilon_, highLimit_, lowLimit_, and nbInterval_.

Referenced by decode(), and fromExact().

Here is the caller graph for this function:

◆ _encode_()

template<typename GUM_ELEMENT>
Idx gum::LinearApproximationPolicy< GUM_ELEMENT >::_encode_ ( const GUM_ELEMENT & 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_ELEMENT&).
Parameters
valueThe value to encode.
Returns
The encoded value.

Definition at line 389 of file linearApproximationPolicy_tpl.h.

389 {
390 if (value <= this->lowLimit_) return 0;
391
392 if (value >= this->highLimit_) return nbInterval_;
393
394 return 1 + Idx(((value - this->lowLimit_) / this->epsilon_));
395 }
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() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineAdd ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using addition with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineAdd() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineAdd ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using addition with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 83 of file linearApproximationPolicy_tpl.h.

84 {
85 try {
87 = dynamic_cast< const LinearApproximationPolicy< GUM_ELEMENT >* >(ap);
88
91
93
95
97
99
101
103
105
107
109
110 this->lowLimit_ = newLowLimit;
111 this->highLimit_ = newHighLimit;
113 } catch (const std::bad_cast&) {}
114 }
LinearApproximationPolicy(GUM_ELEMENT low=(GUM_ELEMENT) 0.0, GUM_ELEMENT high=(GUM_ELEMENT) 1.0, GUM_ELEMENT eps=(GUM_ELEMENT) 0.1)
Default constructor.
const GUM_ELEMENT & highLimit() const
Gets Highest possible value.
const GUM_ELEMENT & lowLimit() const
Gets lowest possible value.

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineDiv() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineDiv ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using division with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineDiv() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineDiv ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using division with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 185 of file linearApproximationPolicy_tpl.h.

186 {
187 try {
189 = dynamic_cast< const LinearApproximationPolicy< GUM_ELEMENT >* >(ap);
190
193
195
197
199
201
203
205
207
209
211
212 this->lowLimit_ = newLowLimit;
213 this->highLimit_ = newHighLimit;
215 } catch (const std::bad_cast&) {}
216 }

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMax() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineMax ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using max with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineMax() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineMax ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using max with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 219 of file linearApproximationPolicy_tpl.h.

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMin() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineMin ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using min with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineMin() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineMin ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using min with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 253 of file linearApproximationPolicy_tpl.h.

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineMult() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineMult ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using multiplication with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineMult() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineMult ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using multiplication with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 151 of file linearApproximationPolicy_tpl.h.

152 {
153 try {
155 = dynamic_cast< const LinearApproximationPolicy< GUM_ELEMENT >* >(ap);
156
159
161
163
165
167
169
171
173
175
177
178 this->lowLimit_ = newLowLimit;
179 this->highLimit_ = newHighLimit;
181 } catch (const std::bad_cast&) {}
182 }

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ combineSub() [1/2]

virtual void gum::ApproximationPolicy< GUM_SCALAR >::combineSub ( const ApproximationPolicy< GUM_SCALAR > * ap)
pure virtualinherited

Combine using subtraction with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

◆ combineSub() [2/2]

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::combineSub ( const ApproximationPolicy< GUM_ELEMENT > * ap)
override

Combine using subtraction with the given gum::ApproximationPolicy.

Parameters
apThe policy to combine with.

Definition at line 117 of file linearApproximationPolicy_tpl.h.

118 {
119 try {
121 = dynamic_cast< const LinearApproximationPolicy< GUM_ELEMENT >* >(ap);
122
125
127
129
131
133
135
137
139
141
143
144 this->lowLimit_ = newLowLimit;
145 this->highLimit_ = newHighLimit;
147 } catch (const std::bad_cast&) {}
148 }

References LinearApproximationPolicy(), computeNbInterval_(), highLimit(), highLimit_, lowLimit(), and lowLimit_.

Here is the call graph for this function:

◆ computeNbInterval_()

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

Get the number of interval.

Definition at line 411 of file linearApproximationPolicy_tpl.h.

411 {
412 nbInterval_ = 1 + Idx((this->highLimit_ - this->lowLimit_) / this->epsilon_);
413 }

References epsilon_, highLimit_, lowLimit_, and nbInterval_.

Referenced by LinearApproximationPolicy(), combineAdd(), combineDiv(), combineMax(), combineMin(), combineMult(), combineSub(), setEpsilon(), setHighLimit(), setLimits(), and setLowLimit().

Here is the caller graph for this function:

◆ decode()

template<typename GUM_ELEMENT>
GUM_ELEMENT gum::LinearApproximationPolicy< GUM_ELEMENT >::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 322 of file linearApproximationPolicy_tpl.h.

322 {
324 GUM_ERROR(OutOfBounds, "Interval Number asked is higher than total number of interval")
325 }
326
328 }
GUM_ELEMENT _decode_(const GUM_ELEMENT &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_ELEMENT>
Idx gum::LinearApproximationPolicy< GUM_ELEMENT >::encode ( const GUM_ELEMENT & 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 301 of file linearApproximationPolicy_tpl.h.

301 {
302// we keep the bounds checked in debug mode
303#ifdef GUM_DEBUG_MODE
304 if (value > this->highLimit_) {
306 "Value asked is higher than High limit : not in (" << this->lowLimit_ << "-"
307 << this->highLimit_ << ")")
308 }
309
312 "Value asked is lower than low limit : not in (" << this->lowLimit_ << "-"
313 << this->highLimit_ << ")")
314 }
315
316#endif // GUM_DEBUG_MODE
317 return _encode_(value);
318 }
Idx _encode_(const GUM_ELEMENT &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() [1/2]

virtual GUM_SCALAR gum::ApproximationPolicy< GUM_SCALAR >::fromExact ( const GUM_SCALAR & value) const
pure virtualinherited

Convert value to his approximation.

This method, at least in release mode, should not verify the limits

Parameters
valueThe converted value.
Returns
The value approximation representation.

◆ fromExact() [2/2]

template<typename GUM_ELEMENT>
GUM_ELEMENT gum::LinearApproximationPolicy< GUM_ELEMENT >::fromExact ( const GUM_ELEMENT & value) const
override

Convert value to his approximation.

Parameters
valueThe converted value.
Returns
The value approximation representation.

Definition at line 77 of file linearApproximationPolicy_tpl.h.

77 {
79 }
Idx encode(const GUM_ELEMENT &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_ELEMENT>
const GUM_ELEMENT & gum::LinearApproximationPolicy< GUM_ELEMENT >::highLimit ( ) const

Gets Highest possible value.

Returns
Returns the highest possible value.

Definition at line 383 of file linearApproximationPolicy_tpl.h.

383 {
384 return highLimit_;
385 }

References highLimit_.

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

Here is the caller graph for this function:

◆ lowLimit()

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

Gets lowest possible value.

Returns
Returns the lowest possible value.

Definition at line 365 of file linearApproximationPolicy_tpl.h.

365 {
366 return lowLimit_;
367 }

References lowLimit_.

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

Here is the caller graph for this function:

◆ safeFromExact()

template<typename GUM_ELEMENT>
GUM_ELEMENT gum::LinearApproximationPolicy< GUM_ELEMENT >::safeFromExact ( const GUM_ELEMENT & 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 289 of file linearApproximationPolicy_tpl.h.

289 {
290 if (value > this->highLimit_) {
291 GUM_ERROR(OutOfBounds, "Value asked is higher than high limit")
292 }
293
294 if (value < this->lowLimit_) { GUM_ERROR(OutOfBounds, "Value asked is lower than low limit") }
295
296 return fromExact(value);
297 }
GUM_ELEMENT fromExact(const GUM_ELEMENT &value) const override
Convert value to his approximation.

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

Here is the call graph for this function:

◆ setEpsilon()

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

Sets approximation factor.

Parameters
eThe new epsilon value.

Definition at line 332 of file linearApproximationPolicy_tpl.h.

332 {
333 if (e <= 0) { GUM_ERROR(OutOfBounds, "Epsilon must be >0") }
334 epsilon_ = e;
336 }

References computeNbInterval_(), epsilon_, and GUM_ERROR.

Here is the call graph for this function:

◆ setHighLimit()

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

Sets Highest possible value.

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

Definition at line 371 of file linearApproximationPolicy_tpl.h.

371 {
373 GUM_ERROR(OutOfBounds, "Value asked is lower than low limit")
374 }
375
377
379 }

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

Here is the call graph for this function:

◆ setLimits()

template<typename GUM_ELEMENT>
void gum::LinearApproximationPolicy< GUM_ELEMENT >::setLimits ( const GUM_ELEMENT & newLowLimit,
const GUM_ELEMENT & 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 340 of file linearApproximationPolicy_tpl.h.

341 {
343 GUM_ERROR(OutOfBounds, "Asked low value is higher than asked high value")
344 }
345
349 }

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

Here is the call graph for this function:

◆ setLowLimit()

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

Sets lowest possible value.

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

Definition at line 353 of file linearApproximationPolicy_tpl.h.

353 {
354 if (newLowLimit > this->highLimit_) {
355 GUM_ERROR(OutOfBounds, "Value asked is higher than High limit")
356 }
357
359
361 }

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

Here is the call graph for this function:

Member Data Documentation

◆ epsilon_

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

◆ highLimit_

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

◆ lowLimit_

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

◆ nbInterval_

template<typename GUM_ELEMENT>
Idx gum::LinearApproximationPolicy< GUM_ELEMENT >::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: