aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimNoisyORNet_tpl.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 class for NoisyOR-net implementation as multiDim
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  */
28 
29 #include <agrum/tools/multidim/ICIModels/multiDimNoisyORNet.h>
30 
31 namespace gum {
32 
33  // Default constructor
34  template < typename GUM_SCALAR >
39  }
40 
41  // Default constructor
42  template < typename GUM_SCALAR >
47  }
48 
49  // Copy constructor using a bijection to replace variables from source.
50  template < typename GUM_SCALAR >
52  const Bijection< const DiscreteVariable*, const DiscreteVariable* >& bij,
56  }
57 
58  // destructor
59  template < typename GUM_SCALAR >
62  }
63 
64  template < typename GUM_SCALAR >
66  if (this->nbrDim() < 1) { GUM_ERROR(OperationNotAllowed, "Not enough variable for a NoisyOr ") }
67 
68  const DiscreteVariable& C = this->variable((Idx)0);
69 
70  if (i.val(C) > 1) return (GUM_SCALAR)0.0;
71 
72  GUM_SCALAR ratio = (GUM_SCALAR)1.0 - this->externalWeight();
73 
75 
76  if (fact != (GUM_SCALAR)0) {
77  for (Idx j = 1; j < this->nbrDim(); j++) {
78  const DiscreteVariable& v = this->variable(j);
79 
80  if (i.val(v) == 1) {
81  GUM_SCALAR pr = (1 - this->causalWeight(v));
82 
83  if (pr == (GUM_SCALAR)0.0) {
84  fact = (GUM_SCALAR)0.0;
85  break;
86  } else {
87  fact *= pr;
88  }
89  }
90  }
91  }
92 
93  return (i.val(C) != 1) ? fact : (GUM_SCALAR)1.0 - fact;
94  }
95 
96  template < typename GUM_SCALAR >
99  s << MultiDimImplementation< GUM_SCALAR >::variable(0) << "=noisyORNet(["
100  << this->externalWeight() << "],";
101 
102  for (Idx i = 1; i < MultiDimImplementation< GUM_SCALAR >::nbrDim(); i++) {
105  }
106 
107  s << ")";
108 
109  std::string res;
110  s >> res;
111  return res;
112  }
113 
114  // For friendly displaying the content of the variable.
115  template < typename GUM_SCALAR >
117  return s << ag.toString();
118  }
119 
120  template < typename GUM_SCALAR >
123  }
124 
125  // returns the name of the implementation
126  template < typename GUM_SCALAR >
128  static const std::string str = "MultiDimNoisyORNet";
129  return str;
130  }
131 
132 } /* namespace gum */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643