25 #include <utils/DataCollector.hpp>
28 namespace application {
40 hidden_maze_number(
"hidden_maze", 0),
41 hidden_x(
"hidden_x", 0),
42 hidden_y(
"hidden_y", 0),
44 epsilon(
"epsilon", 0.0),
45 hit_factor(
"hit_factor", 0.6),
46 miss_factor(
"miss_factor", 0.2),
47 exact_move_probability(
"exact_move_probability", 1.0),
48 overshoot_move_probability(
"overshoot_move_probability", 0.0),
49 undershoot_move_probability(
"undershoot_move_probability", 0.0),
50 statistics_filename(
"statistics_filename",
"statistics_filename.csv")
68 LOG(LINFO) <<
"Properties registered";
82 VGL_MANAGER->initializeGLUT(argc, argv);
86 maze_collector_ptr = std::make_shared < mic::utils::DataCollector<std::string, float> >( );
107 LOG(LERROR) <<
"The dataset must consists of at least one maze!";
112 LOG(LNOTICE) <<
"Loaded mazes";
113 for (
size_t m=0; m<
importer.size(); m++) {
115 LOG(LNOTICE) <<
"maze(" <<m<<
"):\n" << (
importer.data()[m]);
129 std::vector<std::string> maze_pose_labels;
130 for (
size_t y=0; y < (size_t)
importer.data(0)->rows(); y++)
131 for (
size_t x=0; x < (size_t)
importer.data(0)->cols(); x++) {
132 std::string label =
"(" + std::to_string(y) +
";" + std::to_string(x) +
")";
133 maze_pose_labels.push_back(label);
135 mic::utils::DataCollector<std::string, std::string>::exportVectorToCsv(
statistics_filename,
"maze pose labels",maze_pose_labels,
true);
139 std::vector<int> obs_labels = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
140 mic::utils::DataCollector<std::string, int>::exportVectorToCsv(
statistics_filename,
"observation labels",obs_labels,
true);
159 mic::utils::DataCollector<std::string, short>::exportValueToCsv(
statistics_filename,
"First observation",
hf.
obs,
true);
179 std::random_device rd;
180 std::mt19937_64 rng_mt19937_64(rd());
182 std::uniform_int_distribution<> color_dist(50, 200);
184 for (
size_t m=0; m<
importer.size(); m++) {
185 std::string label =
"P(m" + std::to_string(m) +
")";
186 int r= color_dist(rng_mt19937_64);
187 int g= color_dist(rng_mt19937_64);
188 int b= color_dist(rng_mt19937_64);
198 std::string label =
"P(x" + std::to_string(x) +
")";
199 int r= color_dist(rng_mt19937_64);
200 int g= color_dist(rng_mt19937_64);
201 int b= color_dist(rng_mt19937_64);
211 std::string label =
"P(y" + std::to_string(y) +
")";
212 int r= color_dist(rng_mt19937_64);
213 int g= color_dist(rng_mt19937_64);
214 int b= color_dist(rng_mt19937_64);
235 APP_DATA_SYNCHRONIZATION_SCOPED_LOCK();
238 for (
size_t m=0; m<
importer.size(); m++) {
239 std::string label =
"P(m" + std::to_string(m) +
")";
245 std::string label =
"P(x" + std::to_string(x) +
")";
251 std::string label =
"P(y" + std::to_string(y) +
")";
263 for (
size_t m=0; m<
importer.size(); m++) {
264 std::string label =
"P(m" + std::to_string(m) +
")";
270 std::string label =
"P(x" + std::to_string(x) +
")";
276 std::string label =
"P(y" + std::to_string(y) +
")";
290 LOG(LINFO) <<
"Performing a single step (" << iteration <<
")";
292 short tmp_action =
action;
296 if (RAN_GEN->uniRandReal() < (double)
epsilon)
301 mic::types::Action2DInterface act;
304 act = A_RANDOM;
break;
310 act = mic::types::NESWAction((mic::types::NESW) (
short)tmp_action);
313 std:: string label =
"Action d_x at " + std::to_string(iteration);
314 mic::utils::DataCollector<std::string, int>::exportValueToCsv(
statistics_filename, label, act.dx,
true);
315 label =
"Action d_y at " + std::to_string(iteration);
316 mic::utils::DataCollector<std::string, int>::exportValueToCsv(
statistics_filename, label, act.dy,
true);
324 label =
"Observation (after motion) at " + std::to_string(iteration);
331 label =
"P(p) at " + std::to_string(iteration);
333 label =
"P(m) at " + std::to_string(iteration);
335 label =
"P(x) at " + std::to_string(iteration);
337 label =
"P(y) at " + std::to_string(iteration);
340 label =
"hidden_maze_number at " + std::to_string(iteration);
342 label =
"hidden_x at " + std::to_string(iteration);
344 label =
"hidden_y at " + std::to_string(iteration);
351 std::string tmp = filename.substr(0, (filename.find(
'.'))) +
"-convergence.csv";
void probabilisticMove(mic::types::Action2DInterface ac_, double exact_move_probability_, double overshoot_move_probability_, double undershoot_move_probability_)
void setHiddenPose(int hidden_maze_number_, int hidden_x_, int hidden_y_)
size_t maze_height
Height of a maze.
size_t maze_width
Width of a maze.
HistogramFilterMazeLocalization(std::string node_name_="application")
mic::configuration::Property< double > hit_factor
Property: variable denoting the hit factor (the gain when the observation coincides with current posi...
mic::configuration::Property< short > hidden_maze_number
Property: variable denoting in which maze are we right now (unknown, to be determined).
mic::configuration::Property< std::string > statistics_filename
Property: name of the file to which the statistics will be exported.
mic::utils::DataCollectorPtr< std::string, float > coordinate_y_collector_ptr
WindowCollectorChart< float > * w_current_maze_chart
Window for displaying chart with statistics on current maze number.
mic::configuration::Property< short > hidden_y
Property: variable denoting the y position are we right now (unknown, to be determined).
mic::utils::DataCollectorPtr< std::string, float > coordinate_x_collector_ptr
mic::importers::MazeMatrixImporter importer
Importer responsible for loading mazes from file.
WindowCollectorChart< float > * w_current_coordinate_x
Window for displaying chart with statistics on current x coordinate.
void assignInitialProbabilities()
mic::configuration::Property< double > miss_factor
Property: variable denoting the miss factor (the gain when the observation does not coincide with cur...
int hidden_maze_number
shortariable denoting in which maze are we right now (unknown, to be determined). ...
void storeCurrentStateInDataContainers(bool synchronize_)
Declaration of a class being a histogram filter based maze localization application.
Class implementing a histogram filter based solution of the maze-of-digits problem.
virtual bool performSingleStep()
WindowCollectorChart< float > * w_current_coordinate_y
Window for displaying chart with statistics on current y coordinate.
mic::configuration::Property< double > exact_move_probability
Property: variable storing the probability that we made the exact move (x+dx).
mic::configuration::Property< double > undershoot_move_probability
Property: variable storing the probability that we made the "undershoot" move (d+dx-1).
void sense(double hit_factor_, double miss_factor_)
virtual void initialize(int argc, char *argv[])
mic::utils::DataCollectorPtr< std::string, float > maze_collector_ptr
int hidden_x
Variable denoting the x position are we right now (unknown, to be determined).
mic::types::Action2DInterface sumOfMostUniquePatchesActionSelection()
mic::configuration::Property< short > hidden_x
Property: variable denoting the x position are we right now (unknown, to be determined).
mic::utils::DataCollectorPtr< std::string, float > max_probabilities_collector_ptr
Data collector with maximal maze/x/y/ probabilities.
mic::types::Action2DInterface mostUniquePatchActionSelection()
std::vector< double > maze_patch_probabilities
Variable storing the probability that we can find given patch in a given maze.
mic::configuration::Property< double > overshoot_move_probability
Property: variable storing the probability that we made the "overshoot" move (d+dx+1).
virtual void initializePropertyDependentVariables()
std::vector< double > maze_probabilities
Variable storing the probability that we are currently moving in/observing a given maze...
mic::configuration::Property< double > epsilon
Property: variable denoting epsilon in aciton selection (the probability "below" which a random actio...
std::vector< double > maze_y_coordinate_probilities
Variable storing the probability that we are currently in a given y coordinate.
void updateAggregatedProbabilities()
void setMazes(std::vector< mic::types::MatrixXiPtr > &mazes_, unsigned int number_of_distinctive_patches_)
mic::algorithms::MazeHistogramFilter hf
Histogram filter.
int hidden_y
Variable denoting the y position are we right now (unknown, to be determined).
std::vector< double > maze_x_coordinate_probilities
Variable storing the probability that we are currently in a given x coordinate.
short obs
Current Observation.
void RegisterApplication(void)
Registers application.
void createDataContainers()
WindowCollectorChart< float > * w_max_probabilities_chart
Window for displaying chart with maximal maze/x/y/ probabilities.
virtual ~HistogramFilterMazeLocalization()
mic::configuration::Property< short > action
Property: performed action (0-3: NESW, -3: random, -2: sumOfMostUniquePatchesActionSelection, -1: mostUniquePatchActionSelection).
std::vector< mic::types::MatrixXdPtr > maze_position_probabilities
Variable storing the probability that we are in a given maze position.