aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
leafPair.h
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 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) { GUM_CONSTRUCTOR(LeafPair); }
61 
62  // ###################################################################
63  /// Default destructor
64  // ###################################################################
65  ~LeafPair() {
66  GUM_DESTRUCTOR(LeafPair);
67  ;
68  }
69 
70  // ============================================================================
71  /// Allocators and Deallocators redefinition
72  // ============================================================================
73  void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
74  void operator delete(void* p) {
75  SmallObjectAllocator::instance().deallocate(p, sizeof(LeafPair));
76  }
77 
78  /// @}
79 
80  // ==========================================================================
81  /// @name Likelyhood Methods
82  // ==========================================================================
83  /// @{
84 
85  // ###################################################################
86  /// Updates GStatistic
87  // ###################################################################
88  void updateLikelyhood();
89 
90  // ###################################################################
91  /// Updates GStatistic
92  // ###################################################################
93  double likelyhood();
94 
95  /// @}
96 
97  // ###################################################################
98  ///
99  // ###################################################################
100  AbstractLeaf* firstLeaf() { return _l1_; }
101  AbstractLeaf* secondLeaf() { return _l2_; }
102 
103  // ###################################################################
104  /// Returns true if pair has leaf in it
105  // ###################################################################
106  bool contains(NodeId testedId) { return _l1_->contains(testedId) || _l2_->contains(testedId); }
107 
108  // ###################################################################
109  /// Returns a leaf matching data and having given id as id
110  // ###################################################################
111  AbstractLeaf* convert2Leaf(NodeId leafId) const { return new ComposedLeaf(leafId, _l1_, _l2_); }
112 
113  AbstractLeaf* otherLeaf(AbstractLeaf* l) const { return l == _l1_ ? _l2_ : _l1_; }
114 
115  std::string toString();
116 
117  private:
120 
123  };
124 
125 
126 } /* namespace gum */
127 
128 
129 #endif // GUM_LEAF_PAIR_H
AbstractLeaf * convert2Leaf(NodeId leafId) const
Returns a leaf matching data and having given id as id.
Definition: leafPair.h:111
AbstractLeaf * _l2_
Definition: leafPair.h:119
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
~LeafPair()
Default destructor.
Definition: leafPair.h:65
<agrum/FMDP/learning/datastructure/leaves/leafPair.h>
Definition: leafPair.h:50
AbstractLeaf * otherLeaf(AbstractLeaf *l) const
Definition: leafPair.h:113
AbstractLeaf * secondLeaf()
Definition: leafPair.h:101
double _likelyhood2_
Definition: leafPair.h:122
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition: leafPair.h:60
void * operator new(size_t s)
Allocators and Deallocators redefinition.
Definition: leafPair.h:73
AbstractLeaf * _l1_
Definition: leafPair.h:118
void operator delete(void *p)
Default constructor.
Definition: leafPair.h:74
AbstractLeaf * firstLeaf()
Definition: leafPair.h:100
std::string toString()
Definition: leafPair.cpp:80
double _likelyhood1_
Definition: leafPair.h:121
double likelyhood()
Updates GStatistic.
Definition: leafPair.cpp:73
bool contains(NodeId testedId)
Returns true if pair has leaf in it.
Definition: leafPair.h:106
void updateLikelyhood()
Updates GStatistic.
Definition: leafPair.cpp:42