Part III — Adaptive behaviour · Chapter 12

Robot learning

~60 min read1 interactive widget1 plate

In this chapter

  1. Machine learning in one slide
  2. The three learning paradigms
  3. What a learning robot needs
  4. Associative learning: conditioning and Hebb's rule
  5. Reinforcement learning: the MDP formulation
  6. Q-learning
  7. Exploration vs exploitation
  8. Extensions and related families
  9. Actor-critic methods
  10. Inverse reinforcement learning
  11. IRL meets automatic design: Demo-Cho
  12. Lab activity: Q-learning path following in ARGoS
  13. Check your understanding

1. Machine learning in one slide

There exist problems for which it is extremely difficult to write programs that solve them satisfactorily: programs might be horrendously complicated, might lack generality, might not work for noisy data, and probably need to be frequently updated. The solution: use programs/systems that learn from experience. Instead of writing a program by hand for each specific task, we collect lots of examples that specify the correct behaviour; a machine learning algorithm takes these examples and produces a program that does the job. The resulting program might look very different from a handwritten one; if we do it right, it works also for new cases (generalisation); and if data change, the program can change too by training on new data.

Definition (Tom M. Mitchell, Machine Learning, 1997)

A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.

Example — handwriting recognition: task T = recognising and classifying handwritten words within images; performance P = percent of words correctly classified; experience E = a database of handwritten words with given classification.

Example — robot driving: task T = driving on public highways using vision sensors; performance P = average distance travelled before an error (as judged by a human overseer); experience E = a sequence of images and steering commands recorded while observing a human driver.

2. The three learning paradigms

ParadigmFeedbackTypical class
Supervised learningA set of (hopefully correct) input–output examples is used to provide feedback to the learning process; derive a model for the unknown relationshipClassification (pattern recognition) and regression
Unsupervised learningNo target outputs; learn how data are organised, discover patterns, build a representation. The model is often implicit; feedback is provided by an intrinsic objective functionClustering
Reinforcement learningA critic provides a reward or a penalty indicating the desirability of the resulting behaviour; the agent learns from this reward to choose sequences of actions that produce the greatest cumulative rewardSequential decision making

Reinforcement learning addresses the question of how an autonomous agent that senses and acts in its environment can learn to choose optimal actions to achieve its goal — which makes it the paradigm of choice for robots, where behaviour unfolds in time and the consequences of an action arrive after the action.

3. What a learning robot needs

The requirements for learning robots (sometimes not met, or only partially met):

