MCPcopy Create free account
hub / github.com/bytedance/Fastbot_Android / selectActionByQValue

Method selectActionByQValue

native/agent/ModelReusableAgent.cpp:384–419  ·  view source on GitHub ↗

Select an action with the largest quality value based on its quality value and the uniform distribution \return the selected action with the highest quality value

Source from the content-addressed store, hash-verified

382 /// its quality value and the uniform distribution
383 /// \return the selected action with the highest quality value
384 ActionPtr ModelReusableAgent::selectActionByQValue() {
385 ActionPtr returnAction = nullptr;
386 float maxQ = -MAXFLOAT;
387 const GraphPtr &graphRef = this->_model.lock()->getGraph();
388 auto visitedActivities = graphRef->getVisitedActivities();
389 for (auto action: this->_newState->getActions()) {
390 double qv = 0.0;
391 uintptr_t actionHash = action->hash();
392 // it won't happen, since if there is am unvisited action in state, it will be
393 // visited before this method is called.
394 if (action->getVisitedCount() <= 0) {
395 auto iterator = this->_reuseModel.find(actionHash);
396 if (iterator != this->_reuseModel.end()) {
397 qv += this->probabilityOfVisitingNewActivities(action, visitedActivities);
398 } else {
399 BDLOG("qvalue pick return a action: %s", action->toString().c_str());
400 return action;
401 }
402 }
403 qv += getQValue(action);
404 qv /= entropyAlpha;
405 float uniform = static_cast<float>(randomInt(0, 10)) /
406 10.0f; // with this uniform distribution, add a little disturbance to the qv value
407
408 // use the uniform distribution and humble gumbel to add some randomness to the qv value
409 if (uniform < std::numeric_limits<float>::min())
410 uniform = std::numeric_limits<float>::min();
411 qv -= log(-log(uniform));
412 // choose the action with the highest qv value
413 if (qv > maxQ) {
414 maxQ = static_cast<float >(qv);
415 returnAction = action;
416 }
417 }
418 return returnAction; // return the action with the largest qv value
419 }
420
421 void ModelReusableAgent::adjustActions() {
422 AbstractAgent::adjustActions();

Callers 1

selectNewActionMethod · 0.95

Calls 9

randomIntFunction · 0.85
getVisitedActivitiesMethod · 0.80
getActionsMethod · 0.80
getVisitedCountMethod · 0.80
hashMethod · 0.45
endMethod · 0.45
c_strMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected