34 stream.open(filename);
35 if (!stream.is_open())
36 throw std::runtime_error(
"cannot open action values file");
38 std::vector<std::vector<double>> av;
39 while(std::getline(stream, line))
45 throw std::runtime_error(
46 "number of values not equal to number of actions");
47 std::vector<double> row(A);
48 for (
size_t i = 0;
i <
A;
i++)
49 row[
i] = std::stod(vect[
i]);
54 throw std::runtime_error(
55 "The number of lines in the file is not equal to the nnumber of states");
66 if (lowerBound > upperBound)
68 throw std::invalid_argument(
"The lower bound is greater than the upper bound");
71 std::vector<std::vector<double>> av(S, std::vector<double>(A));
72 for (
size_t s = 0; s <
S; s++)
74 for (
size_t a = 0; a <
A; a++)
84 std::vector<std::vector<double>> av(S, std::vector<double>(A, value));
90 size_t S = context->stateSpace->size();
91 size_t A = context->actionSpace->size();
93 std::string str = context->conf->getStringValue(
"reinforcementLearning",
"actionValuesInitialization");
94 if (!str.compare(
"uniform"))
96 double initialAV = context->conf->getDoubleValue(
"reinforcementLearning",
"initialActionValue");
99 else if (!str.compare(
"fromFile"))
103 else if (!str.compare(
"random"))
105 time_t seed = context->conf->getIntValue(
"reinforcementLearning",
"seed");
106 double lowerBound = context->conf->getDoubleValue(
"reinforcementLearning",
"lowerBound");
107 double upperBound = context->conf->getDoubleValue(
"reinforcementLearning",
"upperBound");
112 throw std::invalid_argument(
"invalid value for actionValuesInitialization");
std::vector< std::vector< double > > fromFile(size_t S, size_t A, std::string filename)
void init(std::shared_ptr< Context > context)
void updateValue(state_t state, action_t action, double value)
double getValue(state_t state, action_t action) override
std::vector< std::vector< double > > randomly(size_t S, size_t A, time_t seed, double lowerBound, double upperBound)
std::vector< std::vector< double > > uniformly(size_t S, size_t A, double initialActionValues)
std::vector< double > getValues(state_t state) override
std::vector< std::vector< double > > actionValues
TabularActionValues(std::shared_ptr< Context > context)
static std::vector< std::string > split(std::string str, char delimiter)
double drawUniform(double min, double max)