Search Knowledge

© 2026 LIBREUNI PROJECT

Machine Learning / MLOps & System Deployment

Reinforcement Learning

Reinforcement Learning and Q-Learning

Reinforcement Learning (RL) is a paradigm where an agent learns to make sequences of decisions in an environment to maximize its cumulative long-term reward.

Markov Decision Processes (MDP)

An MDP provides a formal mathematical framework for modeling decision-making under uncertainty, defined by:

  • States (SS): The set of all possible environmental states.
  • Actions (AA): The set of actions available to the agent.
  • Transition Probability P(ss,a)P(s' | s, a): The probability of transition to state ss' given action aa in state ss.
  • Reward Function R(s,a,s)R(s, a, s'): The immediate reward received after transitioning.

The Bellman Optimality Equation

The objective is to find a policy π(s)\pi(s) that maximizes the expected discounted return Gt=k=0γkRt+k+1G_t = \sum_{k=0}^{\infty} \gamma^k R_{t+k+1}, where γ[0,1)\gamma \in [0, 1) is the discount factor.

The optimal action-value function Q(s,a)Q^*(s, a) satisfies the Bellman Optimality Equation:

Q(s,a)=sP(ss,a)[R(s,a,s)+γmaxaQ(s,a)]Q^*(s, a) = \sum_{s'} P(s' | s, a) \left[ R(s, a, s') + \gamma \max_{a'} Q^*(s', a') \right]

Q-Learning (Model-Free Control)

When transition probabilities P(ss,a)P(s'|s,a) are unknown, the agent learns QQ-values through experience using temporal difference updates:

Q(s,a)Q(s,a)+α[r+γmaxaQ(s,a)Q(s,a)]Q(s, a) \leftarrow Q(s, a) + \alpha \left[ r + \gamma \max_{a'} Q(s', a') - Q(s, a) \right]

where α\alpha is the learning rate, and rr is the immediate reward.

Deep Q-Networks (DQN)

In large state spaces, we replace the lookup table Q(s,a)Q(s, a) with a neural network Q(s,a;θ)Q(s, a; \theta) parameterized by weights θ\theta. We train the network by minimizing the loss against a target value:

y=r+γmaxaQ(s,a;θ)y = r + \gamma \max_{a'} Q(s', a'; \theta^{-})

where θ\theta^{-} represents the weights of a separate target network updated periodically to stabilize training. We use an Experience Replay Buffer to store state transitions, breaking sample correlation and stabilizing updates.

Example: Q-Learning Update Step

The following example demonstrates a single Q-learning update step:

python

Interactive Lab

Perform a Temporal Difference (TD) Q-learning update calculation for a single state transition, updating its action-value rating.

Step 1
Inspect the idea
Step 2
Edit the program
Step 3
Run and compare

Exercise

Test your understanding of the discount factor parameter:

What happens to an RL agent's behavior if the discount factor gamma is set close to zero?

Dimensional Complexity

Tabular Q-learning is limited to small discrete environments. Continuous, high-dimensional spaces require deep neural network function approximators (DQNs).

References & Further Reading

Previous Module Recommender Systems