aGrUM 2.3.2
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-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#pragma once
41
42
51
55
56#define ALLOCATE(x) SmallObjectAllocator::instance().allocate(x)
57#define DEALLOCATE(x, y) SmallObjectAllocator::instance().deallocate(x, y)
58
59namespace gum {
60
61 template < typename GUM_SCALAR,
62 template < typename > class COMBINEOPERATOR,
63 template < typename > class PROJECTOPERATOR,
64 template < typename > class TerminalNodePolicy >
72
73 template < typename GUM_SCALAR,
74 template < typename > class COMBINEOPERATOR,
75 template < typename > class PROJECTOPERATOR,
76 template < typename > class TerminalNodePolicy >
80
81 // This function is the main function. To be call every time an operation
82 // between the two given Function Graphs is required
83 template < typename GUM_SCALAR,
84 template < typename > class COMBINEOPERATOR,
85 template < typename > class PROJECTOPERATOR,
86 template < typename > class TerminalNodePolicy >
96
97 template < typename GUM_SCALAR,
98 template < typename > class COMBINEOPERATOR,
99 template < typename > class PROJECTOPERATOR,
100 template < typename > class TerminalNodePolicy >
103 _xPloreVFunc_(NodeId currentNodeId) {
104 const InternalNode* currentNode = _vFunc_->node(currentNodeId);
105
106 std::vector< MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* > varbucket;
107
108 for (Idx moda = 0; moda < currentNode->nodeVar()->domainSize(); ++moda) {
110 _context_.insert(currentNode->nodeVar(), moda);
111 if (_vFunc_->isTerminalNode(currentNode->son(moda))) {
112 GUM_SCALAR value = _vFunc_->nodeValue(currentNode->son(moda));
113 if (value) {
115 vpxi->manager()->setRootNode(vpxi->manager()->addTerminalNode(value));
116 }
117 } else {
118 vpxi = _xPloreVFunc_(currentNode->son(moda));
119 }
120
121 if (vpxi != nullptr) {
123 _pxi_.second(currentNode->nodeVar()),
124 _context_);
125 varbucket.push_back(combinope.compute());
126 }
127 delete vpxi;
128 _context_.erase(currentNode->nodeVar());
129 }
130
131 if (varbucket.empty()) return nullptr;
132
134 varbucket.pop_back();
135 while (!varbucket.empty()) {
137 TreeOperator< GUM_SCALAR, PROJECTOPERATOR > projope(vp, varbucket.back());
138 vp = projope.compute();
139 delete temp;
140 temp = varbucket.back();
141 varbucket.pop_back();
142 delete temp;
143 }
144
145 return vp;
146 }
147
148} // namespace gum
Set of pairs of elements with fast search for both elements.
Definition bijection.h:1594
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_SCALAR > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
static MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * getTreeInstance()
Returns an arborescent instance.
Class used to perform Decision Tree Operation in the FMDP Framework.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _xPloreVFunc_(NodeId currentNodeId)
The whatever 1.
~TreeRegress()
Default destructor.
TreeRegress(const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > *qAction, const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * > pxi)
Default constructor.
const Bijection< const DiscreteVariable *, const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * > _pxi_
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * compute()
Computes and builds the Function Graph that is the result of the operation.
HashTable< const DiscreteVariable *, Idx > _context_
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * _vFunc_
The function graphs used for the operation.
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.