Description
State–action–reward–state–action (SARSA) is a fundamental algorithm within the reinforcement learning domain of machine learning. Developed initially as "Modified Connectionist Q-Learning" by Rummery and Niranjan, its current name, SARSA, was popularized by Rich Sutton. The name itself is derived from the quintuple of elements that form the basis of its Q-value update rule: the current state (S), the action taken (A), the reward received (R), the subsequent state (S'), and the next action chosen in that new state (A'). This specific sequence, often denoted as (S_t, A_t, R_{t+1}, S_{t+1}, A_{t+1}), is what gives the algorithm its distinctive name.
SARSA operates as an on-policy learning algorithm, meaning it learns the value of a policy while following that same policy. The core of the algorithm lies in its Q-value update equation: Q_new(S_t, A_t) ← (1 - α)Q(S_t, A_t) + α [R_{t+1} + γ Q(S_{t+1}, A_{t+1})]. Here, α represents the learning rate, controlling how much new information overrides old information, and γ is the discount factor, which determines the importance of future rewards. A learning rate of 0 means no learning occurs, while a rate of 1 prioritizes the most recent information. A discount factor of 0 makes the agent myopic, focusing only on immediate rewards, whereas a factor close to 1 encourages long-term reward maximization.
Unlike algorithms like Watkin's Q-learning, which estimates the optimal state-action value function by considering the maximum possible reward from the next state, SARSA learns the Q-values associated with the policy it is currently executing. This distinction is significant for understanding its behavior, especially in environments where exploration strategies are employed. Optimizations from Q-learning can sometimes be applied to SARSA. The algorithm's performance is also influenced by its initial conditions. "Optimistic initial conditions," where Q-values are set to a high, potentially infinite, value, can encourage exploration by making initial actions appear more rewarding. Recent research has also explored using the first reward received to reset initial conditions, allowing for immediate learning in deterministic reward scenarios, a method that shows consistency with human learning patterns.
SARSA is particularly useful for agents that need to learn optimal behavior through trial and error in environments where the consequences of actions are not fully known. Its on-policy nature makes it suitable for scenarios where the agent must learn to act according to a specific policy, such as in robotics, game playing, or resource management, where the exploration strategy directly impacts the learned policy.
State–action–reward–state–action Highlights
Learns Markov decision process policies
Utilizes state, action, reward, next state, and next action for updates
On-policy learning algorithm
Q-value update rule based on learning rate (alpha)
Discount factor (gamma) for future reward importance
Adaptable to different initial conditions
Supports optimistic initial conditions for exploration
Can incorporate first reward for initial condition reset
Foundation for reinforcement learning agents
Enables adaptive decision-making in dynamic environments
Suitable for learning through trial and error
Getting Started with State–action–reward–state–action
Initialize Q-values for state-action pairs
Select an action based on the current policy and Q-values
Execute the action, observe reward and next state
Select the next action in the new state based on the current policy
Update the Q-value for the previous state-action pair using the SARSA update rule
Repeat until convergence or termination condition is met
State–action–reward–state–action's Use Cases
- Robotics control
- Game AI development
- Autonomous navigation
- Resource management
- Personalized recommendations
- Algorithmic trading






