aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
leafPair.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 Headers of the leaf pair class.
25  *
26  * @author Jean-Christophe MAGNAN
27  */
28 
29 // =========================================================================
30 #ifndef GUM_LEAF_PAIR_H
31 #define GUM_LEAF_PAIR_H
32 // =========================================================================
33 #include <agrum/tools/graphs/graphElements.h>
34 // =========================================================================
35 #include <agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
36 #include <agrum/FMDP/learning/datastructure/leaves/composedLeaf.h>
37 // =========================================================================
38 
39 namespace gum {
40 
41  /**
42  * @class LeafPair leafPair.h
43  * <agrum/FMDP/learning/datastructure/leaves/leafPair.h>
44  * @brief Handles a pair of leaves
45  * @ingroup fmdp_group
46  *
47  */
48 
49 
50  class LeafPair {
51  public:
52  // ==========================================================================
53  /// @name Constructor & destructor.
54  // ==========================================================================
55  /// @{
56 
57  // ###################################################################
58  /// Default constructor
59  // ###################################################################
60  LeafPair(AbstractLeaf* l1, AbstractLeaf* l2) : l1__(l1), l2__(l2) {
61  GUM_CONSTRUCTOR(LeafPair);
62  }
63 
64  // ###################################################################
65  /// Default destructor
66  // ###################################################################
67  ~LeafPair() { GUM_DESTRUCTOR(LeafPair); }
68 
69  // ============================================================================
70  /// Allocators and Deallocators redefinition
71  // ============================================================================
72  void* operator new(size_t s) {
73  return SmallObjectAllocator::instance().allocate(s);
74  }
75  void operator delete(void* p) {
76  SmallObjectAllocator::instance().deallocate(p, sizeof(LeafPair));
77  }
78 
79  /// @}
80 
81  // ==========================================================================
82  /// @name Likelyhood Methods
83  // ==========================================================================
84  /// @{
85 
86  // ###################################################################
87  /// Updates GStatistic
88  // ###################################################################
89  void updateLikelyhood();
90 
91  // ###################################################################
92  /// Updates GStatistic
93  // ###################################################################
94  double likelyhood();
95 
96  /// @}
97 
98  // ###################################################################
99  ///
100  // ###################################################################
101  AbstractLeaf* firstLeaf() { return l1__; }
102  AbstractLeaf* secondLeaf() { return l2__; }
103 
104  // ###################################################################
105  /// Returns true if pair has leaf in it
106  // ###################################################################
107  bool contains(NodeId testedId) {
108  return l1__->contains(testedId) || l2__->contains(testedId);
109  }
110 
111  // ###################################################################
112  /// Returns a leaf matching data and having given id as id
113  // ###################################################################
115  return new ComposedLeaf(leafId, l1__, l2__);
116  }
117 
119  return l == l1__ ? l2__ : l1__;
120  }
121 
122  std::string toString();
123 
124  private:
127 
130  };
131 
132 
133 } /* namespace gum */
134 
135 
136 #endif // GUM_LEAF_PAIR_H
AbstractLeaf * convert2Leaf(NodeId leafId) const
Returns a leaf matching data and having given id as id.
Definition: leafPair.h:114
AbstractLeaf * l1__
Definition: leafPair.h:125
double likelyhood2__
Definition: leafPair.h:129
AbstractLeaf * l2__
Definition: leafPair.h:126
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
~LeafPair()
Default destructor.
Definition: leafPair.h:67
<agrum/FMDP/learning/datastructure/leaves/leafPair.h>
Definition: leafPair.h:50
AbstractLeaf * otherLeaf(AbstractLeaf *l) const
Definition: leafPair.h:118
AbstractLeaf * secondLeaf()
Definition: leafPair.h:102
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:60
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: leafPair.h:72
double likelyhood1__
Definition: leafPair.h:128
void operator delete(void *p)
Default constructor.
Definition: leafPair.h:75
AbstractLeaf * firstLeaf()
Definition: leafPair.h:101
std::string toString()
Definition: leafPair.cpp:83
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:75
bool contains(NodeId testedId)
Returns true if pair has leaf in it.
Definition: leafPair.h:107
void updateLikelyhood()
Updates GStatistic.
Definition: leafPair.cpp:42