aGrUM  0.16.0
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. More...
 
 LinearApproximationPolicy (const LinearApproximationPolicy< GUM_SCALAR > *md)
 Copy constructor. More...
 
Accessors/Modifiers
GUM_SCALAR fromExact (const GUM_SCALAR &value) const
 Convert value to his approximation. More...
 
void combineAdd (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using addition with the given gum::ApproximationPolicy. More...
 
void combineSub (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using substraction with the given gum::ApproximationPolicy. More...
 
void combineMult (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using multiplication with the given gum::ApproximationPolicy. More...
 
void combineDiv (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using division with the given gum::ApproximationPolicy. More...
 
void combineMax (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using max with the given gum::ApproximationPolicy. More...
 
void combineMin (const ApproximationPolicy< GUM_SCALAR > *ap)
 Combine using min with the given gum::ApproximationPolicy. More...
 
GUM_SCALAR safeFromExact (const GUM_SCALAR &value)
 Convert value to his approximation. More...
 
Idx encode (const GUM_SCALAR &value) const
 Encode a given value into its approximation representation. More...
 
GUM_SCALAR decode (Idx representation) const
 Convert approximation representation to value. More...
 
virtual void setEpsilon (const GUM_SCALAR &e)
 Sets approximation factor. More...
 
virtual void setLimits (const GUM_SCALAR &newLowLimit, const GUM_SCALAR &newHighLimit)
 Set bounds in a whole. More...
 
virtual void setLowLimit (const GUM_SCALAR &newLowLimit)
 Sets lowest possible value. More...
 
const GUM_SCALAR & lowLimit () const
 Gets lowest possible value. More...
 
virtual void setHighLimit (const GUM_SCALAR &newHighLimit)
 Sets Highest possible value. More...
 
const GUM_SCALAR & highLimit () const
 Gets Highest possible value. More...
 

Protected Attributes

GUM_SCALAR _lowLimit
 Lowest value possible. More...
 
GUM_SCALAR _highLimit
 Highest value possible. More...
 
GUM_SCALAR _epsilon
 Approximation factor. More...
 
Idx _nbInterval
 The number of interval. More...
 

Protected Member Functions

Idx __encode (const GUM_SCALAR &value) const
 Concretely computes the approximate representation. More...
 
GUM_SCALAR __decode (const GUM_SCALAR &representation) const
 Concretely computes the approximate value from representation. More...
 
void _computeNbInterval ()
 Get the number of interval. More...
 

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.
Template Parameters
GUM_SCALARThe type used for computations.

Definition at line 55 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
OutOfBoundif out of bounds (low<high, eps>0)

Definition at line 38 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_computeNbInterval(), and GUM_ERROR.

39  :
40  ApproximationPolicy< GUM_SCALAR >(),
41  _lowLimit(low), _highLimit(high), _epsilon(eps) {
42  if (eps <= 0) { GUM_ERROR(OutOfBounds, "Epsilon must be >0"); }
43 
45  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _epsilon
Approximation factor.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void _computeNbInterval()
Get the number of interval.
+ Here is the call 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 49 of file linearApproximationPolicy_tpl.h.

50  :
51  ApproximationPolicy< GUM_SCALAR >(md),
52  _epsilon(md->_epsilon), _nbInterval(md->_nbInterval) {}
GUM_SCALAR _epsilon
Approximation factor.
Idx _nbInterval
The number of interval.

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 373 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_epsilon, gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and gum::LinearApproximationPolicy< GUM_SCALAR >::_nbInterval.

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::decode(), and gum::LinearApproximationPolicy< GUM_SCALAR >::fromExact().

374  {
375  if (representation == 0) return this->_lowLimit;
376 
377  if (representation == _nbInterval) return this->_highLimit;
378 
379  return (GUM_SCALAR)(((representation * this->_epsilon) - (this->_epsilon / 2))
380  + this->_lowLimit);
381  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _epsilon
Approximation factor.
GUM_SCALAR _highLimit
Highest value possible.
Idx _nbInterval
The number of interval.
+ 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 362 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_epsilon, gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and gum::LinearApproximationPolicy< GUM_SCALAR >::_nbInterval.

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::encode().

363  {
364  if (value <= this->_lowLimit) return 0;
365 
366  if (value >= this->_highLimit) return _nbInterval;
367 
368  return 1 + Idx(((value - this->_lowLimit) / this->_epsilon));
369  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _epsilon
Approximation factor.
GUM_SCALAR _highLimit
Highest value possible.
Idx _nbInterval
The number of interval.
Size Idx
Type for indexes.
Definition: types.h:53
+ Here is the caller graph for this function:

◆ _computeNbInterval()

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

◆ 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 64 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

65  {
66  try {
67  const LinearApproximationPolicy< GUM_SCALAR >* lap =
68  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
69 
70  GUM_SCALAR newHighLimit = _lowLimit + lap->lowLimit();
71  GUM_SCALAR newLowLimit = _lowLimit + lap->lowLimit();
72 
73  GUM_SCALAR newVal = _lowLimit + lap->highLimit();
74 
75  if (newHighLimit < newVal) newHighLimit = newVal;
76 
77  if (newLowLimit > newVal) newLowLimit = newVal;
78 
79  newVal = _highLimit + lap->lowLimit();
80 
81  if (newHighLimit < newVal) newHighLimit = newVal;
82 
83  if (newLowLimit > newVal) newLowLimit = newVal;
84 
85  newVal = _highLimit + lap->highLimit();
86 
87  if (newHighLimit < newVal) newHighLimit = newVal;
88 
89  if (newLowLimit > newVal) newLowLimit = newVal;
90  } catch (const std::bad_cast&) {}
91  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ 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 154 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

155  {
156  try {
157  const LinearApproximationPolicy< GUM_SCALAR >* lap =
158  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
159 
160  GUM_SCALAR newHighLimit = _lowLimit / lap->lowLimit();
161  GUM_SCALAR newLowLimit = _lowLimit / lap->lowLimit();
162 
163  GUM_SCALAR newVal = _lowLimit / lap->highLimit();
164 
165  if (newHighLimit < newVal) newHighLimit = newVal;
166 
167  if (newLowLimit > newVal) newLowLimit = newVal;
168 
169  newVal = _highLimit / lap->lowLimit();
170 
171  if (newHighLimit < newVal) newHighLimit = newVal;
172 
173  if (newLowLimit > newVal) newLowLimit = newVal;
174 
175  newVal = _highLimit / lap->highLimit();
176 
177  if (newHighLimit < newVal) newHighLimit = newVal;
178 
179  if (newLowLimit > newVal) newLowLimit = newVal;
180  } catch (const std::bad_cast&) {}
181  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ 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 184 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

185  {
186  try {
187  const LinearApproximationPolicy< GUM_SCALAR >* lap =
188  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
189 
190  GUM_SCALAR newHighLimit =
191  _lowLimit > lap->lowLimit() ? _lowLimit : lap->lowLimit();
192  GUM_SCALAR newLowLimit =
193  _lowLimit > lap->lowLimit() ? _lowLimit : lap->lowLimit();
194 
195  GUM_SCALAR newVal =
196  _lowLimit > lap->highLimit() ? _lowLimit : lap->highLimit();
197 
198  if (newHighLimit < newVal) newHighLimit = newVal;
199 
200  if (newLowLimit > newVal) newLowLimit = newVal;
201 
202  newVal = _highLimit > lap->lowLimit() ? _highLimit : lap->lowLimit();
203 
204  if (newHighLimit < newVal) newHighLimit = newVal;
205 
206  if (newLowLimit > newVal) newLowLimit = newVal;
207 
208  newVal = _highLimit > lap->highLimit() ? _highLimit : lap->highLimit();
209 
210  if (newHighLimit < newVal) newHighLimit = newVal;
211 
212  if (newLowLimit > newVal) newLowLimit = newVal;
213  } catch (const std::bad_cast&) {}
214  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ 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 217 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

218  {
219  try {
220  const LinearApproximationPolicy< GUM_SCALAR >* lap =
221  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
222 
223  GUM_SCALAR newHighLimit =
224  _lowLimit < lap->lowLimit() ? _lowLimit : lap->lowLimit();
225  GUM_SCALAR newLowLimit =
226  _lowLimit < lap->lowLimit() ? _lowLimit : lap->lowLimit();
227 
228  GUM_SCALAR newVal =
229  _lowLimit < lap->highLimit() ? _lowLimit : lap->highLimit();
230 
231  if (newHighLimit < newVal) newHighLimit = newVal;
232 
233  if (newLowLimit > newVal) newLowLimit = newVal;
234 
235  newVal = _highLimit < lap->lowLimit() ? _highLimit : lap->lowLimit();
236 
237  if (newHighLimit < newVal) newHighLimit = newVal;
238 
239  if (newLowLimit > newVal) newLowLimit = newVal;
240 
241  newVal = _highLimit < lap->highLimit() ? _highLimit : lap->highLimit();
242 
243  if (newHighLimit < newVal) newHighLimit = newVal;
244 
245  if (newLowLimit > newVal) newLowLimit = newVal;
246  } catch (const std::bad_cast&) {}
247  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ 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 124 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

125  {
126  try {
127  const LinearApproximationPolicy< GUM_SCALAR >* lap =
128  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
129 
130  GUM_SCALAR newHighLimit = _lowLimit * lap->lowLimit();
131  GUM_SCALAR newLowLimit = _lowLimit * lap->lowLimit();
132 
133  GUM_SCALAR newVal = _lowLimit * lap->highLimit();
134 
135  if (newHighLimit < newVal) newHighLimit = newVal;
136 
137  if (newLowLimit > newVal) newLowLimit = newVal;
138 
139  newVal = _highLimit * lap->lowLimit();
140 
141  if (newHighLimit < newVal) newHighLimit = newVal;
142 
143  if (newLowLimit > newVal) newLowLimit = newVal;
144 
145  newVal = _highLimit * lap->highLimit();
146 
147  if (newHighLimit < newVal) newHighLimit = newVal;
148 
149  if (newLowLimit > newVal) newLowLimit = newVal;
150  } catch (const std::bad_cast&) {}
151  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ 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 94 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::highLimit(), and gum::LinearApproximationPolicy< GUM_SCALAR >::lowLimit().

95  {
96  try {
97  const LinearApproximationPolicy< GUM_SCALAR >* lap =
98  dynamic_cast< const LinearApproximationPolicy< GUM_SCALAR >* >(ap);
99 
100  GUM_SCALAR newHighLimit = _lowLimit - lap->lowLimit();
101  GUM_SCALAR newLowLimit = _lowLimit - lap->lowLimit();
102 
103  GUM_SCALAR newVal = _lowLimit - lap->highLimit();
104 
105  if (newHighLimit < newVal) newHighLimit = newVal;
106 
107  if (newLowLimit > newVal) newLowLimit = newVal;
108 
109  newVal = _highLimit - lap->lowLimit();
110 
111  if (newHighLimit < newVal) newHighLimit = newVal;
112 
113  if (newLowLimit > newVal) newLowLimit = newVal;
114 
115  newVal = _highLimit - lap->highLimit();
116 
117  if (newHighLimit < newVal) newHighLimit = newVal;
118 
119  if (newLowLimit > newVal) newLowLimit = newVal;
120  } catch (const std::bad_cast&) {}
121  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
+ Here is the call 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 290 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::__decode(), gum::LinearApproximationPolicy< GUM_SCALAR >::_nbInterval, and GUM_ERROR.

290  {
291  if (representation > _nbInterval) {
292  GUM_ERROR(OutOfUpperBound,
293  "Interval Number asked is higher than total number of interval");
294  }
295 
296  return __decode(GUM_SCALAR(representation));
297  }
GUM_SCALAR __decode(const GUM_SCALAR &representation) const
Concretely computes the approximate value from representation.
Idx _nbInterval
The number of interval.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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
OutOfLowerBoundRaised if value is out of bounds.
OutOfUpperBoundRaised if value is out of bounds.

Definition at line 267 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::__encode(), gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and GUM_ERROR.

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::fromExact().

268  {
269 // we keep the bounds checked in debug mode
270 #ifdef GUM_DEBUG_MODE
271  if (value > this->_highLimit) {
272  GUM_TRACE(value << " not in (" << this->_lowLimit << "-" << this->_highLimit
273  << ")");
274  GUM_ERROR(OutOfUpperBound, "Value asked is higher than High limit");
275  }
276 
277  if (value < this->_lowLimit) {
278  GUM_TRACE(value << " not in (" << this->_lowLimit << "-" << this->_highLimit
279  << ")");
280  GUM_ERROR(OutOfLowerBound, "Value asked is lower than low limit");
281  }
282 
283 #endif // GUM_DEBUG_MODE
284  return __encode(value);
285  }
Idx __encode(const GUM_SCALAR &value) const
Concretely computes the approximate representation.
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 57 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::__decode(), and gum::LinearApproximationPolicy< GUM_SCALAR >::encode().

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::safeFromExact().

58  {
59  return __decode(GUM_SCALAR(encode(value)));
60  }
GUM_SCALAR __decode(const GUM_SCALAR &representation) const
Concretely computes the approximate value from representation.
Idx encode(const GUM_SCALAR &value) const
Encode a given value into its approximation representation.
+ 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 356 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit.

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::combineAdd(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineDiv(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMax(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMin(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMult(), and gum::LinearApproximationPolicy< GUM_SCALAR >::combineSub().

356  {
357  return _highLimit;
358  }
GUM_SCALAR _highLimit
Highest value possible.
+ 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 336 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit.

Referenced by gum::LinearApproximationPolicy< GUM_SCALAR >::combineAdd(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineDiv(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMax(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMin(), gum::LinearApproximationPolicy< GUM_SCALAR >::combineMult(), and gum::LinearApproximationPolicy< GUM_SCALAR >::combineSub().

336  {
337  return _lowLimit;
338  }
GUM_SCALAR _lowLimit
Lowest value possible.
+ 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
OutOfLowerBoundRaised if value is out of bounds.
OutOfUpperBoundRaised if value is out of bounds.

Definition at line 252 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::fromExact(), and GUM_ERROR.

253  {
254  if (value > this->_highLimit) {
255  GUM_ERROR(OutOfUpperBound, "Value asked is higher than high limit");
256  }
257 
258  if (value < this->_lowLimit) {
259  GUM_ERROR(OutOfLowerBound, "Value asked is lower than low limit");
260  }
261 
262  return fromExact(value);
263  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
GUM_SCALAR fromExact(const GUM_SCALAR &value) const
Convert value to his approximation.
+ 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 302 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_computeNbInterval(), and gum::LinearApproximationPolicy< GUM_SCALAR >::_epsilon.

302  {
303  _epsilon = e;
305  }
GUM_SCALAR _epsilon
Approximation factor.
void _computeNbInterval()
Get the number of interval.
+ 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
OutOfLowerBoundRaised if out of bound.

Definition at line 342 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_computeNbInterval(), gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and GUM_ERROR.

343  {
344  if (newHighLimit < this->_lowLimit) {
345  GUM_ERROR(OutOfLowerBound, "Value asked is lower than low limit");
346  }
347 
348  _highLimit = newHighLimit;
349 
351  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void _computeNbInterval()
Get the number of interval.
+ 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 309 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_computeNbInterval(), gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and GUM_ERROR.

310  {
311  if (newLowLimit > newHighLimit) {
312  GUM_ERROR(OutOfBounds, "Asked low value is higher than asked high value");
313  }
314 
315  _lowLimit = newLowLimit;
316  _highLimit = newHighLimit;
318  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void _computeNbInterval()
Get the number of interval.
+ 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
OutOfUpperBoundRaised if out of bound.

Definition at line 322 of file linearApproximationPolicy_tpl.h.

References gum::LinearApproximationPolicy< GUM_SCALAR >::_computeNbInterval(), gum::LinearApproximationPolicy< GUM_SCALAR >::_highLimit, gum::LinearApproximationPolicy< GUM_SCALAR >::_lowLimit, and GUM_ERROR.

323  {
324  if (newLowLimit > this->_highLimit) {
325  GUM_ERROR(OutOfUpperBound, "Value asked is higher than High limit");
326  }
327 
328  _lowLimit = newLowLimit;
329 
331  }
GUM_SCALAR _lowLimit
Lowest value possible.
GUM_SCALAR _highLimit
Highest value possible.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
void _computeNbInterval()
Get the number of interval.
+ Here is the call graph for this function:

Member Data Documentation

◆ _epsilon

◆ _highLimit

◆ _lowLimit

◆ _nbInterval


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