aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimICIModel.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Abstract base class for all multi dimensionnal Causal Independency
25  * models
26  *
27  * Independance of Causal Influence (ICI) is a method of defining a discrete
28  * distribution that can dramatically reduce the number of prior probabilities
29  * necessary to define a distribution. (see "The Noisy-Average Model for Local
30  * Probability Distributions", Zagorecki, 2003) (see also "Canonical
31  * Probabilistic Models for Knowledge Engineering", Diez, Druzdzel, 2007)
32  *
33  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
34  */
35 #ifndef GUM_MULTI_DIM_ICI_MODEL_H
36 #define GUM_MULTI_DIM_ICI_MODEL_H
37 
38 #include <agrum/tools/core/bijection.h>
39 #include <agrum/tools/multidim/implementations/multiDimReadOnly.h>
40 
41 namespace gum {
42 
43  // ===========================================================================
44  // === GUM_MULTI_DIM_AGGREGATOR ===
45  // ===========================================================================
46  // clang-format off
47  /**
48  * @class MultiDimICIModel
49  * @headerfile multiDimICIModel.h <agrum/tools/multidim/ICIModels/multiDimICIModel.h>
50  * @ingroup multidim_group
51  *
52  * @brief abstract class for Conditional Indepency Models
53  *
54  * @warning The first variable is assumed to be the children. The latter are
55  * the causes.
56  */
57  // clang-format on
58  template < typename GUM_SCALAR >
60  public:
61  // ============================================================================
62  /// @name Constructors / Destructors
63  // ============================================================================
64  /// @{
65 
66  /**
67  * Default constructor.
68  */
69  MultiDimICIModel(GUM_SCALAR external_weight, GUM_SCALAR default_weight = (GUM_SCALAR)1.0);
70 
71  /**
72  * Default constructor.
73  */
74  MultiDimICIModel(const MultiDimICIModel< GUM_SCALAR >& from);
75 
76  /**
77  * @brief Copy constructor using a bijection to swap variables from source.
78  *
79  * @param bij First variables are new variables, seconds are in from.
80  * @param from the copied instance
81  */
82  MultiDimICIModel(const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
83  const MultiDimICIModel< GUM_SCALAR >& from);
84 
85  /**
86  * Destructor.
87  */
88  virtual ~MultiDimICIModel();
89 
90  /// @}
91  // ============================================================================
92  /// @name Accessors / Modifiers
93  // ============================================================================
94  /// @{
95 
96  public:
97  std::string toString() const override;
98 
99  virtual void changeNotification(const gum::Instantiation&,
100  const gum::DiscreteVariable* const,
101  gum::Idx,
102  gum::Idx) override{};
103 
104  virtual void setFirstNotification(const gum::Instantiation&) override{};
105 
106  virtual void setLastNotification(const gum::Instantiation&) override{};
107 
108  virtual void setIncNotification(const gum::Instantiation&) override{};
109 
110  virtual void setDecNotification(const gum::Instantiation&) override{};
111 
112  virtual void setChangeNotification(const gum::Instantiation&) override{};
113 
114  std::string toString(const gum::Instantiation* i) const override { return i->toString(); };
115 
116  /**
117  * @brief Copy of a multiDimICIModel.
118  *
119  * This method is virtual because it should be optimized in certain
120  * MultiDimContainer.
121  *
122  * @throw OperationNotAllowed Raised if src does not have the same domain
123  * size than this MultiDimContainer.
124  **/
125  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const override;
126 
127  /**
128  * @return the real number of parameters used for this table. This function
129  * is used for compute @see compressionRatio()
130  */
131  virtual Size realSize() const override { return this->nbrDim(); };
132 
133  GUM_SCALAR causalWeight(const DiscreteVariable& v) const;
134 
135  void causalWeight(const DiscreteVariable& v, GUM_SCALAR w) const;
136 
137  GUM_SCALAR externalWeight() const;
138 
139  void externalWeight(GUM_SCALAR w) const;
140 
141  /**
142  * @brief returns the real name of the multiDimArray
143  *
144  * In aGrUM, all the types of multi-dimensional arrays/functionals have a
145  * name that describes what they are in reality. For instance, a table
146  * stored in extension is a "MultiDimArray", one that stores only non zero
147  * elements is a "MultiDimSparseArray", and so on. These names are unique
148  * for each type of implementation and is used by the system to determine
149  * which is the best functions to use, say, when we wish to use operators
150  * such as operator+ on two MultiDimImplementations.
151  */
152  virtual const std::string& name() const override;
153 
154  /// @}
155  protected:
156  /// \f$ p_0 \f$ in Henrion (89).
157  mutable GUM_SCALAR _external_weight_;
158 
159  // ============================================================================
160  /// @name causal weights
161  // ============================================================================
162  /// @{
163 
164  /// \f$ P(e | c_i) \f$ in Henrion (89) in a hashtable with a default_value.
165  mutable GUM_SCALAR _default_weight_;
166 
168  /// @}
169 
170  virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y) override;
171  };
172 
173 
174 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
175  extern template class MultiDimICIModel< double >;
176 #endif
177 
178 } /* namespace gum */
179 
180 #include <agrum/tools/multidim/ICIModels/multiDimICIModel_tpl.h>
181 
182 #endif /* GUM_MULTI_DIM_ICI_MODEL_H */
virtual ~MultiDimICIModel()
Destructor.
virtual void setIncNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual void setDecNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
GUM_SCALAR _external_weight_
in Henrion (89).
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
GUM_SCALAR externalWeight() const
Copy of a multiDimICIModel.
virtual void changeNotification(const gum::Instantiation &, const gum::DiscreteVariable *const, gum::Idx, gum::Idx) override
Copy of a multiDimICIModel.
abstract class for Conditional Indepency Models
void externalWeight(GUM_SCALAR w) const
Copy of a multiDimICIModel.
HashTable< const DiscreteVariable *, GUM_SCALAR > _causal_weights_
in Henrion (89) in a hashtable with a default_value.
void causalWeight(const DiscreteVariable &v, GUM_SCALAR w) const
Copy of a multiDimICIModel.
virtual Size realSize() const override
virtual const std::string & name() const override
returns the real name of the multiDimArray
MultiDimICIModel(const MultiDimICIModel< GUM_SCALAR > &from)
Default constructor.
MultiDimICIModel(const Bijection< const DiscreteVariable *, const DiscreteVariable * > &bij, const MultiDimICIModel< GUM_SCALAR > &from)
Copy constructor using a bijection to swap variables from source.
std::string toString() const override
Copy of a multiDimICIModel.
GUM_SCALAR _default_weight_
in Henrion (89) in a hashtable with a default_value.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const override
Copy of a multiDimICIModel.
virtual void setFirstNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
MultiDimICIModel(GUM_SCALAR external_weight, GUM_SCALAR default_weight=(GUM_SCALAR) 1.0)
Default constructor.
std::string toString(const gum::Instantiation *i) const override
Copy of a multiDimICIModel.
virtual void setChangeNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
virtual void setLastNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.