aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
treeRegress_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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#pragma once
42
43
52
56
57#define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
58#define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
59
60namespace gum {
61
62 template < typename GUM_ELEMENT,
63 template < typename > class COMBINEOPERATOR,
64 template < typename > class PROJECTOPERATOR,
65 template < typename > class TerminalNodePolicy >
73
74 template < typename GUM_ELEMENT,
75 template < typename > class COMBINEOPERATOR,
76 template < typename > class PROJECTOPERATOR,
77 template < typename > class TerminalNodePolicy >
81
82 // This function is the main function. To be call every time an operation
83 // between the two given Function Graphs is required
84 template < typename GUM_ELEMENT,
85 template < typename > class COMBINEOPERATOR,
86 template < typename > class PROJECTOPERATOR,
87 template < typename > class TerminalNodePolicy >
97
98 template < typename GUM_ELEMENT,
99 template < typename > class COMBINEOPERATOR,
100 template < typename > class PROJECTOPERATOR,
101 template < typename > class TerminalNodePolicy >
104 _xPloreVFunc_(NodeId currentNodeId) {
105 const InternalNode* currentNode = _vFunc_->node(currentNodeId);
106
107 std::vector< MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy >* > varbucket;
108
109 for (Idx moda = 0; moda < currentNode->nodeVar()->domainSize(); ++moda) {
111 _context_.insert(currentNode->nodeVar(), moda);
112 if (_vFunc_->isTerminalNode(currentNode->son(moda))) {
113 GUM_ELEMENT value = _vFunc_->nodeValue(currentNode->son(moda));
114 if (value) {
116 vpxi->manager()->setRootNode(vpxi->manager()->addTerminalNode(value));
117 }
118 } else {
119 vpxi = _xPloreVFunc_(currentNode->son(moda));
120 }
121
122 if (vpxi != nullptr) {
124 _pxi_.second(currentNode->nodeVar()),
125 _context_);
126 varbucket.push_back(combinope.compute());
127 }
128 delete vpxi;
129 _context_.erase(currentNode->nodeVar());
130 }
131
132 if (varbucket.empty()) return nullptr;
133
135 varbucket.pop_back();
136 while (!varbucket.empty()) {
138 TreeOperator< GUM_ELEMENT, PROJECTOPERATOR > projope(vp, varbucket.back());
139 vp = projope.compute();
140 delete temp;
141 temp = varbucket.back();
142 varbucket.pop_back();
143 delete temp;
144 }
145
146 return vp;
147 }
148
149} // namespace gum
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1640
Base class for discrete random variable.
Structure used to represent a node internal structure.
const DiscreteVariable * nodeVar() const
Returns the node variable.
NodeId son(Idx modality) const
Returns the son at a given index.
virtual void copy(const MultiDimContainer< GUM_ELEMENT > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
static MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
Class used to perform Decision Tree Operation in the FMDP Framework.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _xPloreVFunc_(NodeId currentNodeId)
The whatever 1.
~TreeRegress()
Default destructor.
HashTable< const DiscreteVariable *, Idx > _context_
TreeRegress(const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > *qAction, const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * > pxi)
Default constructor.
MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * _vFunc_
The function graphs used for the operation.
const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_ELEMENT, TerminalNodePolicy > * > _pxi_
Size Idx
Type for indexes.
Definition types.h:79
Size NodeId
Type for node ids.
Headers of the InternalNode class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Class used to compute the operation between two decision diagrams.
Class used to compute the operation between two decision diagrams.