Commit ba31cf76 authored by Amelie Royer's avatar Amelie Royer

Cleaning up run script

parent 631d7f37
......@@ -56,7 +56,7 @@ namespace AIToolbox {
MEMCP(const M& m, size_t n_environments, size_t beliefSize, unsigned iterations, double exp);
/**
* @brief This function resets the internal graph and samples
* @brief This function resets the internal graph and samples
* for the provided belief and horizon.
*
*
......@@ -279,7 +279,7 @@ namespace AIToolbox {
/**
* @brief This function updates the full graph with the current state of the simulation.
* More precisely, the last branch/actionNode corresponding to the current history is
* More precisely, the last branch/actionNode corresponding to the current history is
* replaced by the currently build tree.
*
* @param current The subtree computed for action a.
......@@ -299,7 +299,7 @@ namespace AIToolbox {
graph_ = BeliefNode(A);
graph_.children.resize(A);
reset_belief = false;
}
}
// Reset with the stored information
else {
graph_ = fullgraph_;
......@@ -308,13 +308,13 @@ namespace AIToolbox {
if (start_session && history.size() == 0) {
fullgraph_ = BeliefNode(A);
fullgraph_.children.resize(A);
}
}
// Clear history if beginning
if (start_session) {
history.clear();
}
// Init the belief
// Init the belief
auto b = Belief(S); b.fill(0);
for (int u = 0; u < E; u++) {
b(u * O + o) = be(u);
......@@ -374,7 +374,7 @@ namespace AIToolbox {
// Modify
current_branch.children.resize(A);
current_branch.children[a] = current;
}
......
......@@ -282,7 +282,7 @@ int main(int argc, char* argv[]) {
// Load model parameters
auto start = std::chrono::high_resolution_clock::now();
std::cout << "\n" << current_time_str() << "- Loading model parameters\n";
std::cout << "\n" << current_time_str() << " - Loading model parameters\n";
assert(("Usage: ./main Param_basename [Discount] [solver steps]", argc >= 2));
std::string datafile_base = std::string(argv[1]);
init_pows();
......@@ -303,7 +303,7 @@ int main(int argc, char* argv[]) {
// Init Sparse Model in AIToolbox
start = std::chrono::high_resolution_clock::now();
RecoMEMDP world;
std::cout << "\n" << current_time_str() << "- Copying model [sparse]...!\n";
std::cout << "\n" << current_time_str() << " - Copying model [sparse]...!\n";
AIToolbox::POMDP::SparseModel<decltype(world)> model(world);
// Training
......@@ -321,7 +321,7 @@ int main(int argc, char* argv[]) {
AIToolbox::POMDP::POMCP<decltype(model)> solver(model, beliefSize, steps, exp);
training_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000000.;
start = std::chrono::high_resolution_clock::now();
std::cout << current_time_str() << "- Starting evaluation!\n";
std::cout << current_time_str() << " - Starting evaluation!\n";
evaluate_pomcp(datafile_base + ".test", solver, discount, horizon, rewards);
testing_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000000.;
}
......@@ -330,7 +330,7 @@ int main(int argc, char* argv[]) {
AIToolbox::POMDP::MEMCP<decltype(model)> solver(model, n_environments, beliefSize, steps, exp);
training_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000000.;
start = std::chrono::high_resolution_clock::now();
std::cout << current_time_str() << "- Starting evaluation!\n";
std::cout << current_time_str() << " - Starting evaluation!\n";
evaluate_memcp(datafile_base + ".test", solver, discount, horizon, rewards);
testing_time = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - start).count() / 1000000.;
}
......
#!/bin/bash
# PATHES
AIBUILD="/home/amelie/Libs/AI-Toolbox/build"
AIINCLUDE="/home/amelie/Libs/AI-Toolbox/include"
EIGEN="/usr/local/include/eigen3/"
LPSOLVE="/usr/local/lib/"
GCC="/usr/local/bin/gcc-4.9.0/bin/g++"
STDLIB="/usr/local/bin/gcc-4.9.0/lib64"
# DEFAULT ARGUMENTS
MODE="mdp"
DATA="fm"
PLEVEL="4"
HIST="2"
DISCOUNT="0.95"
STEPS="1500"
PRECISION="0"
HORIZON="1"
COMPILE=false
# SET ARGUMENTS FROM CMD LINE
while getopts "m:d:n:k:g:s:p:h:c" opt; do
case $opt in
m)
MODE=$OPTARG
;;
d)
DATA=$OPTARG
;;
n)
PLEVEL=$OPTARG
;;
k)
HIST=$OPTARG
;;
g)
DISCOUNT=$OPTARG
;;
s)
STEPS=$OPTARG
;;
p)
PRECISION=$OPTARG
;;
h)
HORIZON=$OPTARG
;;
c)
COMPILE=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
echo $COMPILE
# SET CORRECT DATA PATHS
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if [ $DATA = "fm" ]; then
PROFILES=6
ALPHA=1.10
printf -v BASE "$DIR/Models/Foodmart%d%d%d/foodmart_u%d_k%d_pl%d_a%.2f" "$PROFILES" "$HIST" "$PLEVEL" "$PROFILES" "$HIST" "$PLEVEL" "$ALPHA"
if [ ! -f "$BASE.items" ]; then
echo "File $BASE.items not found"
echo "exit"
exit 1
fi
NITEMS=$(($(wc -l < "$BASE.items") + 1))
elif [ $DATA = "rd" ]; then
PROFILES=$PLEVEL
NITEMS=$PLEVEL
printf -v BASE "$DIR/Models/Synth%d%d%d/synth_u%d_k%d_pl%d" "$PLEVEL" "$HIST" "$PLEVEL" "$PLEVEL" "$HIST" "$PLEVEL"
else
echo "Unkown data mode $DATA"
echo "exit"
exit 1
fi
# MDP
if [ $MODE = "mdp" ]; then
# COMPILE
if [ "$COMPILE" = true ]; then
echo
echo "Compiling MDP model in mainMDP"
$GCC -O3 -Wl,-rpath,$STDLIB -DNITEMSPRM=$NITEMS -DHISTPRM=$HIST -DNPROFILESPRM=$PROFILES -std=c++11 utils.cpp main_MDP.cpp -o mainMDP -I $AIINCLUDE -I $EIGEN -L $AIBUILD -l AIToolboxMDP -l AIToolboxPOMDP -l lpsolve55
if [ $? -ne 0 ]; then
echo "Compilation failed!"
echo "exit"
exit 1
fi
fi
# RUN
echo
echo "Running mainMDP on $BASE"
./mainMDP $BASE $DISCOUNT $STEPS $PRECISION
echo
# POMDPs
else
# COMPILE
if [ "$COMPILE" = true ]; then
echo
echo "Compiling MEMDP model in mainMEMDP"
$GCC -O3 -Wl,-rpath,$STDLIB -DNITEMSPRM=$NITEMS -DHISTPRM=$HIST -DNPROFILESPRM=$PROFILES -std=c++11 utils.cpp main_MEMDP.cpp -o mainMEMDP -I $AIINCLUDE -I $EIGEN -L $LPSOLVE -L $AIBUILD -l AIToolboxMDP -l AIToolboxPOMDP -l lpsolve55
if [ $? -ne 0 ]
then
echo "Compilation failed!"
echo "exit"
exit 1
fi
fi
# RUN
echo
echo "Running mainMEMDP on $BASE with $MODE solver"
./mainMEMDP $BASE $MODE $DISCOUNT $STEPS $PRECISION $HORIZON
echo
fi
\ No newline at end of file
#!/bin/bash
[[ "$#" > 0 ]] && PLEVEL="$1" || PLEVEL="4"
[[ "$#" > 1 ]] && HIST="$2" || HIST="2"
[[ "$#" > 2 ]] && PRECISION="$3" || PRECISION="0"
# GLOBAL VARIABLES
PROFILES=6
ALPHA=1.10
STEPS=1000000
PRECISION=0 #PRECISION=5 for 3 actions
DISCOUNT=0.95
echo "Foodmart"
echo
echo "MDP"
echo
./run_mdp.sh "fm" $PLEVEL $HIST $DISCOUNT $PRECISION
echo
echo "IP"
echo "too slow"
#./run_memdp.sh "fm" "IP" $PLEVEL $HIST 1 0.95 $PRECISION
echo
echo "POMCP"
echo
./run_memdp.sh "fm" "POMCP" $PLEVEL $HIST 1 0.95 $PRECISION
echo
echo "MEMCP"
echo
./run_memdp.sh "fm" "MEMCP" $PLEVEL $HIST 1 0.95 $PRECISION
echo "Random"
echo
echo "MDP"
echo
./run_mdp.sh "rd" $PLEVEL $HIST $DISCOUNT $PRECISION
echo
echo "IP"
echo "too slow"
#./run_memdp.sh "rd" "IP" $PLEVEL $HIST 1 0.95 $PRECISION
echo
echo "POMCP"
echo
./run_memdp.sh "rd" "POMCP" $PLEVEL $HIST 1 0.95 $PRECISION
echo
echo "MEMCP"
echo
./run_memdp.sh "rd" "MEMCP" $PLEVEL $HIST 1 0.95 $PRECISION
\ No newline at end of file
#!/bin/bash
AIBUILD="/home/amelie/Libs/AI-Toolbox/build"
AIINCLUDE="/home/amelie/Libs/AI-Toolbox/include"
EIGEN="/usr/local/include/eigen3/"
GCC="/usr/local/bin/gcc-4.9.0/bin/g++"
STDLIB="/usr/local/bin/gcc-4.9.0/lib64"
# PARAMETERS
[[ "$#" > 0 ]] && DATA="$1" || DATA="fm"
[[ "$#" > 1 ]] && PLEVEL="$2" || PLEVEL="4"
[[ "$#" > 2 ]] && HIST="$3" || HIST="2"
[[ "$#" > 3 ]] && DISCOUNT="$4" || DISCOUNT="0.95"
[[ "$#" > 4 ]] && PRECISION="$5" || PRECISION="0"
# GLOBAL VARIABLES
PROFILES=6
ALPHA=1.10
STEPS=1000000
#PRECISION=5 for 3 actions
# DATA PATH
if [ $DATA = "fm" ]; then
printf -v BASE '/home/amelie/Rotations/ChatterjeeRotation/Code/Models/Foodmart%d%d%d/foodmart_u%d_k%d_pl%d_a%.2f' "$PROFILES" "$HIST" "$PLEVEL" "$PROFILES" "$HIST" "$PLEVEL" "$ALPHA"
elif [ $DATA = "rd" ]; then
if [ $PLEVEL == "4" ]; then
PROFILES=3
elif [ $PLEVEL == "3" ]; then
PROFILES=22
elif [ $PLEVEL == "2" ]; then
PROFILES=45
fi
printf -v BASE '/home/amelie/Rotations/ChatterjeeRotation/Code/Models/Random%d%d%d/random_u%d_k%d_pl%d' "$PROFILES" "$HIST" "$PLEVEL" "$PROFILES" "$HIST" "$PLEVEL"
else
echo "Unkown data mode $DATA"
echo "exit"
exit 1
fi
if [ ! -f "$BASE.items" ]; then
echo "File $BASE.items not found"
echo "exit"
exit 1
fi
ITEMS=$(($(wc -l < "$BASE.items") + 1))
# COMPILE
echo
echo "Compiling MDP model in mainMDP"
$GCC -O3 -Wl,-rpath,$STDLIB -DNITEMSPRM=$ITEMS -DHISTPRM=$HIST -DNPROFILESPRM=$PROFILES -std=c++11 utils.cpp main_MDP.cpp -o mainMDP -I $AIINCLUDE -I $EIGEN -L $AIBUILD -l AIToolboxMDP -l AIToolboxPOMDP -l lpsolve55
if [ $? -ne 0 ]
then
echo "Compilation failed!"
echo "exit"
exit 1
fi
# RUN
echo
echo "Running mainMDP on $BASE"
./mainMDP $BASE $DISCOUNT $STEPS $PRECISION
echo
#!/bin/bash
AIBUILD="/home/amelie/Libs/AI-Toolbox/build"
AIINCLUDE="/home/amelie/Libs/AI-Toolbox/include"
EIGEN="/usr/local/include/eigen3/"
LPSOLVE="/usr/local/lib/"
GCC="/usr/local/bin/gcc-4.9.0/bin/g++"
STDLIB="/usr/local/bin/gcc-4.9.0/lib64"
# PARAMETERS
[[ "$#" > 0 ]] && DATA="$1" || DATA="fm"
[[ "$#" > 1 ]] && ALGO="$2" || ALGO="IP"
[[ "$#" > 2 ]] && PLEVEL="$3" || PLEVEL="4"
[[ "$#" > 3 ]] && HIST="$4" || HIST="2"
[[ "$#" > 4 ]] && HORIZON="$5" || HORIZON="90"
[[ "$#" > 5 ]] && DISCOUNT="$6" || DISCOUNT="0.95"
[[ "$#" > 6 ]] && PRECISION="$7" || PRECISION="0"
# GLOBAL VARIABLES
PROFILES=6
ALPHA=1.10
STEPS=5000
PRECISION=0
# DATA PATH
if [ $DATA = "fm" ]; then
printf -v BASE '/home/amelie/Rotations/ChatterjeeRotation/Code/Models/Foodmart%d%d%d/foodmart_u%d_k%d_pl%d_a%.2f' "$PROFILES" "$HIST" "$PLEVEL" "$PROFILES" "$HIST" "$PLEVEL" "$ALPHA"
elif [ $DATA = "rd" ]; then
if [ $PLEVEL = "4" ]; then
PROFILES=3
elif [ $PLEVEL = "3" ]; then
PROFILES=22
elif [ $PLEVEL = "2" ]; then
PROFILES=45
fi
printf -v BASE '/home/amelie/Rotations/ChatterjeeRotation/Code/Models/Random%d%d%d/random_u%d_k%d_pl%d' "$PROFILES" "$HIST" "$PLEVEL" "$PROFILES" "$HIST" "$PLEVEL"
else
echo "Unkown data mode $DATA"
echo "exit"
exit 1
fi
if [ ! -f "$BASE.items" ]; then
echo "File $BASE.items not found"
echo "exit"
exit 1
fi
ITEMS=$(($(wc -l < "$BASE.items") + 1))
# COMPILE
echo
echo "Compiling MEMDP model in mainMEMDP"
$GCC -O3 -Wl,-rpath,$STDLIB -DNITEMSPRM=$ITEMS -DHISTPRM=$HIST -DNPROFILESPRM=$PROFILES -std=c++11 utils.cpp main_MEMDP.cpp -o mainMEMDP -I $AIINCLUDE -I $EIGEN -L $LPSOLVE -L $AIBUILD -l AIToolboxMDP -l AIToolboxPOMDP -l lpsolve55
if [ $? -ne 0 ]
then
echo "Compilation failed!"
echo "exit"
exit 1
fi
# RUN
echo
echo "Running mainMEMDP on $BASE with $ALGO solver"
./mainMEMDP $BASE $ALGO $DISCOUNT $STEPS $PRECISION $HORIZON
echo
......@@ -22,7 +22,8 @@
#include <AIToolbox/MDP/Policies/Policy.hpp>
#include <AIToolbox/POMDP/Policies/Policy.hpp>
#include <AIToolbox/POMDP/Algorithms/POMCP.hpp>
#include <AIToolbox/POMDP/Algorithms/MEMCP.hpp>
#include "AIToolBox/MEMCP.hpp"
//#include <AIToolbox/POMDP/Algorithms/MEMCP.hpp>
#include <AIToolbox/POMDP/Types.hpp>
#include <AIToolbox/Types.hpp>
......
......@@ -31,8 +31,8 @@ def init_output_dir(plevel, hlength):
* ``output_base`` (*str*): base name for output files.
"""
import shutil
output_base = "random_u%d_k%d_pl%d" % (plevel, hlength, plevel)
output_dir = os.path.join(args.output, "Random%d%d%d" % (plevel, hlength, plevel))
output_base = "synth_u%d_k%d_pl%d" % (plevel, hlength, plevel)
output_dir = os.path.join(args.output, "Synth%d%d%d" % (plevel, hlength, plevel))
if os.path.isdir(output_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)
......
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