MachineIntelligenceCore:ReinforcementLearning
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
SpatialExperienceMemory.hpp
Go to the documentation of this file.
1 
23 #ifndef SRC_ALGORITHMS_EPERIENCEREPLAYTABLE_HPP_
24 #define SRC_ALGORITHMS_EPERIENCEREPLAYTABLE_HPP_
25 
26 #include <types/Batch.hpp>
27 #include <types/Position2D.hpp>
28 #include <types/MatrixTypes.hpp>
29 
30 
31 namespace mic {
32 namespace types {
33 
40  mic::types::Position2D s_t;
41 
43  mic::types::NESWAction a_t;
44 
46  mic::types::Position2D s_t_prim;
47 
54  SpatialExperience(mic::types::Position2D s_t_, mic::types::NESWAction a_t_, mic::types::Position2D s_t_prim_) {
55  s_t = s_t_;
56  a_t = a_t_;
57  s_t_prim = s_t_prim_;
58  }
59 
60 };
61 
66 typedef std::shared_ptr < mic::types::SpatialExperience> SpatialExperiencePtr;
67 
72 typedef mic::types::Sample<mic::types::SpatialExperience, mic::types::MatrixXf> SpatialExperienceSample;
73 
78 typedef mic::types::Batch<mic::types::SpatialExperience, mic::types::MatrixXf> SpatialExperienceBatch;
79 
80 
88 public:
89 
95  SpatialExperienceMemory(size_t number_of_experiences_, size_t batch_size_) : Batch(batch_size_), number_of_experiences(number_of_experiences_) {
96 
97  }
98 
103 
110  virtual void add(std::shared_ptr<mic::types::SpatialExperience> input_, std::shared_ptr<mic::types::MatrixXf> target_) {
111 
112  if (sample_data.size() == number_of_experiences) {
113  // Initialize uniform index distribution - integers.
114  std::uniform_int_distribution<> index_dist(0, this->sample_data.size()-1);
115 
116  // Pick an index.
117  unsigned int tmp_index= index_dist(rng_mt19937_64);
118 
119  // Erase the sample from all three lists.
120  sample_data.erase (sample_data.begin()+tmp_index);
121  sample_labels.erase (sample_labels.begin()+tmp_index);
122  sample_indices.erase (sample_indices.begin()+tmp_index);
123  }
124 
125  // Add sample to vectors.
126  sample_data.push_back(input_);
127  sample_labels.push_back(target_);
128  sample_indices.push_back(sample_indices.size());
129  }
130 
131 protected:
132 
135 };
136 
137 
138 
139 } /* namespace types */
140 } /* namespace mic */
141 
142 #endif /* SRC_ALGORITHMS_EPERIENCEREPLAYTABLE_HPP_ */
virtual void add(std::shared_ptr< mic::types::SpatialExperience > input_, std::shared_ptr< mic::types::MatrixXf > target_)
std::shared_ptr< mic::types::SpatialExperience > SpatialExperiencePtr
Shared pointer to spatial experience object.
mic::types::NESWAction a_t
Action at time t.
Structure storing a spatial experience - a triplet of position in time t, executed action and positio...
SpatialExperience(mic::types::Position2D s_t_, mic::types::NESWAction a_t_, mic::types::Position2D s_t_prim_)
SpatialExperienceMemory(size_t number_of_experiences_, size_t batch_size_)
size_t number_of_experiences
Size of the experience table (maximum number of stored experiences).
mic::types::Position2D s_t
State at time t.
mic::types::Batch< mic::types::SpatialExperience, mic::types::MatrixXf > SpatialExperienceBatch
Spatial experience replay batch.
mic::types::Position2D s_t_prim
State at time t+1 (t prim).
mic::types::Sample< mic::types::SpatialExperience, mic::types::MatrixXf > SpatialExperienceSample
Spatial experience replay sample.
Class representing the spatial experience memory - used in memory replay. Derived from the Batch clas...