Commit 526bbccd authored by Amelie Royer's avatar Amelie Royer

Removing SparseModel initialization. The custom-made RecoM*P classes already...

Removing SparseModel initialization. The custom-made RecoM*P classes already take the sparsity into account
parent 130e701a
This diff is collapsed.
......@@ -14,8 +14,6 @@
#include <AIToolbox/MDP/IO.hpp>
#include <AIToolbox/MDP/Algorithms/ValueIteration.hpp>
#include <AIToolbox/MDP/SparseModel.hpp>
#include <AIToolbox/MDP/Model.hpp>
/*
* Global variables
......@@ -274,14 +272,10 @@ int main(int argc, char* argv[]) {
assert(("Out of range discount parameter", discount > 0 && discount <= 1));
// Init Sparse Model in AIToolbox
start = std::chrono::high_resolution_clock::now();
RecoMDP world;
std::cout << "\n" << current_time_str() << " - Copying model [sparse]...!\n";
AIToolbox::MDP::SparseModel model(world, precision);
// Solve
start = std::chrono::high_resolution_clock::now();
std::cout << current_time_str() << " - Init solver...!\n";
RecoMDP model;
AIToolbox::MDP::ValueIteration<decltype(model)> solver(steps, epsilon);
std::cout << current_time_str() << " - Starting solver!\n";
auto solution = solver(model);
......@@ -292,7 +286,7 @@ int main(int argc, char* argv[]) {
// Build and Evaluate Policy
start = std::chrono::high_resolution_clock::now();
std::cout << "\n" << current_time_str() << " - Evaluation results\n";
AIToolbox::MDP::Policy policy(world.getS(), world.getA(), std::get<1>(solution));
AIToolbox::MDP::Policy policy(n_observations, n_actions, std::get<1>(solution));
evaluate_policyMDP(datafile_base + ".test", policy, discount, rewards);
elapsed = std::chrono::high_resolution_clock::now() - start;
double testing_time = std::chrono::duration_cast<std::chrono::microseconds>(elapsed).count() / 1000000.;
......
......@@ -13,9 +13,6 @@
#include "utils.hpp"
#include <AIToolbox/POMDP/IO.hpp>
#include <AIToolbox/MDP/SparseModel.hpp>
#include <AIToolbox/MDP/Model.hpp>
#include <AIToolbox/POMDP/SparseModel.hpp>
#include <AIToolbox/POMDP/Algorithms/IncrementalPruning.hpp>
......@@ -321,24 +318,11 @@ int main(int argc, char* argv[]) {
sizeof(rewards) / sizeof(**rewards) == n_observations * n_actions));
assert(("Out of range discount parameter", discount > 0 && discount <= 1));
// Init Sparse Model in AIToolbox
start = std::chrono::high_resolution_clock::now();
RecoMEMDP world;
std::cout << "\n" << current_time_str() << " - Copying model [sparse]...!\n";
/*
auto obfunc = new double[n_states][n_actions][n_observations]();
for (size_t s1 = 0; s1 < n_states; s1++) {
for (size_t a = 0; a < n_actions; a++) {
obfunc[s1][a][get_rep(s1)] = 1.;
}
}
AIToolbox::POMDP::SparseModel<AIToolbox::MDP::SparseModel> model(world.getO(), obfunc, world, precision);*/
AIToolbox::POMDP::SparseModel<decltype(world)> model(world);
// Training
double training_time, testing_time;
start = std::chrono::high_resolution_clock::now();
std::cout << current_time_str() << " - Init " << algo << " solver...!\n";
RecoMEMDP model;
// Evaluation
// POMCP
......@@ -370,7 +354,7 @@ int main(int argc, char* argv[]) {
// Build and Evaluate Policy
start = std::chrono::high_resolution_clock::now();
std::cout << "\n" << current_time_str() << " - Evaluation results\n";
AIToolbox::POMDP::Policy policy(world.getS(), world.getA(), world.getO(), std::get<1>(solution));
AIToolbox::POMDP::Policy policy(n_states, n_actions, n_observations, std::get<1>(solution));
evaluate_policyMEMDP(datafile_base + ".test", policy, discount, horizon, rewards);
testing_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000000.;
}
......@@ -381,7 +365,7 @@ int main(int argc, char* argv[]) {
std::cout << " > Training : " << training_time << "s\n";
std::cout << " > Testing : " << testing_time << "s\n";
// Save policy in file
// Save policy or pomcp seach tree in file
/*
* TODO
*/
......
......@@ -20,17 +20,6 @@ make -j
ctest -V
```
##### 3. Optional step
(``root`` designates the directory containing this README file).
```bash
cd AIToolbox_root/include/AIToolbox/MDP/
mv SparseModel.hpp SparseModel_backup.hpp
cp root/Code/AiToolBox/SparseModel.hpp SparseModel.hpp
```
This file contains an updated version of the constructor ``SparseModel(model)``, and is identical to the default AITB SparseModel otherwise. In fact, when dealing with the foodmart dataset for large state spaces, the probabilities in the transition function might become very low, which conflicts with the Eigen summation that AIToolbox uses by default in the creation of a SparseModel (approximation error). To prevent this, the new constructor can use *Kahan Summation* by setting the second (optional, defaulting to false) argument to true: ``SparseModel(model, true)``.
#### Generating the data (``Data/`` folder)
......@@ -85,7 +74,7 @@ If needed, first set the correct library pathes in ``run.sh``. The script can th
* ``[8]`` Convergence criterion for mdp and ip. Defaults to 0.01.
* ``[9]`` Exploration parameter for pomcp and memcp. Defaults to 10000 (high exploration).
* ``[10]`` Number of particles for the belief approximation in pomcp and memcp. Defaults to 100.
* ``[-p]`` If present, use Kahan summation for more precision while handling small probabilities. Use this option if AIToolbox throws an ``Input transition table does not contain valid probabilities`` error when creating the SparseModel object. (*Note*: this requires to use the ``SparseModel.hpp`` file given in ``Code/AiToolBox`` instead of the default AIToolbox one, as described in the first section).
* ``[-p]`` If present, use Kahan summation for more precision while handling small probabilities. Use this option if AIToolbox throws an ``Input transition table does not contain valid probabilities`` error.
* ``[-c]`` If present, recompile the code before running (*Note*: this should be used whenever using a dataset with different parameters as the number of items, environments etc are determined at compilation time).
**Example** *(foodmart, 6 environments, 3 actions, 13 states)* :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment