Main Content


Options for SARSA agent


Use an rlSARSAAgentOptions object to specify options for creating SARSA agents. To create a SARSA agent, use rlSARSAAgent

For more information on SARSA agents, see SARSA Agents.

For more information on the different types of reinforcement learning agents, see Reinforcement Learning Agents.



opt = rlSARSAAgentOptions creates an rlSARSAAgentOptions object for use as an argument when creating a SARSA agent using all default settings. You can modify the object properties using dot notation.


opt = rlSARSAAgentOptions(Name,Value) sets option properties using name-value pairs. For example, rlSARSAAgentOptions('DiscountFactor',0.95) creates an option set with a discount factor of 0.95. You can specify multiple name-value pairs. Enclose each property name in quotes.


expand all

Options for epsilon-greedy exploration, specified as an EpsilonGreedyExploration object with the following properties.

PropertyDescriptionDefault Value
EpsilonProbability threshold to either randomly select an action or select the action that maximizes the state-action value function. A larger value of Epsilon means that the agent randomly explores the action space at a higher rate.1
EpsilonMinMinimum value of Epsilon0.01
EpsilonDecayDecay rate0.0050

At the end of each training time step, if Epsilon is greater than EpsilonMin, then it is updated using the following formula.

Epsilon = Epsilon*(1-EpsilonDecay)

If your agent converges on local optima too quickly, you can promote agent exploration by increasing Epsilon.

To specify exploration options, use dot notation after creating the rlSARSAAgentOptions object opt. For example, set the epsilon value to 0.9.

opt.EpsilonGreedyExploration.Epsilon = 0.9;

Sample time of agent, specified as a positive scalar.

Within a Simulink® environment, the agent gets executed every SampleTime seconds of simulation time.

Within a MATLAB® environment, the agent gets executed every time the environment advances. However, SampleTime is the time interval between consecutive elements in the output experience returned by sim or train.

Discount factor applied to future rewards during training, specified as a positive scalar less than or equal to 1.

Object Functions

rlSARSAAgentSARSA reinforcement learning agent


collapse all

This example shows how to create a SARSA agent option object.

Create an rlSARSAAgentOptions object that specifies the agent sample time.

opt = rlSARSAAgentOptions('SampleTime',0.5)
opt = 
  rlSARSAAgentOptions with properties:

    EpsilonGreedyExploration: [1x1 rl.option.EpsilonGreedyExploration]
                  SampleTime: 0.5000
              DiscountFactor: 0.9900

You can modify options using dot notation. For example, set the agent discount factor to 0.95.

opt.DiscountFactor = 0.95;

See Also

Introduced in R2019a