aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimICIModel.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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,
70  GUM_SCALAR default_weight = (GUM_SCALAR)1.0);
71 
72  /**
73  * Default constructor.
74  */
75  MultiDimICIModel(const MultiDimICIModel< GUM_SCALAR >& from);
76 
77  /**
78  * @brief Copy constructor using a bijection to swap variables from source.
79  *
80  * @param bij First variables are new variables, seconds are in from.
81  * @param from the copied instance
82  */
84  const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
85  const MultiDimICIModel< GUM_SCALAR >& from);
86 
87  /**
88  * Destructor.
89  */
90  virtual ~MultiDimICIModel();
91 
92  /// @}
93  // ============================================================================
94  /// @name Accessors / Modifiers
95  // ============================================================================
96  /// @{
97 
98  public:
99  std::string toString() const override;
100 
101  virtual void changeNotification(const gum::Instantiation&,
102  const gum::DiscreteVariable* const,
103  gum::Idx,
104  gum::Idx) override{};
105 
106  virtual void setFirstNotification(const gum::Instantiation&) override{};
107 
108  virtual void setLastNotification(const gum::Instantiation&) override{};
109 
110  virtual void setIncNotification(const gum::Instantiation&) override{};
111 
112  virtual void setDecNotification(const gum::Instantiation&) override{};
113 
114  virtual void setChangeNotification(const gum::Instantiation&) override{};
115 
116  std::string toString(const gum::Instantiation* i) const override {
117  return i->toString();
118  };
119 
120  /**
121  * @brief Copy of a multiDimICIModel.
122  *
123  * This method is virtual because it should be optimized in certain
124  * MultiDimContainer.
125  *
126  * @throw OperationNotAllowed Raised if src does not have the same domain
127  * size than this MultiDimContainer.
128  **/
129  virtual void
130  copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const override;
131 
132  /**
133  * @return the real number of parameters used for this table. This function
134  * is used for compute @see compressionRatio()
135  */
136  virtual Size realSize() const override { return this->nbrDim(); };
137 
138  GUM_SCALAR causalWeight(const DiscreteVariable& v) const;
139 
140  void causalWeight(const DiscreteVariable& v, GUM_SCALAR w) const;
141 
142  GUM_SCALAR externalWeight() const;
143 
144  void externalWeight(GUM_SCALAR w) const;
145 
146  /**
147  * @brief returns the real name of the multiDimArray
148  *
149  * In aGrUM, all the types of multi-dimensional arrays/functionals have a
150  * name that describes what they are in reality. For instance, a table
151  * stored in extension is a "MultiDimArray", one that stores only non zero
152  * elements is a "MultiDimSparseArray", and so on. These names are unique
153  * for each type of implementation and is used by the system to determine
154  * which is the best functions to use, say, when we wish to use operators
155  * such as operator+ on two MultiDimImplementations.
156  */
157  virtual const std::string& name() const override;
158 
159  /// @}
160  protected:
161  /// \f$ p_0 \f$ in Henrion (89).
162  mutable GUM_SCALAR external_weight__;
163 
164  // ============================================================================
165  /// @name causal weights
166  // ============================================================================
167  /// @{
168 
169  /// \f$ P(e | c_i) \f$ in Henrion (89) in a hashtable with a default_value.
170  mutable GUM_SCALAR default_weight__;
171 
173  /// @}
174 
175  virtual void replace_(const DiscreteVariable* x,
176  const DiscreteVariable* y) override;
177  };
178 
179 
180 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
181  extern template class MultiDimICIModel< double >;
182 #endif
183 
184 } /* namespace gum */
185 
186 #include <agrum/tools/multidim/ICIModels/multiDimICIModel_tpl.h>
187 
188 #endif /* GUM_MULTI_DIM_ICI_MODEL_H */
virtual ~MultiDimICIModel()
Destructor.
virtual void setIncNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
HashTable< const DiscreteVariable *, GUM_SCALAR > causal_weights__
in Henrion (89) in a hashtable with a default_value.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual void setDecNotification(const gum::Instantiation &) override
Copy of a multiDimICIModel.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
GUM_SCALAR default_weight__
in Henrion (89) in a hashtable with a default_value.
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.
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 external_weight__
in Henrion (89).
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.