bitsim
Model, simulate, estimate and control robots in C++
Loading...
Searching...
No Matches
bitrl::rl::multi_agent::IndependentQLearning Class Reference

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

Detailed Description

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.

Member Typedef Documentation

◆ joint_action_type

Constructor & Destructor Documentation

◆ IndependentQLearning()

bitrl::rl::multi_agent::IndependentQLearning::IndependentQLearning ( uint_t n_agents,
uint_t n_states,
uint_t n_actions,
const IndependentQLearningConfig & config = {} )
inline

Member Function Documentation

◆ act()

template<typename TimeStepType>
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.

◆ act_greedy()

template<typename TimeStepType>
IndependentQLearning::joint_action_type bitrl::rl::multi_agent::IndependentQLearning::act_greedy ( const TimeStepType & step) const

The greedy action of every agent, for evaluation.

◆ agent()

const QLearningAgent & bitrl::rl::multi_agent::IndependentQLearning::agent ( uint_t agent) const
inline

The learner of one agent.

◆ epsilon()

real_t bitrl::rl::multi_agent::IndependentQLearning::epsilon ( ) const
inlinenoexcept

The current exploration, the same for all agents.

◆ greedy()

Greedy bitrl::rl::multi_agent::IndependentQLearning::greedy ( ) const
inline

◆ n_agents()

uint_t bitrl::rl::multi_agent::IndependentQLearning::n_agents ( ) const
inlinenoexcept

◆ on_episode_begin()

void bitrl::rl::multi_agent::IndependentQLearning::on_episode_begin ( uint_t )
inline

◆ on_episode_end()

void bitrl::rl::multi_agent::IndependentQLearning::on_episode_end ( uint_t episode)
inline

Decay the exploration of every agent.

◆ q_table()

const DynMat< real_t > & bitrl::rl::multi_agent::IndependentQLearning::q_table ( uint_t agent) const
inline

◆ save()

void bitrl::rl::multi_agent::IndependentQLearning::save ( const std::string & prefix) const
inline

Write the Q-table of every agent to <prefix><agent>.csv, a row per state.

◆ update()

template<typename TimeStepType>
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.


The documentation for this class was generated from the following file: