aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
leafPair.cpp
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 Sources for concrete leaf class
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and Christophe
27  * GONZALES(@AMU)
28  */
29 // =======================================================
30 #include <agrum/tools/core/math/math_utils.h>
31 #include <agrum/FMDP/learning/core/chiSquare.h>
32 #include <agrum/FMDP/learning/datastructure/leaves/leafPair.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 = _l1_->effectif(moda)
57  * std::log(_l1_->effectif(moda)
59  _likelyhood1_ += add;
60  }
61  if (_l2_->effectif(moda)) {
62  double add = _l2_->effectif(moda)
63  * std::log(_l2_->effectif(moda)
65  _likelyhood2_ += add;
66  }
67  }
68 
69  _likelyhood1_ *= 2;
70  _likelyhood2_ *= 2;
71  }
72 
73  double LeafPair::likelyhood() {
74  // updateLikelyhood();
75  return 1
77  (_l1_->nbModa() - 1));
78  }
79 
82  ss << "\t[ Leaf1 : " << _l1_->toString() << " - Leaf2 : " << _l2_->toString();
83  // ss << " - L1 Total : " << _l1_->total() << " - L2 Total : " <<
84  // _l2_->total();
85  // for( Idx moda = 0; moda < _l1_->nbModa(); ++moda )
86  // ss << "~ M=" << moda << ".L1=" << _l1_->effectif(moda) << ".L2="
87  // << _l2_->effectif(moda) << " ~";
88  ss << " - GStat : " << this->likelyhood() << " ]";
89  return ss.str();
90  }
91 
92 } // namespace gum
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643