double FiniteBudgetModelIR::getExpectedReward(size_t s, size_t a, size_t) const { size_t ap; std::tie(std::ignore, ap) = decodeAction(a); auto trueS = convertToNormalState(s); return trueS == ap; }
// generate an action distributed according to our history statistics action_t Agent::genAction(void) const { assert(m_last_update == percept_update); // sample from context tree symbol_list_t action_syms; m_ct->genRandomSymbols(action_syms, m_env.actionBits()); // decode sample return decodeAction(action_syms); }
std::tuple<size_t, double> FiniteBudgetModelIR::sampleSR(size_t s, size_t a) const { auto trueS = convertToNormalState(s); auto budget = getRemainingBudget(s); size_t an, ap; std::tie(an, ap) = decodeAction(a); size_t trueS1 = sampleTrajectoryTransition(trueS); auto s1 = makeState(trueS1, an == worldWidth_ ? budget : budget + 1); return std::make_tuple(s1, trueS == ap); }
void LunarLander::updateState(VectorXd *p_action) { double rate = 0; decodeAction(p_action, rate); update(rate); _reward = 0; if (isFinished()) { cout<<"Final velocity: "<<_velocity; if (_velocity >= safe_velocity) { _reward = 10; cout<<"...good landing!\n"; } else { _reward = (_velocity - safe_velocity) / 20; cout<<"...you crashed!\n"; } } }
void StateItem::move(const int & action) { switch (decodeAction(action)) { case NO_ACTION: return; case SHIFT: shift(); return; case REDUCE: reduce(); return; case ARC_LEFT: arcLeft(action - AL_FIRST + 1); return; case ARC_RIGHT: arcRight(action - AR_FIRST + 1); return; case POP_ROOT: popRoot(); return; } }
std::tuple<size_t, double> FiniteBudgetModelIR::sampleOR(size_t s, size_t a, size_t s1) const { size_t an, ap; std::tie(an, ap) = decodeAction(a); auto trueS = convertToNormalState(s); return std::make_tuple(sampleObservation(s1, an), trueS == ap); }
Action MetaClass::decodeAction(const DataValueDict& atts) { // Decode the string and return the default in the absence of the attribute const DataValue* c = atts.get(Tags::action); return c ? decodeAction(c->getString().c_str()) : ADD_CHANGE; }
DECLARE_EXPORT Action MetaClass::decodeAction(const AttributeList& atts) { // Decode the string and return the default in the absence of the attribute const DataElement* c = atts.get(Tags::tag_action); return *c ? decodeAction(c->getString().c_str()) : ADD_CHANGE; }