bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
random_tabular_policy.h
Go to the documentation of this file.
1#ifndef RANDOM_TABULAR_POLICY_H
2#define RANDOM_TABULAR_POLICY_H
3
4#include "bitrl/base/bitrl_config.h"
7
8#ifdef USE_PYTORCH
9#include <torch/torch.h>
10#endif
11
12#include <random>
13
14namespace bitrl
15{
16namespace rl
17{
18namespace policies
19{
20
25{
26
27 public:
32
37
42
46 template <typename MatType>
47 output_type operator()(const MatType &q_map, uint_t state_idx) const;
48
49#ifdef USE_PYTORCH
50 output_type operator()(const torch_tensor_t &vec) const;
51#endif
52
58 template <typename VecTp> output_type operator()(const VecTp &vec) const;
59
63 template <typename MatType> output_type get_action(const MatType &q_map, uint_t state_idx);
64
70 template <typename VecTp> output_type get_action(const VecTp &q_map);
71
76 void on_episode(uint_t) noexcept {}
77
81 void reset() noexcept {}
82
83 private:
87 // std::random_device rd_;
88
92 mutable std::mt19937 generator_;
93};
94
95#ifdef USE_PYTORCH
98{
99
101 // std::discrete_distribution<int> distribution(vector.begin(), vector.end());
102 std::uniform_int_distribution<uint_t> distribution(0, vector.size() - 1);
103 return distribution(generator_);
104}
105#endif
106
107template <typename VecTp>
109{
110
111 // std::discrete_distribution<int> distribution(vec.begin(), vec.end());
112 std::uniform_int_distribution<uint_t> distribution(0, vec.size() - 1);
113 return distribution(generator_);
114}
115
116template <typename VecTp>
118{
119 std::uniform_int_distribution<uint_t> distribution(0, vec.size() - 1);
120 return distribution(generator_);
121}
122
123} // namespace policies
124} // namespace rl
125} // namespace bitrl
126
127#endif // RANDOM_TABULAR_POLICY_H
output_type operator()(const MatType &q_map, uint_t state_idx) const
operator(). Given a
uint_t output_type
The type returned when calling this->operator().
Definition random_tabular_policy.h:31
output_type get_action(const MatType &q_map, uint_t state_idx)
get_action. Given a
void on_episode(uint_t) noexcept
any actions the policy should perform on the given episode index
Definition random_tabular_policy.h:76
void reset() noexcept
Reset the policy.
Definition random_tabular_policy.h:81
RandomTabularPolicy(uint_t seed)
Constructor Initialize with a seed.
Definition policy_stochastic_adaptor.h:21
Definition dummy_agent.h:9
Various utilities used when working with RL problems.
Definition bitrl_log.h:25
torch::Tensor torch_tensor_t
torch_tensor_t
Definition bitrl_types.h:95
std::size_t uint_t
uint_t
Definition bitsim_types.h:40
static std::vector< T > to_vector(torch_tensor_t tensor)