The most common type of learning in natural and artificial systems is associative learning: the robot learns about the relationship (a) between two stimuli, or (b) between a stimulus and a response. Case (a) is classical conditioning (Pavlov's experiments); case (b) is reinforcement learning, also called operant conditioning.

4. Associative learning: conditioning and Hebb's rule

Classical conditioning is unsupervised, with typical learning rules the Hebb rule and the Kohonen rule. The Hebb rule: Hebbian learning strengthens the connection between two neurons if they are active at the same time. In artificial neural systems:

Δwi = η · oj · oi

where η is the learning rate and oi, oj the outputs of neurons i and j.

Example: Distributed adaptive control

The goal is to associate the stimuli from proximity sensors with avoidance behaviour through collision reflexes. Collision sensors activate the wheels such that the robot goes away (hardcoded neural connections). Each time a collision takes place, Hebbian learning is applied to strengthen the connections that were active at the same time — hence connections between proximity sensor neurons and collision ones are strengthened. After some collisions, the inputs from proximity sensor neurons are high enough to activate collision neurons even without a collision: (a) the robot learns the association between "moving away" and "close obstacles"; (b) if a target sensor is added, the goal-oriented behaviour with obstacle avoidance can be achieved.

Editor note

This architecture is the course's bridge between Chapter 7 (perceptual schemas, weights) and this chapter: the weights of a reactive controller are not tuned by a designer but learned from the robot's own experience, with a learning rule that is local (each connection only needs the two neurons it connects). Local rules will matter again when learning must happen inside a swarm.

5. Reinforcement learning: the MDP formulation

Definition (Sutton & Barto, Reinforcement Learning, 2nd ed., 2018)

"RL is learning what to do — how to map situations to actions — so as to maximize a numerical reward signal. The learner is not told which actions to take, but instead must discover which actions yield the most reward by trying them. In the most interesting and challenging cases, actions may affect not only the immediate reward but also the next situation and, through that, all subsequent rewards. Trial-and-error search and delayed reward are the two most important distinguishing features of RL."

RL learns a mapping from perceived states to desired actions — a policy — that maximises system performance at the particular task assigned. The fundamental assumption: robot-environment interactions can be modelled as a Markov Decision Process (MDP) — both the robot and the environment can be modelled as probabilistic FSMs acting at discrete time steps (the bridge to Chapter 6). The qualifier "Markov" means the transition probabilities and reward functions depend on the past only through the current state and the action selected in it.

The RL learning scheme: the robot can perceive a finite set S of distinct states and has a finite set A of actions. At each discrete time step t the robot senses the current state st, chooses an action at and performs it; the environment responds by giving the reward rt = r(st, at) and producing the succeeding state st+1 = δ(st, at). The functions r and δ are not known to the robot. In practice the robot might not receive a reward every step, and the reward is likely to come with a delay with respect to the actions taken — the problem of temporal credit assignment: determining which of the actions in the sequence are to be credited with producing the eventual rewards.

The infinite horizon discounted model

The policy is a function from states to actions, π : S → A. We define Vπ(st) as the cumulative value achieved by following π from initial state st. The typical model is the infinite horizon discounted model:

Vπ(st) = Σ_{i=0..∞} γ^i · r_{t+i}

where γ ∈ [0,1] is the discount factor (00 ≡ 1). Rewards far in the future are normally less trusted than the current one and those in the near future; moreover, the final outcome of a strategy often strongly depends on the first choices. The learning task: find the optimal policy π* that maximises Vπ(s) for all states s.

How to find it: the robot should prefer state s1 over s2 whenever V*(s1) > V*(s2) — but the policy must choose among actions, not among states. The optimal action in state s is the action a that maximises the sum of the immediate reward r(s,a) plus the value V* of the immediate successor state, discounted by γ:

π*(s) = argmax_a [ r(s, a) + γV*(δ(s, a)) ]

If the robot knew r and δ (the typical case of a fully specified MDP), it could compute the optimal action for any state. Unfortunately the robot does not know r and δ. Is there an alternative evaluation function the robot can learn by exploiting its experience? Yes: Q-learning.

6. Q-learning

The robot learns an action–value function Q(s, a), which it uses to evaluate the utility of performing action a in state s: Q(s,a) is defined as the return the robot expects to receive given that it starts in state s and follows the optimal policy π* thereafter:

Q(s, a) ≡ r(s, a) + γV*(δ(s, a))

As V*(δ(s,a)) is the highest utility one can get from the successor state, the definition can be rewritten recursively:

Q(s, a) ≡ r(s, a) + γ · max_{a'} Q(δ(s, a), a')

Hence the best action in state s is the one that maximises Q: π*(s) = argmax_a Q(s, a). It may seem surprising that one can choose globally optimal action sequences by reacting repeatedly to the local values of Q for the current state — no lookahead search is ever needed, because the value of Q for the current state and action summarises in a single value all the information needed to determine the discounted cumulative reward that will be gained in the future if action a is selected in state s.

The Q-learning algorithm iteratively manipulates an estimate Q̂:

For each (s, a) initialize the table entry Q̂(s, a) to zero
Observe the current state s
Repeat until termination condition not reached:
   Select an action a and execute it
   Receive immediate reward r
   Observe the new state s′
   Update the table entry for Q̂(s, a):
      Q̂(s, a) ← (1 − α)Q̂(s, a) + α[ r + γ max_{a′} Q̂(s′, a′) ]
   s ← s′

α is the learning rate: how much the old Q-values are taken into account in the update. If α is very high, the robot's prior knowledge is almost entirely ignored; if α is small, a lot of weight is given to past experience. The intuition: each time the robot moves forward from an old state to a new one, Q-learning propagates Q estimates backward from the new state to the old, augmented by the immediate reward; given enough training episodes, information propagates from the transitions with nonzero reward back through the entire state-action space. The recursion is guaranteed to converge under easily satisfiable hypotheses.

Widget — Q-learning in a gridworld

The robot starts at the left, the goal (reward +1) is at the right, the grey cell is a wall. Run episodes: Q-values propagate backward from the goal; arrows show the greedy policy. Watch what changes if you raise the discount γ or silence exploration.

episodes 0
α (learning rate) = 0.5
γ (discount) = 0.9

7. Exploration vs exploitation

Q-learning's action selection is the typical case of the exploration/exploitation tradeoff. At one extreme, actions are chosen randomly (pure exploration); at the other, we choose the action with the highest Q̂ (pure exploitation). Better to choose probabilistically. A possible way:

P(ai | s) = Q̂(s, ai)^k / Σ_j Q̂(s, aj)^k

The exponent k determines how strongly selection favours actions with high Q̂: larger values assign higher probabilities to above-average actions (exploit what has been learned); small values allow higher probabilities for other actions (explore). In some cases k is varied with the number of iterations — favour exploration early, gradually shift toward exploitation. An alternative: ε-greedy — pick a random action with probability ε, choose the action that maximises Q̂ with probability 1 − ε, tuning ε along the process from high to low values.

For the exam — why exploration is not optional

If the robot always exploits, it can lock onto a suboptimal action forever: the Q-values for never-tried actions stay at their initial values, and the "best" action is an artefact of the initial table. Exploration is what makes the recursion's convergence claim meaningful in practice — and it is the same tension Chapter 10 met in novelty search: what you select for determines what you find.

8. Extensions and related families

9. Actor-critic methods

Actor-critic methods have a separate memory structure to explicitly represent the policy independent of the value function. The policy structure is known as the actor, because it is used to select actions; the estimated value function is known as the critic, because it criticises the actions made by the actor. Typically the critic is a state-value function: after each action selection, the critic evaluates the new state to determine whether things have gone better or worse than expected; the critique takes the form of a temporal difference (TD) error — a scalar signal that is the sole output of the critic and drives all learning in both actor and critic.

Editor note

The lecture deck also lists a master's thesis on online robot adaptation by actor-critic reinforcement learning (P.S. Vargas Graterón, UniBo) — the actor-critic family is the one that scales to continuous state/action spaces and to adaptation during operation. Both properties are exactly what the online-adaptation material of Chapter 16 needs; keep the TD-error idea in mind for the Boolean-network and nanowire-network robots there.

10. Inverse reinforcement learning

Inverse reinforcement learning (IRL) is the problem of inferring the reward function of an agent, given its policy or observed behaviour (Arora & Doshi, 2021). The learned reward function can then be used to generate a policy that reproduces the demonstrated behaviour. IRL is motivated by the fact that, for some classes of problems, demonstrating an optimal behaviour is easier than defining a reward function — and the same difficulty was already flagged for objective functions in Chapter 11. As Russell pointed out, the reward function is also inherently more transferable than the policy: even slight changes in the environment (e.g. noise levels in the transition function) likely render a learned policy unusable, while the reward function survives and simply needs to be extended to any new states.

In IRL, the reward function R of the agent's MDP is not provided; demonstrations of the desired behaviour are given in the form of sequences of states, and it is assumed that a "true" reward function R* exists such that the policy π* that maximises the value function based on R* would generate the given demonstrations. Ng and Russell (1998) gave the foundational formulation and algorithms. Apprenticeship learning (Abbeel & Ng, 2004) is the most influential practical variant: it assumes a feature map φ : S → [0,1]k from states to a k-dimensional vector of features, and works with feature expectations µ(π) — the expected discounted cumulative feature vector under a policy. The algorithm:

Apprenticeship learning (Abbeel & Ng 2004)
Given: φ, µE (the feature expectation of the expert)
Select a random initial policy π0
Compute µ0 := µ(π0)
repeat
   Compute w_{i+1} by fitting a SVM on µE and all µi
   Learn policy π_{i+1} on rewards R_{i+1}(s) = w_{i+1} · φ(s)
   Compute µ_{i+1} := µ(π_{i+1})
until stopping criterion met
return w_{i+1} as w*

At every iteration, a support vector machine is fitted on the expert's feature expectation and all encountered ones; its coefficients define the weight vector w that specifies the reward function; a new policy is learned on that reward; the process stops when the current policy's behaviour is sufficiently close to the demonstrations. The well-known application that brought attention to IRL: helicopter flight control — an expert helicopter operator's preferences over 24 features were learned from recorded behaviour, and the reward was used to teach a physical remote-controlled helicopter advanced manoeuvres with RL. Other applications: socially adaptive navigation (learning from human walking trajectories), route prediction for taxis, driving styles.

FORWARD RL vs INVERSE RL REWARD R POLICY π maximise hard to write by hand: multi-attribute, delicate, easy to get wrong DEMONSTRATIONS REWARD R infer easier to provide: watch an expert, record the behaviour
Plate 12.1 — IRL inverts the RL pipeline. The learned reward is more transferable than the learned policy: change the environment's noise and the policy breaks, while the reward only needs to be extended to new states.

11. IRL meets automatic design: Demo-Cho

The Robot learning deck closes with the link to Chapter 11, and the IRIDIA group made it concrete: the problem of defining an objective function is similar to the one of defining a reward function in reinforcement learning — so RL can be adopted in the framework of the automatic design of control software for robot swarms: instead of defining a mission-specific objective function, provide demonstrations of the desired swarm behaviour and let an IRL algorithm infer an objective function to automatically generate the control software that produces the desired behaviour itself.

Demo-Cho (Gharbi, Kuckling, Garzón Ramos & Birattari, ICRA 2023) combines inverse reinforcement learning with automatic modular design: apprenticeship learning is used to infer a reward function from demonstrations, and Chocolate (Chapter 11) then designs the control software that optimises it. The focus is on missions in which what the robots should accomplish is to position themselves in the environment according to a desired distribution — in this class, a demonstration is simply the desired final configuration of the robots, which an untrained end user can specify without mathematical modelling. Only on the basis of demonstrations, and without an explicit objective function, Demo-Cho successfully generated control software for four missions, in simulation and with physical robots. It is the endpoint of a chain the course built in order: reward definition is hard (Chapter 12) exactly like objective-function definition is hard (Chapter 11) — and the solution is to let demonstration stand in for specification.

For the exam — the two-step pipeline

First step (IRL): demonstrations → reward/objective function, via apprenticeship learning (feature expectations, SVM weights). Second step (automatic design): objective function → control software, via an optimizer such as Chocolate over a parametric architecture. The IRL step removes the need for the user to write the objective; the design step removes the need to write the controller. What remains is: the feature map, the architecture vocabulary, and the simulations — the "formulation debt" that Chapter 15's experimental methodology is designed to audit.

12. Lab activity: Q-learning path following in ARGoS

One of the most common tasks for robots in real-world contexts is to follow a path: for instance, moving objects to target areas while constraining the path by following a trace painted on the ground (the path is assumed always free, so no collision issues). The robot is equipped with ground sensors and uses these values to define its trajectory. One could write a control program by hand — but this is also an interesting context to try RL.

The handout provides a Q-learning implementation for path following in ARGoS (code by Matteo Magnini, with minor changes), structured as: Qlearning.lua (the main module with the Q-learning implementation), circuit-learning.lua + circuit-learning.argos (Q-learning for path following), train-script.sh (runs the learning process for a given number of epochs), and circuit-testing.lua + circuit-testing.argos (to test the robot after training). The Q-table is stored as a csv file and updated at the end of each learning epoch; the first table is created by running create Q-table.lua with parameters Qtable-circuit.csv 256 5256 states, 5 actions.

-- the heart of Q-learning (schematic, from Qlearning.lua)
Q[s][a] = (1 - alpha) * Q[s][a] +
          alpha * (reward + gamma * maxQ(next_state))

Suggested experiments with the code:

  1. Before exploring the code, think of a possible implementation: how would you define states and actions? And the reward function?
  2. Go back to step 1 until you are sure you know what to do if you had to program RL yourself.
  3. Explore the code, starting from Qlearning.lua.
  4. Assign values to the parameters of the algorithm (in circuit-learning.lua).
  5. Run the learning code with batches of 10 or 20 epochs up to 50 (at least); at the end of each epoch test the behaviour. Apply a sound experimental evaluation: run the robot from different initial conditions and collect statistics using test-script.sh — the protocol of Chapter 15 applied to a learned controller.
  6. Repeat the whole learning phase with different parameter values; try different combinations of train/test images.
Food for thought (from the handout)

Are there alternative ways for defining the reward function? What is the impact of parameter values — is there a parameter more critical than others? How could you assess the overall performance of the technique? Is there a way to estimate the convergence of the algorithm? Notice the last question: convergence of Q-learning is guaranteed asymptotically, but in a lab you must decide when to stop training — an empirical question, answerable only with the statistics of Chapter 15.

Check your understanding

Give Mitchell's definition of learning and instantiate it for robot driving.

A computer program learns from experience E with respect to a class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E. Robot driving: T = driving on public highways using vision sensors; P = average distance travelled before an error (as judged by a human overseer); E = a sequence of images and steering commands recorded while observing a human driver.

List the three learning paradigms and their typical problem classes.

Supervised learning (feedback from correct input–output examples; classification and regression); unsupervised learning (no target outputs; discover patterns and build representations; clustering); reinforcement learning (a critic provides reward or penalty; learn to choose actions that maximise cumulative reward; sequential decision making).

What are the requirements for learning robots?

Noise immunity; fast convergence; on-line learning; incremental learning; tractability; situatedness (learning based on the robot's view of the world).

Explain classical conditioning, the Hebb rule, and the distributed adaptive control example.

Classical conditioning learns the relationship between two stimuli (Pavlov); it is unsupervised, with typical rules the Hebb rule (strengthens the connection between two neurons active at the same time, Δw_i = η·o_j·o_i) and the Kohonen rule. In distributed adaptive control, collision sensors activate avoidance through hardcoded connections; every collision applies Hebbian learning to strengthen proximity→collision connections, so after some collisions proximity readings alone activate avoidance; adding a target sensor yields goal-oriented behaviour with obstacle avoidance.

Define the RL problem: MDP assumption, policy, discounted model, optimal policy.

RL learns a mapping from perceived states to desired actions (a policy) maximising cumulative reward. The fundamental assumption is that robot-environment interactions are an MDP: both can be modelled as probabilistic FSMs at discrete time steps, with transition probabilities and rewards depending on the past only through the current state and action. Vπ(s_t) = Σ γ^i r_{t+i} (infinite horizon discounted model, γ ∈ [0,1]); the optimal policy π* maximises Vπ(s) for all states, and π*(s) = argmax_a [r(s,a) + γV*(δ(s,a))] — computable only if r and δ are known, which they are not.

Write the Q-learning recursion and the update rule, explaining each symbol.

Q(s,a) ≡ r(s,a) + γ max_{a'} Q(δ(s,a), a'). The update: Q̂(s,a) ← (1−α)Q̂(s,a) + α[ r + γ max_{a'} Q̂(s′,a′) ], where α is the learning rate (how much old Q-values count), γ the discount factor, r the immediate reward, s′ the successor state. The best action is π*(s) = argmax_a Q(s,a); Q summarises in a single value the discounted cumulative reward of taking a in s. Convergence is guaranteed under easily satisfiable hypotheses; information propagates backward from nonzero-reward transitions.

Explain the exploration/exploitation tradeoff and two probabilistic action-selection schemes.

Pure random choice wastes experience; pure maximisation of Q̂ locks onto the current estimate. Probabilistic schemes balance the two: softmax/Boltzmann P(a_i|s) = Q̂(s,a_i)^k / Σ_j Q̂(s,a_j)^k (k controls how strongly high-Q actions are favoured, often decreased over time), and ε-greedy (random action with probability ε, greedy with 1−ε, ε tuned from high to low).

What are the known limitations of Q-learning and the main extensions?

Requires discrete states; slow convergence; Q-values tend to the true reward distribution. Extensions: continuous domains; improving a given (e.g. imitation-learned) policy; combination with ANNs (deep RL); feature-based approximations V(s) = w_1 f_1(s) + ... + w_n f_n(s) to generalise across states.

Describe actor-critic methods.

Separate memory structures: the actor represents the policy and selects actions; the critic estimates a value function (typically state-value) and evaluates the new state after each action, determining whether things went better or worse than expected. The critique is a temporal difference (TD) error — a scalar signal that is the sole output of the critic and drives all learning in both actor and critic.

Define inverse reinforcement learning and explain why the reward is more transferable than the policy.

IRL infers the reward function of an agent given its policy or observed behaviour; the learned reward can then generate a policy reproducing the demonstrations. It is motivated by the fact that demonstrating an optimal behaviour is often easier than defining a reward function. The reward is more transferable than the policy: slight changes in the environment (e.g. transition noise) likely render a learned policy unusable, while the reward survives and only needs extending to new states.

Outline the apprenticeship learning algorithm and its helicopter application.

Given a feature map φ and the expert's feature expectation µE: start with a random policy π0, compute its feature expectation, then repeat — fit an SVM on µE and all µi to obtain weights w_{i+1}; learn policy π_{i+1} on reward R(s) = w·φ(s); compute its feature expectation; stop when the behaviour is sufficiently close to the demonstrations. Application: an expert pilot's preferences over 24 features were learned from recorded flight data, and the reward was used to teach a physical helicopter advanced manoeuvres via RL.

Explain how IRL plugs into automatic design, and what Demo-Cho is.

Defining an objective function (automatic design) is like defining a reward function (RL), so demonstrations can replace mission-specific objective functions: an IRL algorithm infers the objective from demonstrations of the desired swarm behaviour, and an automatic design method then generates the control software. Demo-Cho combines apprenticeship learning with Chocolate: it infers a reward from demonstrations (for missions describable by the final positions of the robots) and designs control software that optimises it — without any explicit objective function, in simulation and with physical robots, on four missions.

Describe the Q-learning path-following lab: setup, table, and the questions to investigate.

The robot follows a trace painted on the ground using ground sensors. The handout's ARGoS implementation: Qlearning.lua (core algorithm), circuit-learning (training), circuit-testing (testing after training); the Q-table is a csv (created with 256 states, 5 actions) updated at the end of each epoch. Experiments: define states/actions/reward yourself first, then explore the code; run batches of 10–20 epochs up to 50, testing at each epoch; apply a sound experimental evaluation with different initial conditions (test-script.sh); vary parameters and train/test images. Food for thought: alternative reward definitions, critical parameters, performance assessment, and how to estimate convergence.