AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_MDP_MODEL_HEADER_FILE
2 #define AI_TOOLBOX_MDP_MODEL_HEADER_FILE
89 Model(
size_t s,
size_t a,
double discount = 1.0);
124 template <IsNaive3DMatrix T, IsNaive3DMatrix R>
125 Model(
size_t s,
size_t a,
const T & t,
const R & r,
double d = 1.0);
140 Model(
const M& model);
181 template <IsNaive3DMatrix T>
219 template <IsNaive3DMatrix R>
261 std::tuple<size_t, double>
sampleSR(
size_t s,
size_t a)
const;
348 template <IsNaive3DMatrix T, IsNaive3DMatrix R>
349 Model::Model(
const size_t s,
const size_t a,
const T & t,
const R & r,
const double d) :
350 S(s), A(a), transitions_(A,
Matrix2D(S, S)),
351 rewards_(S, A), rand_(
Seeder::getSeed())
360 S(model.getS()), A(model.getA()), transitions_(A,
Matrix2D(S, S)),
361 rewards_(S, A), rand_(
Seeder::getSeed())
365 for (
size_t a = 0; a < A; ++a )
366 for (
size_t s = 0; s < S; ++s ) {
367 for (
size_t s1 = 0; s1 < S; ++s1 ) {
368 transitions_[a](s, s1) = model.getTransitionProbability(s, a, s1);
369 rewards_ (s, a) += model.getExpectedReward (s, a, s1) * transitions_[a](s, s1);
372 throw std::invalid_argument(
"Input transition matrix does not contain valid probabilities.");
376 template <IsNaive3DMatrix T>
379 throw std::invalid_argument(
"Input transition matrix does not contain valid probabilities.");
381 for (
size_t s = 0; s < S; ++s )
382 for (
size_t a = 0; a < A; ++a )
383 for (
size_t s1 = 0; s1 < S; ++s1 )
384 transitions_[a](s, s1) = t[s][a][s1];
387 template <IsNaive3DMatrix R>
390 for (
size_t s = 0; s < S; ++s )
391 for (
size_t a = 0; a < A; ++a )
392 for (
size_t s1 = 0; s1 < S; ++s1 )
393 rewards_(s, a) += r[s][a][s1] * transitions_[a](s, s1);