aGrUM 3.0.0
a C++ library for (probabilistic) graphical models
sdyna_inl.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
44
45namespace gum {
46
47
48 INLINE SDYNA* SDYNA::spitiInstance(double attributeSelectionThreshold,
49 double discountFactor,
50 double epsilon,
51 Idx observationPhaseLenght,
52 Idx nbValueIterationStep) {
53 bool actionReward = false;
55 = new FMDPLearner< CHI2TEST, CHI2TEST, ITILEARNER >(attributeSelectionThreshold,
56 actionReward);
58 = StructuredPlaner< double >::sviInstance(discountFactor, epsilon);
60 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
61 }
62
63 INLINE SDYNA* SDYNA::spimddiInstance(double attributeSelectionThreshold,
64 double similarityThreshold,
65 double discountFactor,
66 double epsilon,
67 Idx observationPhaseLenght,
68 Idx nbValueIterationStep) {
69 bool actionReward = false;
71 = new FMDPLearner< GTEST, GTEST, IMDDILEARNER >(attributeSelectionThreshold,
72 actionReward,
73 similarityThreshold);
75 = StructuredPlaner< double >::spumddInstance(discountFactor, epsilon, false);
77 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward, false);
78 }
79
80 INLINE SDYNA* SDYNA::RMaxMDDInstance(double attributeSelectionThreshold,
81 double similarityThreshold,
82 double discountFactor,
83 double epsilon,
84 Idx observationPhaseLenght,
85 Idx nbValueIterationStep) {
86 bool actionReward = true;
88 = new FMDPLearner< GTEST, GTEST, IMDDILEARNER >(attributeSelectionThreshold,
89 actionReward,
90 similarityThreshold);
92 = AdaptiveRMaxPlaner::ReducedAndOrderedInstance(ls, discountFactor, epsilon);
94 IDecisionStrategy* ds = rm;
95 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
96 }
97
98 INLINE SDYNA* SDYNA::RMaxTreeInstance(double attributeSelectionThreshold,
99 double discountFactor,
100 double epsilon,
101 Idx observationPhaseLenght,
102 Idx nbValueIterationStep) {
103 bool actionReward = true;
105 = new FMDPLearner< GTEST, GTEST, ITILEARNER >(attributeSelectionThreshold, actionReward);
106 AdaptiveRMaxPlaner* rm = AdaptiveRMaxPlaner::TreeInstance(ls, discountFactor, epsilon);
108 IDecisionStrategy* ds = rm;
109 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
110 }
111
112 INLINE SDYNA* SDYNA::RandomMDDInstance(double attributeSelectionThreshold,
113 double similarityThreshold,
114 double discountFactor,
115 double epsilon,
116 Idx observationPhaseLenght,
117 Idx nbValueIterationStep) {
118 bool actionReward = true;
120 = new FMDPLearner< GTEST, GTEST, IMDDILEARNER >(attributeSelectionThreshold,
121 actionReward,
122 similarityThreshold);
124 = StructuredPlaner< double >::spumddInstance(discountFactor, epsilon);
126 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
127 }
128
129 INLINE SDYNA* SDYNA::RandomTreeInstance(double attributeSelectionThreshold,
130 double discountFactor,
131 double epsilon,
132 Idx observationPhaseLenght,
133 Idx nbValueIterationStep) {
134 bool actionReward = true;
136 = new FMDPLearner< CHI2TEST, CHI2TEST, ITILEARNER >(attributeSelectionThreshold,
137 actionReward);
139 = StructuredPlaner< double >::sviInstance(discountFactor, epsilon);
141 return new SDYNA(ls, ps, ds, observationPhaseLenght, nbValueIterationStep, actionReward);
142 }
143
144 INLINE void SDYNA::addAction(const Idx actionId, std::string_view actionName) {
145 fmdp_->addAction(actionId, std::string(actionName));
146 }
147
148 INLINE void SDYNA::addVariable(const DiscreteVariable* var) { fmdp_->addVariable(var); }
149
150 INLINE void SDYNA::setCurrentState(const Instantiation& currentState) {
151 lastState_ = currentState;
152 }
153
154 INLINE std::string SDYNA::optimalPolicy2String() { return _planer_->optimalPolicy2String(); }
155
156 INLINE Size SDYNA::learnerSize() { return _learner_->size(); }
157
158 INLINE Size SDYNA::modelSize() { return fmdp_->size(); }
159
160 INLINE Size SDYNA::valueFunctionSize() { return _planer_->vFunctionSize(); }
161
162 INLINE Size SDYNA::optimalPolicySize() { return _planer_->optimalPolicySize(); }
163
164} // namespace gum
<agrum/FMDP/planning/adaptiveRMaxPlaner.h>
static AdaptiveRMaxPlaner * TreeInstance(const ILearningStrategy *learner, double discountFactor=0.9, double epsilon=0.00001, bool verbose=true)
static AdaptiveRMaxPlaner * ReducedAndOrderedInstance(const ILearningStrategy *learner, double discountFactor=0.9, double epsilon=0.00001, bool verbose=true)
Base class for discrete random variable.
<agrum/FMDP/decision/E_GreedyDecider.h>
<agrum/FMDP/SDyna/IDecisionStrategy.h>
<agrum/FMDP/SDyna/ILearningStrategy.h>
Class for assigning/browsing values to tuples of discrete variables.
Class to make decision randomly.
ILearningStrategy * _learner_
The learner used to learn the FMDP.
Definition sdyna.h:368
static SDYNA * spitiInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:48
Instantiation lastState_
The state in which the system is before we perform a new action.
Definition sdyna.h:364
void setCurrentState(const Instantiation &currentState)
Sets last state visited to the given state.
Definition sdyna_inl.h:150
Size valueFunctionSize()
valueFunctionSize
Definition sdyna_inl.h:160
IPlanningStrategy< double > * _planer_
The planer used to plan an optimal strategy.
Definition sdyna.h:371
FMDP< double > * fmdp_
The learnt Markovian Decision Process.
Definition sdyna.h:361
Size optimalPolicySize()
optimalPolicySize
Definition sdyna_inl.h:162
void addAction(const Idx actionId, std::string_view actionName)
Inserts a new action in the SDyna instance.
Definition sdyna_inl.h:144
std::string optimalPolicy2String()
Definition sdyna_inl.h:154
static SDYNA * spimddiInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:63
static SDYNA * RMaxMDDInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:80
Size learnerSize()
learnerSize
Definition sdyna_inl.h:156
static SDYNA * RandomTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:129
Size modelSize()
modelSize
Definition sdyna_inl.h:158
static SDYNA * RandomMDDInstance(double attributeSelectionThreshold=0.99, double similarityThreshold=0.3, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:112
static SDYNA * RMaxTreeInstance(double attributeSelectionThreshold=0.99, double discountFactor=0.9, double epsilon=1, Idx observationPhaseLenght=100, Idx nbValueIterationStep=10)
@
Definition sdyna_inl.h:98
void addVariable(const DiscreteVariable *var)
Inserts a new variable in the SDyna instance.
Definition sdyna_inl.h:148
SDYNA(ILearningStrategy *learner, IPlanningStrategy< double > *planer, IDecisionStrategy *decider, Idx observationPhaseLenght, Idx nbValueIterationStep, bool actionReward, bool verbose=true)
Constructor.
Definition sdyna.cpp:81
static StructuredPlaner< GUM_ELEMENT > * spumddInstance(GUM_ELEMENT discountFactor=0.9, GUM_ELEMENT epsilon=0.00001, bool verbose=true)
static StructuredPlaner< GUM_ELEMENT > * sviInstance(GUM_ELEMENT discountFactor=0.9, GUM_ELEMENT epsilon=0.00001, bool verbose=true)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Headers of the SDyna abstract class.