aGrUM  0.16.0
leafPair.cpp
Go to the documentation of this file.
1 
29 // =======================================================
30 #include <agrum/core/math/math.h>
33 // =======================================================
34 
35 
36 namespace gum {
37 
38  // ############################################################################
39  // Miscelleanous Methods
40  // ############################################################################
41 
43  __likelyhood1 = 0.0;
44  __likelyhood2 = 0.0;
45 
46  if (!__l1->total() || !__l2->total()) {
47  __likelyhood1 = std::numeric_limits< double >::max();
48  __likelyhood2 = std::numeric_limits< double >::max();
49  return;
50  }
51 
52  double scaleFactor1 = __l1->total() / (__l1->total() + __l2->total());
53  double scaleFactor2 = __l2->total() / (__l1->total() + __l2->total());
54  for (Idx moda = 0; moda < __l1->nbModa(); ++moda) {
55  if (__l1->effectif(moda)) {
56  double add =
57  __l1->effectif(moda)
58  * std::log(
59  __l1->effectif(moda)
60  / (scaleFactor1 * (__l1->effectif(moda) + __l2->effectif(moda))));
61  __likelyhood1 += add;
62  }
63  if (__l2->effectif(moda)) {
64  double add =
65  __l2->effectif(moda)
66  * std::log(
67  __l2->effectif(moda)
68  / (scaleFactor2 * (__l1->effectif(moda) + __l2->effectif(moda))));
69  __likelyhood2 += add;
70  }
71  }
72 
73  __likelyhood1 *= 2;
74  __likelyhood2 *= 2;
75  }
76 
78  // updateLikelyhood();
79  return 1
81  : __likelyhood2,
82  (__l1->nbModa() - 1));
83  }
84 
85  std::string LeafPair::toString() {
86  std::stringstream ss;
87  ss << "\t[ Leaf1 : " << __l1->toString() << " - Leaf2 : " << __l2->toString();
88  // ss << " - L1 Total : " << __l1->total() << " - L2 Total : " <<
89  // __l2->total();
90  // for( Idx moda = 0; moda < __l1->nbModa(); ++moda )
91  // ss << "~ M=" << moda << ".L1=" << __l1->effectif(moda) << ".L2="
92  // << __l2->effectif(moda) << " ~";
93  ss << " - GStat : " << this->likelyhood() << " ]";
94  return ss.str();
95  }
96 
97 } // namespace gum
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual double effectif(Idx) const =0
Gaves the leaf effectif for given modality.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual std::string toString()=0
virtual Idx nbModa() const =0
double __likelyhood2
Definition: leafPair.h:130
static double probaChi2(double x, Size df)
computes the probability of chi2 value (used by the cache)
Definition: chiSquare.cpp:118
AbstractLeaf * __l2
Definition: leafPair.h:127
Size Idx
Type for indexes.
Definition: types.h:53
double __likelyhood1
Definition: leafPair.h:129
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::string toString()
Definition: leafPair.cpp:85
virtual double total() const =0
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:77
AbstractLeaf * __l1
Definition: leafPair.h:126
void updateLikelyhood()
Updates GStatistic.
Definition: leafPair.cpp:42