aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
linearApproximationPolicy.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
49#ifndef GUM_LINEAR_APPROXIMATION_POLICY_H
50#define GUM_LINEAR_APPROXIMATION_POLICY_H
51
52#include <typeinfo>
53
54#include <agrum/agrum.h>
55
57
58namespace gum {
59
75 template < typename GUM_SCALAR >
76 class LinearApproximationPolicy: public virtual ApproximationPolicy< GUM_SCALAR > {
77 public:
78 // ===========================================================================
80 // ===========================================================================
82
91 LinearApproximationPolicy(GUM_SCALAR low = (GUM_SCALAR)0.0,
92 GUM_SCALAR high = (GUM_SCALAR)1.0,
93 GUM_SCALAR eps = (GUM_SCALAR)0.1);
94
100
102
103 // ===========================================================================
105 // ===========================================================================
107
113 GUM_SCALAR fromExact(const GUM_SCALAR& value) const;
114
120
127
134
140
146
152
162 GUM_SCALAR safeFromExact(const GUM_SCALAR& value);
163
171 Idx encode(const GUM_SCALAR& value) const;
172
179 GUM_SCALAR decode(Idx representation) const;
180
185 virtual void setEpsilon(const GUM_SCALAR& e);
186
193 virtual void setLimits(const GUM_SCALAR& newLowLimit, const GUM_SCALAR& newHighLimit);
194
200 virtual void setLowLimit(const GUM_SCALAR& newLowLimit);
201
206 const GUM_SCALAR& lowLimit() const;
207
213 virtual void setHighLimit(const GUM_SCALAR& newHighLimit);
214
219 const GUM_SCALAR& highLimit() const;
221
222 protected:
224 GUM_SCALAR lowLimit_;
225
227 GUM_SCALAR highLimit_;
228
230 GUM_SCALAR epsilon_;
231
241 Idx _encode_(const GUM_SCALAR& value) const;
242
248 GUM_SCALAR _decode_(const GUM_SCALAR& representation) const;
249
253 void computeNbInterval_();
254
257 };
258} // namespace gum
259
260
261#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
262extern template class gum::LinearApproximationPolicy< double >;
263#endif
264
265
266// Always inline template classes implementation.
268
269#endif /* GUM_LINEAR_APPROXIMATION_POLICY_H */
Classes used to practice approximation on value.
ApproximationPolicy()
Default constructor.
Class implementing linear approximation policy (meaning possible value are split out in interval).
GUM_SCALAR _decode_(const GUM_SCALAR &representation) const
Concretely computes the approximate value from representation.
GUM_SCALAR highLimit_
Highest value possible.
void computeNbInterval_()
Get the number of interval.
virtual void setLowLimit(const GUM_SCALAR &newLowLimit)
Sets lowest possible value.
const GUM_SCALAR & highLimit() const
Gets Highest possible value.
void combineSub(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using substraction with the given gum::ApproximationPolicy.
GUM_SCALAR safeFromExact(const GUM_SCALAR &value)
Convert value to his approximation.
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 combineDiv(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using division with the given gum::ApproximationPolicy.
Idx _encode_(const GUM_SCALAR &value) const
Concretely computes the approximate representation.
GUM_SCALAR fromExact(const GUM_SCALAR &value) const
Convert value to his approximation.
GUM_SCALAR decode(Idx representation) const
Convert approximation representation to value.
GUM_SCALAR lowLimit_
Lowest value possible.
virtual void setEpsilon(const GUM_SCALAR &e)
Sets approximation factor.
void combineAdd(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using addition with the given gum::ApproximationPolicy.
void combineMult(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using multiplication with the given gum::ApproximationPolicy.
virtual void setHighLimit(const GUM_SCALAR &newHighLimit)
Sets Highest possible value.
Idx encode(const GUM_SCALAR &value) const
Encode a given value into its approximation representation.
GUM_SCALAR epsilon_
Approximation factor.
void combineMin(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using min with the given gum::ApproximationPolicy.
void combineMax(const ApproximationPolicy< GUM_SCALAR > *ap)
Combine using max with the given gum::ApproximationPolicy.
virtual void setLimits(const GUM_SCALAR &newLowLimit, const GUM_SCALAR &newHighLimit)
Set bounds in a whole.
Size Idx
Type for indexes.
Definition types.h:79
Inlined implementation of gum::LienarApproxiationPolicy.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46