1#ifndef EXPERIENCE_BUFFER_H
2#define EXPERIENCE_BUFFER_H
4#include "bitrl/bitrl_config.h"
11#include <boost/noncopyable.hpp>
12#include <boost/circular_buffer.hpp>
25template<
typename ExperienceType>
36 typedef typename boost::circular_buffer<ExperienceType>::iterator
iterator;
37 typedef typename boost::circular_buffer<ExperienceType>::const_iterator
const_iterator;
38 typedef typename boost::circular_buffer<ExperienceType>::reverse_iterator
reverse_iterator;
103 template<
typename BatchTp>
109 template<
typename ContainerType>
115 template<
typename ContainerType>
135 boost::circular_buffer<ExperienceType> buffer_;
139template<
typename ExperienceTp>
145template<
typename ExperienceTp>
151template<
typename ExperienceTp>
158template<
typename ExperienceTp>
164template<
typename ExperienceTp>
165template<
typename BatchTp>
171 assert(!empty() &&
"Cannot sample from an empty buffer");
176 assert(
false &&
"Cannot sample with zero batch_size");
184 std::vector<real_t>
weights(size(), 1.0/
static_cast<real_t>(size()));
191 batch.push_back(buffer_[idx]);
196template<
typename ExperienceType>
197template<
typename ContainerType>
201 for(
auto val: buffer_){
206template<
typename ExperienceType>
207template<
typename ContainerType>
213 for(
auto val: buffer_){
The ExperienceBuffer class. A buffer based on boost::circular_buffer to accumulate items of type Expe...
Definition experience_buffer.h:26
void sample(uint_t batch_size, BatchTp &batch, uint_t seed=42) const
sample. Sample batch_size experiences from the buffer and transfer them in the BatchTp container.
Definition experience_buffer.h:167
ExperienceType value_type
Definition experience_buffer.h:32
boost::circular_buffer< ExperienceType >::reverse_iterator reverse_iterator
Definition experience_buffer.h:38
reverse_iterator rbegin()
Definition experience_buffer.h:124
void clear() noexcept
clear
Definition experience_buffer.h:77
void resize(uint_t new_size, const experience_type &item=experience_type())
Resize the buffer.
Definition experience_buffer.h:160
boost::circular_buffer< ExperienceType >::iterator iterator
Definition experience_buffer.h:36
static const uint_t DEFAULT_CAPACITY
Definition experience_buffer.h:30
boost::circular_buffer< ExperienceType >::const_iterator const_iterator
Definition experience_buffer.h:37
value_type & operator[](uint_t idx)
operator []
Definition experience_buffer.h:84
bool empty() const noexcept
empty. Returns true if the buffer is empty
Definition experience_buffer.h:72
const_iterator end() const
Definition experience_buffer.h:122
uint_t size() const noexcept
size
Definition experience_buffer.h:60
ExperienceType experience_type
Definition experience_buffer.h:33
iterator begin()
Definition experience_buffer.h:118
iterator end()
Definition experience_buffer.h:119
ExperienceBuffer()
ExperienceBuffer.
Definition experience_buffer.h:140
boost::circular_buffer< ExperienceType >::const_reverse_iterator const_reverse_iterator
Definition experience_buffer.h:39
const value_type & operator[](uint_t idx) const
operator []
Definition experience_buffer.h:97
ContainerType get() const
Copy the contents of the buffer to the given container.
Definition experience_buffer.h:209
const_iterator begin() const
Definition experience_buffer.h:121
reverse_iterator rend()
Definition experience_buffer.h:125
uint_t capacity() const noexcept
capacity
Definition experience_buffer.h:66
void append(const experience_type &experience)
append Add the experience item in the buffer
Definition experience_buffer.h:153
const_reverse_iterator rbegin() const
Definition experience_buffer.h:127
const_reverse_iterator rend() const
Definition experience_buffer.h:128
OutT resolve(const std::string &name, const std::map< std::string, std::any > &input)
Definition std_map_utils.h:25
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