1 /**
2  *
3  *   Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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 class for multiDimNoisyORCompound
25  *
26  * @author Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_AMU)
27  */
28 
29 #ifndef GUM_MULTI_DIM_NOISY_OR_COMPOUND_H
30 #define GUM_MULTI_DIM_NOISY_OR_COMPOUND_H
31 
32 #include <agrum/tools/multidim/ICIModels/multiDimICIModel.h>
33 
34 namespace gum {
35 
36   // ===========================================================================
37   // ===                       GUM_MULTI_DIM_NOISYOR_COMPOU                  ===
38   // ===========================================================================
39   // clang-format off
40   /**
41    * @class MultiDimNoisyORCompound
42    * @headerfile multiDimNoisyORCompound.h <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h>
43    * @ingroup multidim_group
44    *
45    * @brief Noisy OR representation
46    *
47    * Noisy-OR as described by Henrion (UAI-3, 1989, pp161-173)
48    *
49    * @warning
50    *   - The first variable is assumed to be the NOISY-OR. The latter are
51    *     the causes.
52    *   - This code give probabilities for BINARY VARIABLES (other values are
53    *     assumed to be of probability 0). But for optimization reason, we will
54    *     never check if it is the case.
55    */
56   // clang-format on
57   template < typename GUM_SCALAR >
58 
59   class MultiDimNoisyORCompound: public MultiDimICIModel< GUM_SCALAR > {
60     public:
61     // ============================================================================
62     /// @name Constructors / Destructors
63     // ============================================================================
64     /// @{
65 
66     /// Default constructor.
67     MultiDimNoisyORCompound(GUM_SCALAR external_weight,
68                             GUM_SCALAR default_weight = (GUM_SCALAR)1.0);
69 
70     MultiDimNoisyORCompound(const MultiDimNoisyORCompound< GUM_SCALAR >& from);
71 
72     /**
73      * Copy constructor using a bijection to swap variables from source.
74      *
75      * @param bij First variables are new variables, seconds are in from.
76      * @param from the copied instance
77      */
78     MultiDimNoisyORCompound(
79        const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
80        const MultiDimNoisyORCompound< GUM_SCALAR >&                         from);
81 
82     /// Destructor.
83     virtual ~MultiDimNoisyORCompound();
84 
85     /// @}
86 
87     /**
88      * This method creates a clone of this object, withouth its content
89      * (including variable), you must use this method if you want to ensure
90      * that the generated object has the same type than the object containing
91      * the called newFactory()
92      * For example :
93      *   MultiDimArray<double> y;
94      *   MultiDimContainer<double>* x = y.newFactory();
95      * Then x is a MultiDimArray<double>*
96      *
97      * @warning you must desallocate by yourself the memory
98      * @return an empty clone of this object with the same type
99      */
100     virtual MultiDimContainer< GUM_SCALAR >* newFactory() const;
101 
102     // ############################################################################
103     /// @name Accessors / Modifiers
104     // ############################################################################
105     /// @{
106 
107     public:
108     virtual GUM_SCALAR get(const Instantiation& i) const;
109 
110     std::string toString() const;
111 
112     /// returns the real name of the multiDimArray
113     /** In aGrUM, all the types of multi-dimensional arrays/functionals have a
114      * name that describes what they are in reality. For instance, a table
115      * stored
116      * in extension is a "MultiDimArray", one that stores only non zero elements
117      * is a "MultiDimSparseArray", and so on. These names are unique for each
118      * type
119      * of implementation and is used by the system to determine which is the
120      * best
121      * functions to use, say, when we wish to use operators such as operator+ on
122      * two MultiDimImplementations */
123     virtual const std::string& name() const;
124 
125     /// @}
126   };
127 
128 
129 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
130   extern template class MultiDimNoisyORCompound< double >;
131 #endif
132 
133   /// For friendly displaying the content of the array.
134   template < typename GUM_SCALAR >
135   std::ostream& operator<<(std::ostream& s, const MultiDimNoisyORCompound< GUM_SCALAR >& ag);
136 
137 } /* namespace gum */
138 
139 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound_tpl.h>
140 
141 #endif /* GUM_MULTI_DIM_NOISY_OR_COMPOUND_H */
142