aGrUM  0.16.0
multiDimNoisyORCompound_tpl.h
Go to the documentation of this file.
1 
30 
31 namespace gum {
32 
34 
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(MultiDimNoisyORCompound);
40  }
41 
43 
44  template < typename GUM_SCALAR >
47  MultiDimICIModel< GUM_SCALAR >(from) {
48  GUM_CONS_CPY(MultiDimNoisyORCompound);
49  }
50 
52 
53  template < typename GUM_SCALAR >
57  MultiDimICIModel< GUM_SCALAR >(bij, from) {
58  GUM_CONSTRUCTOR(MultiDimNoisyORCompound);
59  }
60 
62 
63  template < typename GUM_SCALAR >
65  GUM_DESTRUCTOR(MultiDimNoisyORCompound);
66  }
67 
68  template < typename GUM_SCALAR >
69  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 
81  GUM_SCALAR fact = (GUM_SCALAR)ratio;
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++) {
110  s << MultiDimImplementation< GUM_SCALAR >::variable(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&
126  operator<<(std::ostream& s, const MultiDimNoisyORCompound< GUM_SCALAR >& ag) {
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 >
139  INLINE const std::string& MultiDimNoisyORCompound< GUM_SCALAR >::name() const {
140  static const std::string str = "MultiDimNoisyORCompound";
141  return str;
142  }
143 
144  // ==================================================
145 } /* namespace gum */
virtual const std::string & name() const
returns the real name of the multiDimArray
virtual const DiscreteVariable & variable(Idx i) const override
Returns a const ref to the ith var.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
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() For example : MultiDimArray<double> y; MultiDimContainer<double>* x = y.newFactory(); Then x is a MultiDimArray<double>*.
abstract class for Conditional Indepency Models
GUM_SCALAR __default_weight
in Henrion (89) in a hashtable with a default_value.
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1805
virtual ~MultiDimNoisyORCompound()
Destructor.
const std::string toString() const
returns the real name of the multiDimArray
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
MultiDimNoisyORCompound(GUM_SCALAR external_weight, GUM_SCALAR default_weight=(GUM_SCALAR) 1.0)
Default constructor.
GUM_SCALAR causalWeight(const DiscreteVariable &v) const
Copy of a multiDimICIModel.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
Definition: types.h:53
virtual GUM_SCALAR get(const Instantiation &i) const
returns the real name of the multiDimArray
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55