34 template <
typename GUM_SCALAR >
36 GUM_SCALAR low, GUM_SCALAR high, GUM_SCALAR eps) :
38 _lowLimit(low), _highLimit(high), _epsilon(eps) {
45 template <
typename GUM_SCALAR >
53 template <
typename GUM_SCALAR >
55 const GUM_SCALAR& value)
const {
60 template <
typename GUM_SCALAR >
72 if (newHighLimit < newVal) newHighLimit = newVal;
74 if (newLowLimit > newVal) newLowLimit = newVal;
78 if (newHighLimit < newVal) newHighLimit = newVal;
80 if (newLowLimit > newVal) newLowLimit = newVal;
84 if (newHighLimit < newVal) newHighLimit = newVal;
86 if (newLowLimit > newVal) newLowLimit = newVal;
87 }
catch (
const std::bad_cast&) {}
90 template <
typename GUM_SCALAR >
102 if (newHighLimit < newVal) newHighLimit = newVal;
104 if (newLowLimit > newVal) newLowLimit = newVal;
108 if (newHighLimit < newVal) newHighLimit = newVal;
110 if (newLowLimit > newVal) newLowLimit = newVal;
114 if (newHighLimit < newVal) newHighLimit = newVal;
116 if (newLowLimit > newVal) newLowLimit = newVal;
117 }
catch (
const std::bad_cast&) {}
120 template <
typename GUM_SCALAR >
132 if (newHighLimit < newVal) newHighLimit = newVal;
134 if (newLowLimit > newVal) newLowLimit = newVal;
138 if (newHighLimit < newVal) newHighLimit = newVal;
140 if (newLowLimit > newVal) newLowLimit = newVal;
144 if (newHighLimit < newVal) newHighLimit = newVal;
146 if (newLowLimit > newVal) newLowLimit = newVal;
147 }
catch (
const std::bad_cast&) {}
150 template <
typename GUM_SCALAR >
162 if (newHighLimit < newVal) newHighLimit = newVal;
164 if (newLowLimit > newVal) newLowLimit = newVal;
168 if (newHighLimit < newVal) newHighLimit = newVal;
170 if (newLowLimit > newVal) newLowLimit = newVal;
174 if (newHighLimit < newVal) newHighLimit = newVal;
176 if (newLowLimit > newVal) newLowLimit = newVal;
177 }
catch (
const std::bad_cast&) {}
180 template <
typename GUM_SCALAR >
187 GUM_SCALAR newHighLimit =
189 GUM_SCALAR newLowLimit =
195 if (newHighLimit < newVal) newHighLimit = newVal;
197 if (newLowLimit > newVal) newLowLimit = newVal;
201 if (newHighLimit < newVal) newHighLimit = newVal;
203 if (newLowLimit > newVal) newLowLimit = newVal;
207 if (newHighLimit < newVal) newHighLimit = newVal;
209 if (newLowLimit > newVal) newLowLimit = newVal;
210 }
catch (
const std::bad_cast&) {}
213 template <
typename GUM_SCALAR >
220 GUM_SCALAR newHighLimit =
222 GUM_SCALAR newLowLimit =
228 if (newHighLimit < newVal) newHighLimit = newVal;
230 if (newLowLimit > newVal) newLowLimit = newVal;
234 if (newHighLimit < newVal) newHighLimit = newVal;
236 if (newLowLimit > newVal) newLowLimit = newVal;
240 if (newHighLimit < newVal) newHighLimit = newVal;
242 if (newLowLimit > newVal) newLowLimit = newVal;
243 }
catch (
const std::bad_cast&) {}
248 template <
typename GUM_SCALAR >
250 const GUM_SCALAR& value) {
263 template <
typename GUM_SCALAR >
265 const GUM_SCALAR& value)
const {
267 #ifdef GUM_DEBUG_MODE 275 GUM_TRACE(value <<
" not in (" << this->_lowLimit <<
"-" << this->
_highLimit 280 #endif // GUM_DEBUG_MODE 285 template <
typename GUM_SCALAR >
290 "Interval Number asked is higher than total number of interval");
293 return __decode(GUM_SCALAR(representation));
297 template <
typename GUM_SCALAR >
305 template <
typename GUM_SCALAR >
307 const GUM_SCALAR& newLowLimit,
const GUM_SCALAR& newHighLimit) {
308 if (newLowLimit > newHighLimit) {
318 template <
typename GUM_SCALAR >
320 const GUM_SCALAR& newLowLimit) {
331 template <
typename GUM_SCALAR >
332 INLINE
const GUM_SCALAR&
338 template <
typename GUM_SCALAR >
340 const GUM_SCALAR& newHighLimit) {
351 template <
typename GUM_SCALAR >
352 INLINE
const GUM_SCALAR&
358 template <
typename GUM_SCALAR >
360 const GUM_SCALAR& value)
const {
365 return 1 +
Idx(((value - this->_lowLimit) / this->
_epsilon));
369 template <
typename GUM_SCALAR >
371 const GUM_SCALAR& representation)
const {
372 if (representation == 0)
return this->
_lowLimit;
376 return (GUM_SCALAR)(((representation * this->
_epsilon) - (this->
_epsilon / 2))
381 template <
typename GUM_SCALAR >
void combineSub(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using substraction with the given gum::ApproximationPolicy.
virtual void setEpsilon(const GUM_SCALAR &e)
Sets approximation factor.
Idx __encode(const GUM_SCALAR &value) const
Concretely computes the approximate representation.
GUM_SCALAR _lowLimit
Lowest value possible.
void combineDiv(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using division with the given gum::ApproximationPolicy.
GUM_SCALAR _epsilon
Approximation factor.
void combineMin(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using min with the given gum::ApproximationPolicy.
virtual void setLimits(const GUM_SCALAR &newLowLimit, const GUM_SCALAR &newHighLimit)
Set bounds in a whole.
gum is the global namespace for all aGrUM entities
Classes used to practice approximation on value.
const GUM_SCALAR & highLimit() const
Gets Highest possible value.
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.
GUM_SCALAR _highLimit
Highest value possible.
Idx _nbInterval
The number of interval.
virtual void setHighLimit(const GUM_SCALAR &newHighLimit)
Sets 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.
void combineMult(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using multiplication with the given gum::ApproximationPolicy.
Size Idx
Type for indexes.
Class implementing linear approximation policy (meaning possible value are split out in interval)...
GUM_SCALAR decode(Idx representation) const
Convert approximation representation to value.
GUM_SCALAR safeFromExact(const GUM_SCALAR &value)
Convert value to his approximation.
void combineMax(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using max with the given gum::ApproximationPolicy.
#define GUM_ERROR(type, msg)
Mother class for all approximation policy classes.
virtual void setLowLimit(const GUM_SCALAR &newLowLimit)
Sets lowest possible value.
void combineAdd(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using addition with the given gum::ApproximationPolicy.
GUM_SCALAR fromExact(const GUM_SCALAR &value) const
Convert value to his approximation.
void _computeNbInterval()
Get the number of interval.