aGrUM  0.16.0
multiDimNoisyORNet_tpl.h
Go to the documentation of this file.
1 
31 
32 namespace gum {
33 
34  // Default constructor
35  template < typename GUM_SCALAR >
37  GUM_SCALAR external_weight, GUM_SCALAR default_weight) :
38  MultiDimICIModel< GUM_SCALAR >(external_weight, default_weight) {
39  GUM_CONSTRUCTOR(MultiDimNoisyORNet);
40  }
41 
42  // Default constructor
43  template < typename GUM_SCALAR >
46  MultiDimICIModel< GUM_SCALAR >(from) {
47  GUM_CONS_CPY(MultiDimNoisyORNet);
48  }
49 
50  // Copy constructor using a bijection to replace variables from source.
51  template < typename GUM_SCALAR >
55  MultiDimICIModel< GUM_SCALAR >(bij, from) {
56  GUM_CONSTRUCTOR(MultiDimNoisyORNet);
57  }
58 
59  // destructor
60  template < typename GUM_SCALAR >
62  GUM_DESTRUCTOR(MultiDimNoisyORNet);
63  }
64 
65  template < typename GUM_SCALAR >
67  if (this->nbrDim() < 1) {
68  GUM_ERROR(OperationNotAllowed, "Not enough variable for a NoisyOr ");
69  }
70 
71  const DiscreteVariable& C = this->variable((Idx)0);
72 
73  if (i.val(C) > 1) return (GUM_SCALAR)0.0;
74 
75  GUM_SCALAR ratio = (GUM_SCALAR)1.0 - this->externalWeight();
76 
77  GUM_SCALAR fact = (GUM_SCALAR)ratio;
78 
79  if (fact != (GUM_SCALAR)0) {
80  for (Idx j = 1; j < this->nbrDim(); j++) {
81  const DiscreteVariable& v = this->variable(j);
82 
83  if (i.val(v) == 1) {
84  GUM_SCALAR pr = (1 - this->causalWeight(v));
85 
86  if (pr == (GUM_SCALAR)0.0) {
87  fact = (GUM_SCALAR)0.0;
88  break;
89  } else {
90  fact *= pr;
91  }
92  }
93  }
94  }
95 
96  return (i.val(C) != 1) ? fact : (GUM_SCALAR)1.0 - fact;
97  }
98 
99  template < typename GUM_SCALAR >
100  const std::string MultiDimNoisyORNet< GUM_SCALAR >::toString() const {
101  std::stringstream s;
102  s << MultiDimImplementation< GUM_SCALAR >::variable(0) << "=noisyORNet(["
103  << this->externalWeight() << "],";
104 
105  for (Idx i = 1; i < MultiDimImplementation< GUM_SCALAR >::nbrDim(); i++) {
106  s << MultiDimImplementation< GUM_SCALAR >::variable(i) << "["
108  << "]";
109  }
110 
111  s << ")";
112 
113  std::string res;
114  s >> res;
115  return res;
116  }
117 
118  // For friendly displaying the content of the variable.
119  template < typename GUM_SCALAR >
120  INLINE std::ostream& operator<<(std::ostream& s,
122  return s << ag.toString();
123  }
124 
125  template < typename GUM_SCALAR >
129  this->__default_weight);
130  }
131 
132  // returns the name of the implementation
133  template < typename GUM_SCALAR >
134  INLINE const std::string& MultiDimNoisyORNet< GUM_SCALAR >::name() const {
135  static const std::string str = "MultiDimNoisyORNet";
136  return str;
137  }
138 
139 } /* namespace gum */
Noisy OR representation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the real name of the multiDimArray.
virtual const DiscreteVariable & variable(Idx i) const override
Returns a const ref to the ith var.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
GUM_SCALAR __external_weight
in Henrion (89).
Idx val(Idx i) const
Returns the current value of the variable at position i.
GUM_SCALAR externalWeight() const
Copy of a multiDimICIModel.
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:605
abstract class for Conditional Indepency Models
const std::string toString() const
Returns the real name of the multiDimArray.
virtual const std::string & name() const
Returns the real name of the multiDimArray.
GUM_SCALAR __default_weight
in Henrion (89) in a hashtable with a default_value.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
This method creates a clone of this object, withouth its content (including variable), you must use this method if you want to ensure that the generated object has the same type than the object containing the called newFactory()
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
virtual Idx nbrDim() const override
Returns the number of vars in the multidimensional container.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:83
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
MultiDimNoisyORNet(GUM_SCALAR external_weight, GUM_SCALAR default_weight=(GUM_SCALAR) 1.0)
Default constructor.
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
virtual ~MultiDimNoisyORNet()
Destructor.