aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
leafPair.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48
49// =========================================================================
50#ifndef GUM_LEAF_PAIR_H
51#define GUM_LEAF_PAIR_H
52// =========================================================================
53// =========================================================================
55
56// =========================================================================
57
58namespace gum {
59
67
68
69 class LeafPair {
70 public:
71 // ==========================================================================
73 // ==========================================================================
75
76 // ###################################################################
78 // ###################################################################
79 LeafPair(AbstractLeaf* l1, AbstractLeaf* l2) : _l1_(l1), _l2_(l2) { GUM_CONSTRUCTOR(LeafPair); }
80
81 // ###################################################################
83 // ###################################################################
85 GUM_DESTRUCTOR(LeafPair);
86 ;
87 }
88
89 // ============================================================================
91 // ============================================================================
92 void* operator new(size_t s) { return SmallObjectAllocator::instance().allocate(s); }
93
94 void operator delete(void* p) {
96 }
97
99
100 // ==========================================================================
102 // ==========================================================================
104
105 // ###################################################################
107 // ###################################################################
108 void updateLikelyhood();
109
110 // ###################################################################
112 // ###################################################################
113 double likelyhood();
114
116
117 // ###################################################################
119 // ###################################################################
121
123
124 // ###################################################################
126 // ###################################################################
127 bool contains(NodeId testedId) { return _l1_->contains(testedId) || _l2_->contains(testedId); }
128
129 // ###################################################################
131 // ###################################################################
132 AbstractLeaf* convert2Leaf(NodeId leafId) const { return new ComposedLeaf(leafId, _l1_, _l2_); }
133
134 AbstractLeaf* otherLeaf(AbstractLeaf* l) const { return l == _l1_ ? _l2_ : _l1_; }
135
136 std::string toString();
137
138 private:
141
144 };
145
146
147} /* namespace gum */
148
149
150#endif // GUM_LEAF_PAIR_H
<agrum/FMDP/learning/datastructure/leaves/abstractLeaf.h>
<agrum/FMDP/learning/datastructure/leaves/composedLeaf.h>
AbstractLeaf * convert2Leaf(NodeId leafId) const
Returns a leaf matching data and having given id as id.
Definition leafPair.h:132
double _likelyhood1_
Definition leafPair.h:142
double _likelyhood2_
Definition leafPair.h:143
void updateLikelyhood()
Updates GStatistic.
Definition leafPair.cpp:64
bool contains(NodeId testedId)
Returns true if pair has leaf in it.
Definition leafPair.h:127
AbstractLeaf * _l1_
Definition leafPair.h:139
~LeafPair()
Default destructor.
Definition leafPair.h:84
std::string toString()
Definition leafPair.cpp:102
LeafPair(AbstractLeaf *l1, AbstractLeaf *l2)
Default constructor.
Definition leafPair.h:79
AbstractLeaf * otherLeaf(AbstractLeaf *l) const
Definition leafPair.h:134
AbstractLeaf * _l2_
Definition leafPair.h:140
AbstractLeaf * secondLeaf()
Definition leafPair.h:122
double likelyhood()
Updates GStatistic.
Definition leafPair.cpp:95
AbstractLeaf * firstLeaf()
Definition leafPair.h:120
static SmallObjectAllocator & instance()
void * allocate(const size_t &objectSize)
Allocates a block.
void deallocate(void *pDeallocatedObject, const size_t &objectSize)
Deallocates an object.
Headers of the abstract leaf class.
Size NodeId
Type for node ids.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46