Commit 7c3b4dc9 authored by Petr NOVOTNY's avatar Petr NOVOTNY

initial commit

parents
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
1 1 1 1 1 1 1 1 1 1 1
1 2 0 1 0 1 9 1 0 f 1
1 0 0 1 0 1 0 1 0 0 1
1 f 3 0 f 0 f 7 0 0 1
1 0 1 1 0 0 0 1 1 0 1
1 0 1 0 0 + 0 0 0 0 1
1 0 1 1 0 0 0 1 1 f 1
1 0 0 1 1 0 1 1 0 0 1
1 0 0 0 f 0 0 1 0 0 1
1 4 1 0 0 0 0 4 0 5 1
1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 3 3 7 + 1 1
1 1 1 7 x 7 1
1 1 1 0 5 0 1
1 1 1 1 5 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 3 3 7 + 1 1
1 8 1 7 x 7 1
1 1 1 3 5 3 1
1 1 1 1 5 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 3 3 7 + 1 1
1 8 1 7 x 7 1
1 1 1 5 5 4 1
1 1 1 1 5 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 3 3 7 + 1 1
1 9 1 7 x 7 1
1 1 1 0 5 0 1
1 1 1 9 5 9 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 3 3 7 + 1 1
1 9 1 7 x 7 1
1 1 1 1 5 1 1
1 1 1 9 5 9 1
1 1 1 1 1 1 1
This diff is collapsed.
discount: 0.9
values: reward
states: first last
actions: left right
observations: oFirst oLast
start include: left
T: * : tiger : final 1.0
T: * : treasure : final 1.0
T: sense : tleft : tleft 1.0
T: sense : tright : tright 1.0
T: left : tleft : tiger 1.0
T: right : tright : tiger 1.0
T: left : tright : treasure 1.0
T: right : tleft : treasure 1.0
T: * : final : final 1.0
O: * : left : oLeft 1.0
O: * : right : oRight 1.0
R: * : treasure : * : * 1000.0
R: * : tleft : * : * 0.0
R: * : tright : * : * 0.0
R: * : final : * : * 0.0
R: * : tiger : * : * -1000.0
discount: 0.6
values: reward
states: tleft tright treasure tiger final
actions: sense left right
observations: oNormal oLeft oRight oTiger oTreasure oFinal
start include: tleft tright
T: * : tiger : final 1.0
T: * : treasure : final 1.0
T: sense : tleft : tleft 1.0
T: sense : tright : tright 1.0
T: left : tleft : tiger 1.0
T: right : tright : tiger 1.0
T: left : tright : treasure 1.0
T: right : tleft : treasure 1.0
T: * : final : final 1.0
O: * : tiger : oTiger 1.0
O: * : final : oFinal 1.0
O: * : treasure : oTreasure 1.0
O: * : tleft : oLeft 0.8
O: * : tright : oLeft 0.2
O: * : tleft : oRight 0.2
O: * : tright : oRight 0.8
R: * : treasure : * : * 10000.0
R: * : tleft : * : * -100.0
R: * : tright : * : * -100.0
R: * : final : * : * 0.0
R: * : tiger : * : * -10000.0
This diff is collapsed.
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: r, NewState: x5y5hNtuuuuuu, Iters: 51693;;LValue: 0.9, CurState: x5y5hNtuuuuuu, Action: l, NewState: x5y5hWtuuuuuu, Iters: 57829;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 64722;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 71540;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 82713;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 97219;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 50967;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 57449;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 63680;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 72767;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 82290;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 91155;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: f, NewState: x6y5hStuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x6y5hStuuuuuu, Action: r, NewState: x6y5hWtuuuuuu, Iters: 52359;;LValue: 0.9, CurState: x6y5hWtuuuuuu, Action: f, NewState: x6y4hWtuuuuuu, Iters: 58227;;LValue: 0.9, CurState: x6y4hWtuuuuuu, Action: r, NewState: x6y4hNtuuuuuu, Iters: 63974;;LValue: 0.9, CurState: x6y4hNtuuuuuu, Action: f, NewState: x5y4hNtuuuuuu, Iters: 71409;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 82633;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 96651;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: l, NewState: x5y5hEtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hEtuuuuuu, Action: r, NewState: x5y5hStuuuuuu, Iters: 7035;;LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 58598;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 65291;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 72319;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 82310;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 96676;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 51607;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 57405;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 64048;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 72555;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 83639;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 96003;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0, CurState: x5y5hStuuuuuu, Action: l, NewState: x5y5hEtuuuuuu, Iters: 100000;;LValue: 0, CurState: x5y5hEtuuuuuu, Action: f, NewState: x5y6hEtuuuuuu, Iters: 50821;;LValue: 0, CurState: x5y6hEtuuuuuu, Action: r, NewState: x5y6hStuuuuuu, Iters: 56702;;LValue: 0, CurState: x5y6hStuuuuuu, Action: f, NewState: x6y6hStuuuuuu, Iters: 62575;;LValue: 0, CurState: x6y6hStuuuuuu, Action: f, NewState: x6y6hStuuuuuu, Iters: 69729;;LValue: 0, CurState: x6y6hStuuuuuu, Action: r, NewState: x6y6hWtuuuuuu, Iters: 77778;;LValue: 0, CurState: x6y6hWtuuuuuu, Action: r, NewState: x6y6hNtuuuuuu, Iters: 89806;;LValue: 0, CurState: x6y6hNtuuuuuu, Action: r, NewState: x6y6hEtuuuuuu, Iters: 100000;;LValue: 0, CurState: x6y6hEtuuuuuu, Action: r, NewState: x6y6hStuuuuuu, Iters: 100000;;LValue: 0, CurState: x6y6hStuuuuuu, Action: r, NewState: x6y6hWtuuuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 50451;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 56693;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 63482;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 71859;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 81784;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 93694;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 51586;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 56844;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 63282;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 71007;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 81017;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 93268;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 51698;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 57023;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 63515;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 71763;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 82137;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 93762;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
LValue: 0.9, CurState: x5y5hStuuuuuu, Action: r, NewState: x5y5hWtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: r, NewState: x5y5hNtuuuuuu, Iters: 50982;;LValue: 0.9, CurState: x5y5hNtuuuuuu, Action: l, NewState: x5y5hWtuuuuuu, Iters: 56698;;LValue: 0.9, CurState: x5y5hWtuuuuuu, Action: f, NewState: x5y4hWtuuuuuu, Iters: 63461;;LValue: 0.9, CurState: x5y4hWtuuuuuu, Action: r, NewState: x5y4hNtuuuuuu, Iters: 71420;;LValue: 0.9, CurState: x5y4hNtuuuuuu, Action: f, NewState: x4y4hNtuuuuuu, Iters: 81972;;LValue: 0.9, CurState: x4y4hNtuuuuuu, Action: f, NewState: x3y4hNtuuuuuu, Iters: 95442;;LValue: 0.9, CurState: x3y4hNtuuuuuu, Action: f, NewState: x2y4hNtuuuuuu, Iters: 100000;;LValue: 0.9, CurState: x2y4hNtuuuuuu, Action: f, NewState: x1y4hNgtumuuuu, Iters: 100000;;LValue: 1, CurState: x1y4hNgtumuuuu, Action: f, NewState: x1y4hNtumuuuu, Iters: 100000;;
Test finished without issues.
AITOOLBOXDIR = /home/pnovotny/programs/AI-Toolbox-2
CPLEXDIR = /usr/local/ILOG/CPLEX_Studio/cplex
CONCERTDIR = /usr/local/ILOG/CPLEX_Studio/concert
SYSTEM = x86-64_linux
LIBFORMAT = static_pic
dspomdp-bwc: cassandra-lexer.cpp cassandra-parser.cpp cassandra-driver.h \
cassandra-driver.cpp main.cpp pomdp.h pomdp.cpp cassandra-parser.h \
dsgame.h dsgame.cpp BWCPOMCP.hpp
c++ -O3 -std=c++11 cassandra-lexer.cpp cassandra-parser.cpp \
cassandra-driver.cpp pomdp.cpp dsgame.cpp main.cpp \
-I/usr/local/include \
-I/usr/include/eigen3 \
-I/home/orouille/lib/AI-Toolbox/include \
-I/home/orouille/lib/cplex/cplex/include \
-L/usr/local/lib \
-L/home/orouille/lib/AI-Toolbox/build \
-L/home/orouille/lib/cplex/concert/lib \
-lz3 -lAIToolboxMDP -lAIToolboxPOMDP -o dspomdp-bwc
test-sim: cassandra-lexer.cpp cassandra-parser.cpp cassandra-driver.h \
cassandra-driver.cpp test.cpp pomdp.h pomdp.cpp cassandra-parser.h \
dsgame.h dsgame.cpp BWCPOMCP.hpp
c++ -g -O3 -DIL_STD -std=c++11 cassandra-lexer.cpp cassandra-parser.cpp \
cassandra-driver.cpp pomdp.cpp dsgame.cpp test.cpp \
-I/usr/local/include \
-I/usr/include/eigen3 \
-I$(AITOOLBOXDIR)/include \
-I$(CPLEXDIR)/include \
-I$(CONCERTDIR)/include \
-L/usr/local/lib \
-L$(AITOOLBOXDIR)/build \
-L$(CPLEXDIR)/lib/$(SYSTEM)/$(LIBFORMAT) \
-L$(CONCERTDIR)/lib/$(SYSTEM)/$(LIBFORMAT) \
-lz3 -lAIToolboxMDP -lAIToolboxPOMDP \
-lconcert -lilocplex -lcplex -lm -lpthread -lboost_timer -lboost_system\
-o test-sim
cassandra-lexer.cpp: cassandra-parser.h cassandra.l
flex --outfile=cassandra-lexer.cpp cassandra.l
cassandra-parser.h: cassandra.y
bison --defines=cassandra-parser.h \
--output=cassandra-parser.cpp cassandra.y
cassandra-parser.cpp: cassandra.y
bison --defines=cassandra-parser.h \
--output=cassandra-parser.cpp cassandra.y
clean:
rm cassandra-parser.h cassandra-parser.cpp \
cassandra-lexer.cpp location.hh position.hh \
stack.hh dspomdp-bwc
Requirements
============
AI-toolbox from 14/01/17 https://github.com/Svalorzen/AI-Toolbox/commit/efd6589056081e923193524132017120950c04a2
CPLEX/CONCERT from IBM
Build Instructions
==================
Use "make test-sim". Requires to fill the firsts lines of the makefile.
Launch Tests
============
There is only one command to launch tests:
./test-sim path_to_POMDP_file threshold n_steps n_runs initial_confidence exploration_constant sim_method gathering_method
Where:
- path_to_POMDP_file is a path to the POMDP file;
- threshold is the reward to obtain with a probability of at least initial_confidence;
- n_steps is the total number of steps of a run;
- n_runs is the number of runs;
- initial_confidence is the initial confidence;
- exploration_constant is POMCP's exploration constant;
- sim_method corresponds to the simulation method: 1 for rollouts from the root and 0 for POMCP;
- gathering_method is the method used to study the exploration tree: 0 for a list based method, 1 for linear programming
This will output, step by step, the runs in the terminal. Four files are created:
- *.res: provides the result of a test (one command), in one line provides the input received,
the average payoff of the test, and the observed probability to beat the threshold.
- *.time: provides, in second, the time of each step of each run.
- *.sum:
- *.log:
Structure of the code
=====================
The only file significantly modified is BWCPOMCP. Several functions are the same as in the original code.
Notable functions:
- sampleAction: initialises or truncate the exploration tree, calls runSimulation;
- runSimulation: launches all the POMCP simulations, for each that beat the threshold launches an exact simulation,
then builds the lists and picks the best action;
- simulatePOMCP: identical to the former simulate;
- simulateExact: given the trace of a simulation, compute the exact belief states and probabilities along the path.
- *Gather: functions used to gather informations from the exploration tree.
- linearSolving* : functions used to gather informations from the exploration tree with linear programming.
#include "cassandra-driver.h"
#include "cassandra-parser.h"
const double epsilon = 0.000001L;
CassDriver::CassDriver(BWC::POMDP* p) :
trace_scanning(false), trace_parsing(false), pomdp(p),
has_det_obs(true) { }
int CassDriver::parse(const std::string &f) {
this->file = f;
beginScan();
yy::CassParser parser(*this);
parser.set_debug_level(this->trace_parsing);
int res = parser.parse();
endScan();
// if the observations are not deterministic, we should make them
// if (!this->has_det_obs) {
//assert(this->pomdp->isValidMdp());
//this->pomdp->makeObsDet();
//}
return res;
}
void CassDriver::error(const yy::location &l, const std::string &m) {
std::cerr << l << ": " << m << std::endl;
}
void CassDriver::error(const std::string &m) {
std::cerr << "error: " << m << std::endl;
}
void CassDriver::addTransition(ElemRef source, ElemRef action, ElemRef target,
double prob) {
assert(source.type == ELEMREFTYPE_NAME);
assert(target.type == ELEMREFTYPE_NAME);
assert(action.type != ELEMREFTYPE_ID);
std::vector<int> dummy_act_vector;
std::vector<int>::iterator a_it;
std::vector<int>::iterator a_end;
if (action.type == ELEMREFTYPE_NAME) {
dummy_act_vector.push_back(this->pomdp->getActionId(action.name));
a_it = dummy_act_vector.begin();
a_end = dummy_act_vector.end();
} else if (action.type == ELEMREFTYPE_ALL) {
for (int i = 0; i < this->pomdp->getActionCount(); i++)
dummy_act_vector.push_back(i);
a_it = dummy_act_vector.begin();
a_end = dummy_act_vector.end();
}
for (; a_it != a_end; ++a_it) {
this->pomdp->addTransition(this->pomdp->getStateId(source.name),
*a_it,
this->pomdp->getStateId(target.name),
prob);
}
}
void addWeightHelper2(BWC::POMDP* p, int source,
int action, ElemRef target, double weight) {
if (target.type == ELEMREFTYPE_ALL)
for (int i = 0; i < p->getStateCount(); i++)
p->weightTransition(source, action, i, weight);
else
p->weightTransition(source, action,
p->getStateId(target.name),
weight);
}
void addWeightHelper1(BWC::POMDP* p, int source,
ElemRef action, ElemRef target, double weight) {
if (action.type == ELEMREFTYPE_ALL)
for (int i = 0; i < p->getActionCount(); i++)
addWeightHelper2(p, source, i, target, weight);
else
addWeightHelper2(p, source, p->getActionId(action.name),
target, weight);
}
void CassDriver::addWeight(ElemRef source, ElemRef action, ElemRef target,
ElemRef obs, double weight) {
assert(obs.type == ELEMREFTYPE_ALL);
assert(source.type != ELEMREFTYPE_ID);
assert(action.type != ELEMREFTYPE_ID);
assert(target.type != ELEMREFTYPE_ID);
if (source.type == ELEMREFTYPE_ALL)
for (int i = 0; i < this->pomdp->getStateCount(); i++)
addWeightHelper1(this->pomdp, i, action, target,
weight * this->weight_sign);
else
addWeightHelper1(this->pomdp, this->pomdp->getStateId(source.name),
action, target, weight * this->weight_sign);
}
void CassDriver::addObsTransition(ElemRef action, ElemRef target, ElemRef obs,
double prob) {
assert(action.type == ELEMREFTYPE_ALL);
assert(target.type == ELEMREFTYPE_NAME);
assert(obs.type == ELEMREFTYPE_NAME);
this->pomdp->addObservationProb(this->pomdp->getStateId(target.name),
this->pomdp->getObservationId(obs.name),
prob);
this->has_det_obs = this->has_det_obs &&
((std::abs(prob - 1.0L) < epsilon) ||
(std::abs(prob) < epsilon));
}
void CassDriver::setDiscount(double discount) {
this->pomdp->setDiscFactor(discount);
}
void CassDriver::setWeightSign(int sign) {
this->weight_sign = sign;
}
void CassDriver::setStates(std::vector<std::string> states) {
this->pomdp->setStates(states);
}
void CassDriver::setActions(std::vector<std::string> actions) {
this->pomdp->setActions(actions);
}
void CassDriver::setObservations(std::vector<std::string> observations) {
this->pomdp->setObservations(observations);
}
void CassDriver::setInitialDist(std::vector<ElemRef> states) {
std::map<int, double> initial_dist;
double denominator = states.size();
for (std::vector<ElemRef>::iterator i = states.begin();
i != states.end(); ++i) {
assert(i->type == ELEMREFTYPE_NAME);
initial_dist[this->pomdp->getStateId(i->name)] = 1.0/denominator;
}
this->pomdp->setInitialDist(initial_dist);
}
void CassDriver::setInitialDist(std::vector<double> probs) {
assert(probs.size() == this->pomdp->getStateCount());
std::map<int, double> initial_dist;
for (int i = 0; i < probs.size(); i++)
if (probs[i] > 0.0)
initial_dist[i] = probs[i];
this->pomdp->setInitialDist(initial_dist);
}
#ifndef CASS_DRIVER_H
#define CASS_DRIVER_H
#include <string>
#include <map>
#include "cassandra-parser.h"
#include "pomdp.h"
// tell flex the prototype of the lexer
#define YY_DECL \
yy::CassParser::symbol_type yylex(CassDriver &driver)
// and instantiate it for the parser
YY_DECL;
class CassDriver {
protected:
BWC::POMDP* pomdp;
double discount_factor;
int weight_sign;
bool has_det_obs;
public:
CassDriver(BWC::POMDP*);
int result;
// Scan handling
void beginScan();
void endScan();
bool trace_scanning;
// parse file f, return 0 on success
int parse(const std::string &f);
std::string file;
bool trace_parsing;
// Error handling
void error(const yy::location &l, const std::string &m);
void error(const std::string &m);
// Building an MDP
void addTransition(ElemRef source, ElemRef action, ElemRef target,
double prob);
void addWeight(ElemRef source, ElemRef action, ElemRef target,
ElemRef obs, double weight);
void addObsTransition(ElemRef action, ElemRef target, ElemRef obs,
double prob);
void setDiscount(double discount);
void setWeightSign(int sign);
void setStates(std::vector<std::string> states);
void setActions(std::vector<std::string> actions);
void setObservations(std::vector<std::string> observations);
void setInitialDist(std::vector<ElemRef> states);
void setInitialDist(std::vector<double> probs);
};
#endif // CASS_DRIVER_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
%{ /* -*- C++ -*- */
#include <cerrno>
#include <climits>
#include <cstdlib>
#include <string>
#include "cassandra-driver.h"
#include "cassandra-parser.h"
// work around an incompatibility in flex
#undef yywrap
#define yywrap() 1
// the location of the token
static yy::location loc;
%}
%option noyywrap nounput batch debug noinput
%{
// Code ran every time a pattern is matched
#define YY_USER_ACTION loc.columns(yyleng);
%}
%%
%{
// Code called every time yylex is called
loc.step();
%}
#[^$]*$ loc.step(); /* ignore comments */
[\n]+ loc.lines(yyleng); loc.step(); /* ignore end of line */
[ \t]+ loc.step(); /* ignore whitespace */
discount return yy::CassParser::make_DISCOUNT(loc);
values return yy::CassParser::make_VALUES(loc);
states return yy::CassParser::make_STATES(loc);
actions return yy::CassParser::make_ACTIONS(loc);
observations return yy::CassParser::make_OBSERVATIONS(loc);
T return yy::CassParser::make_T(loc);
O return yy::CassParser::make_O(loc);
R return yy::CassParser::make_R(loc);
uniform return yy::CassParser::make_UNIFORM(loc);
identity return yy::CassParser::make_IDENTITY(loc);
reward return yy::CassParser::make_REWARD(loc);
cost return yy::CassParser::make_COST(loc);
start return yy::CassParser::make_START(loc);
include return yy::CassParser::make_INCLUDE(loc);
exclude return yy::CassParser::make_EXCLUDE(loc);
reset return yy::CassParser::make_RESET(loc);
: return yy::CassParser::make_COLON(loc);
"*" return yy::CassParser::make_ASTERISK(loc);
"+" return yy::CassParser::make_PLUS(loc);
"-" return yy::CassParser::make_MINUS(loc);
0|[1-9][0-9]* {
errno = 0;
long n = strtol(yytext, NULL, 10);
if (!(INT_MIN <= n && n <= INT_MAX && errno != ERANGE))
driver.error(loc, "integer is out of range");
return yy::CassParser::make_INT(n, loc);
}
([0-9]+"."[0-9]*|"."[0-9]+|[0-9]+)([eE][-+]?[0-9]+)? {
errno = 0;
double n = strtod(yytext, NULL);
return yy::CassParser::make_FLOAT(n, loc);
}
[a-zA-Z]([a-zA-Z0-9]|[\_\-])* {
return yy::CassParser::make_STRING(yytext, loc);
}
<<EOF>> return yy::CassParser::make_END(loc);
%%
void CassDriver::beginScan() {
yy_flex_debug = trace_scanning;
if (file.empty() || file == "-")
yyin = stdin;
else if (!(yyin = fopen(file.c_str(), "r"))) {
error("cannot open " + file + ": " + strerror(errno));
exit(EXIT_FAILURE);
}
}
void CassDriver::endScan() {
fclose(yyin);
}
This diff is collapsed.
from __future__ import division
__author__ = 'pnovotny'
import sys
import csv
# USAGE compute_exp_confidence.py resfile
fileName = sys.argv[1]
gather = []
results = []
file = open(fileName,'rb')
reader = csv.reader(file,dialect = 'excel')
for line in reader:
gather.append(float(line[0]))
file.close()
gather.sort()
curVal = float("-inf")
length=len(gather)
i=0
for val in gather:
if val == curVal:
i=i+1
continue
else:
curVal = val
prob = (length - i)/length
results.append([val,prob])
i=i+1
#i = i+1
outFileName = fileName[:-4]
outFileName = outFileName + ".conf"
outFile = open(outFileName,'wb')
writer = csv.writer(outFile)
for item in results:
writer.writerow(item)
outFile.close()