|
bitsim
Model, simulate, estimate and control robots in C++
|
Every agent learns its own Q-table with Q-learning, as if the others were part of the environment. More...
#include <independent_q_learning.h>
Classes | |
| struct | Greedy |
| A team that acts greedily with these tables, for run_episode(). More... | |
Public Types | |
| typedef std::vector< uint_t > | joint_action_type |
Public Member Functions | |
| IndependentQLearning (uint_t n_agents, uint_t n_states, uint_t n_actions, const IndependentQLearningConfig &config={}) | |
| uint_t | n_agents () const noexcept |
| template<typename TimeStepType> | |
| joint_action_type | act (const TimeStepType &step) |
| An exploring action for every agent; agents that are done get action 0. | |
| template<typename TimeStepType> | |
| joint_action_type | act_greedy (const TimeStepType &step) const |
| The greedy action of every agent, for evaluation. | |
| template<typename TimeStepType> | |
| void | update (const TimeStepType &step, const joint_action_type &actions, const TimeStepType &next) |
| Learn from the transition step –actions--> next. | |
| void | on_episode_begin (uint_t) |
| void | on_episode_end (uint_t episode) |
| Decay the exploration of every agent. | |
| real_t | epsilon () const noexcept |
| The current exploration, the same for all agents. | |
| const DynMat< real_t > & | q_table (uint_t agent) const |
| const QLearningAgent & | agent (uint_t agent) const |
| The learner of one agent. | |
| void | save (const std::string &prefix) const |
| Write the Q-table of every agent to <prefix><agent>.csv, a row per state. | |
| Greedy | greedy () const |
Every agent learns its own Q-table with Q-learning, as if the others were part of the environment.
Independent Q-learning is the simplest way to learn with several agents, and the baseline of the others. Each agent explores with its own epsilon-greedy policy, bitrl::rl::policies::EpsilonGreedyPolicy, and updates \(Q_i(o_i, a_i) \leftarrow Q_i(o_i, a_i) + \eta [r_i + \gamma \max_a Q_i(o_i', a) - Q_i(o_i, a_i)]\) from its own observation, action and reward. The others change their behaviour while they learn, so the environment of each agent is not stationary and the guarantees of Q-learning are lost; how much that matters depends on what the agents observe of each other.
An agent that is done takes no actions and learns nothing more. Where the episode was cut by the step limit, the agent still bootstraps from its next observation, since it was not done.
Every agent is a QLearningAgent, which can also learn on its own, in a process of its own.
It suits environments whose observations and actions are indices, such as bitrl::envs::multi_agent::MultiAgentGridWorld, and meets the multi_agent_learner concept of MultiAgentTrainer.
| typedef std::vector<uint_t> bitrl::rl::multi_agent::IndependentQLearning::joint_action_type |
|
inline |
| IndependentQLearning::joint_action_type bitrl::rl::multi_agent::IndependentQLearning::act | ( | const TimeStepType & | step | ) |
An exploring action for every agent; agents that are done get action 0.
| IndependentQLearning::joint_action_type bitrl::rl::multi_agent::IndependentQLearning::act_greedy | ( | const TimeStepType & | step | ) | const |
The greedy action of every agent, for evaluation.
|
inline |
The learner of one agent.
|
inlinenoexcept |
The current exploration, the same for all agents.
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
Decay the exploration of every agent.
|
inline |
|
inline |
Write the Q-table of every agent to <prefix><agent>.csv, a row per state.
| void bitrl::rl::multi_agent::IndependentQLearning::update | ( | const TimeStepType & | step, |
| const joint_action_type & | actions, | ||
| const TimeStepType & | next ) |
Learn from the transition step –actions--> next.