aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimNoisyORCompound_tpl.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 /** @file
23  * @brief ANoisy-OR as described by Henrion (UAI-3, 1989, pp161-173)
24  *
25  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
26  *<info_at_agrum_dot_org>
27  */
28 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORCompound.h>
29 
30 namespace gum {
31 
32  /// Default constructor
33 
34  template < typename GUM_SCALAR >
35  INLINE MultiDimNoisyORCompound< GUM_SCALAR >::MultiDimNoisyORCompound(
40  }
41 
42  /// Default constructor
43 
44  template < typename GUM_SCALAR >
49  }
50 
51  /// Copy constructor using a bijection to swap variables from source.
52 
53  template < typename GUM_SCALAR >
55  const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
59  }
60 
61  /// destructor
62 
63  template < typename GUM_SCALAR >
66  }
67 
68  template < typename GUM_SCALAR >
71  if (this->nbrDim() < 1) {
72  GUM_ERROR(OperationNotAllowed, "Not enough variable for a NoisyOr ");
73  }
74 
75  const DiscreteVariable& C = this->variable((Idx)0);
76 
77  if (i.val(C) > 1) return (GUM_SCALAR)0.0;
78 
79  GUM_SCALAR ratio = (GUM_SCALAR)1.0 - this->externalWeight();
80 
82 
83  if (fact != (GUM_SCALAR)0) {
84  for (Idx j = 1; j < this->nbrDim(); j++) {
85  const DiscreteVariable& v = this->variable(j);
86 
87  if (i.val(v) == 1) {
88  GUM_SCALAR pr = (1 - this->causalWeight(v)) / ratio;
89 
90  if (pr == (GUM_SCALAR)0.0) {
91  fact = (GUM_SCALAR)0.0;
92  break;
93  } else {
94  fact *= pr;
95  }
96  }
97  }
98  }
99 
100  return (i.val(C) != 1) ? fact : (GUM_SCALAR)1.0 - fact;
101  }
102 
103  template < typename GUM_SCALAR >
105  std::stringstream s;
106  s << MultiDimImplementation< GUM_SCALAR >::variable(0) << "=noisyORCompound(["
107  << this->externalWeight() << "],";
108 
109  for (Idx i = 1; i < MultiDimImplementation< GUM_SCALAR >::nbrDim(); i++) {
112  << "]";
113  }
114 
115  s << ")";
116 
117  std::string res;
118  s >> res;
119  return res;
120  }
121 
122  // For friendly displaying the content of the variable.
123 
124  template < typename GUM_SCALAR >
125  INLINE std::ostream&
127  return s << ag.toString();
128  }
129 
130  template < typename GUM_SCALAR >
134  this->default_weight__);
135  }
136 
137  // returns the name of the implementation
138  template < typename GUM_SCALAR >
140  static const std::string str = "MultiDimNoisyORCompound";
141  return str;
142  }
143 
144  // ==================================================
145 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669