bitrl & cuberl Documentation
Simulation engine for reinforcement learning agents
Loading...
Searching...
No Matches
space_type.h
Go to the documentation of this file.
1#ifndef SPACE_TYPE_H
2#define SPACE_TYPE_H
3
4#include "bitrl/bitrl_types.h"
5#include <random>
6#include <vector>
7
8#include <type_traits>
9
10namespace bitrl
11{
12namespace envs
13{
14
21template <uint_t s, uint_t e> struct ScalarDiscreteSpace
22{
23
28
33
38 static constexpr uint_t size = e - s ; //IntegralRange<s, e>::size;
39
44 static space_item_type sample(bool use_end);
45
51 static space_item_type sample(uint_t seed, bool use_end);
52
58 static std::vector<space_item_type> sample(uint_t seed, uint_t size, bool use_end);
59};
60
61template <uint_t s, uint_t e>
63{
64
66
67 if (!use_end)
68 {
69 E -= 1;
70 }
71
72 std::uniform_int_distribution<> dist(IntegralRange<s, e>::S, E);
73 std::random_device rd;
74 std::mt19937 gen(rd());
75 return dist(gen);
76}
77
78template <uint_t s, uint_t e>
80 bool use_end)
81{
82
84
85 if (!use_end)
86 {
87 E -= 1;
88 }
89
90 std::uniform_int_distribution<> dist(IntegralRange<s, e>::S, E);
91 std::mt19937 gen(seed);
92 return dist(gen);
93}
94
95template <uint_t s, uint_t e>
96std::vector<typename ScalarDiscreteSpace<s, e>::space_item_type>
98{
99
100 auto E = IntegralRange<s, e>::E;
101
102 if (!use_end)
103 {
104 E -= 1;
105 }
106
107 std::vector<typename ScalarDiscreteSpace<s, e>::space_item_type> vals_;
108 vals_.reserve(size);
109
110 std::uniform_int_distribution<> dist(IntegralRange<s, e>::S, E);
111 std::mt19937 gen(seed);
112 for (uint_t i = 0; i < size; ++i)
113 {
114 vals_.push_back(dist(gen));
115 }
116
117 return vals_;
118}
119
120template <uint_t Size> struct ContinuousScalareSpace
121{
126
131 static constexpr uint_t size = Size;
132};
133
134template <uint_t Size, typename T = real_t> struct ContinuousVectorSpace
135{
136 static_assert(std::is_floating_point_v<T> == true && "Floating point type is expected");
137
142 static constexpr uint_t size = Size;
143
147 typedef std::vector<T> space_item_type;
148};
149
150template <uint_t SpaceSize, typename T = uint_t> struct DiscreteVectorSpace
151{
152 static_assert(std::is_integral_v<T> == true && "Integral type is expected");
153
157 typedef std::vector<T> space_item_type;
158
162 static constexpr uint_t size = SpaceSize;
163};
164
165} // namespace envs
166} // namespace bitrl
167#endif
Definition bitrl_consts.h:14
double real_t
real_t
Definition bitrl_types.h:23
std::size_t uint_t
uint_t
Definition bitrl_types.h:43
A range of integer values in [s, e].
Definition bitrl_types.h:128
Definition space_type.h:121
static constexpr uint_t size
The overall size of the space meaning how many elements can potentially the space have.
Definition space_type.h:131
real_t space_item_type
item_t
Definition space_type.h:125
Definition space_type.h:135
std::vector< T > space_item_type
item_t
Definition space_type.h:147
static constexpr uint_t size
The overall size of the space meaning how many elements can potentially the space have.
Definition space_type.h:142
Definition space_type.h:151
std::vector< T > space_item_type
item_t
Definition space_type.h:157
static constexpr uint_t size
size. The number of members in the space
Definition space_type.h:162
A scalar discrete space can be used to denote a space that only has a single value at each time....
Definition space_type.h:22
static constexpr IntegralRange< s, e > limits
The limits of the space.
Definition space_type.h:32
uint_t space_item_type
item_t
Definition space_type.h:27
static space_item_type sample(bool use_end)
sample
Definition space_type.h:62
static constexpr uint_t size
The overall size of the space meaning how many elements can potentially the space have.
Definition space_type.h:38