# rlPPOAgentOptions

## Description

Use an `rlPPOAgentOptions`

object to specify options for proximal
policy optimization (PPO) agents. To create a PPO agent, use `rlPPOAgent`

.

For more information on PPO agents, see Proximal Policy Optimization (PPO) Agents.

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

## Creation

### Description

creates an
`opt`

= rlPPOAgentOptions`rlPPOAgentOptions`

object for use as an argument when creating a PPO
agent using all default settings. You can modify the object properties using dot
notation.

creates the options set `opt`

= rlPPOAgentOptions(`Name=Value`

)`opt`

and sets its properties using one
or more name-value arguments. For example,
`rlPPOAgentOptions(DiscountFactor=0.95)`

creates an option set with a
discount factor of `0.95`

. You can specify multiple name-value
arguments.

## Properties

`ExperienceHorizon`

— Number of steps the agent interacts with the environment before learning

`512`

(default) | positive integer

Number of steps the agent interacts with the environment before learning from its
experience, specified as a positive integer. When the agent is trained in parallel,
`ExperienceHorizon`

is ignored, and the whole episode is used to
compute the gradients.

The `ExperienceHorizon`

value must be greater than or equal to
the `MiniBatchSize`

value.

**Example: **`ExperienceHorizon=1024`

`MiniBatchSize`

— Mini-batch size

`128`

(default) | positive integer

Mini-batch size used for each learning epoch, specified as a positive integer. When the agent uses a recurrent neural network, `MiniBatchSize`

is treated as the training trajectory length.

The `MiniBatchSize`

value must be less than or equal to the `ExperienceHorizon`

value.

**Example: **`MiniBatchSize=256`

`ClipFactor`

— Clip factor

`0.2`

(default) | positive scalar less than `1`

Clip factor for limiting the change in each policy update step, specified as a
positive scalar less than `1`

.

**Example: **`ClipFactor=0.5`

`EntropyLossWeight`

— Entropy loss weight

`0.01`

(default) | scalar value between `0`

and `1`

Entropy loss weight, specified as a scalar value between `0`

and
`1`

. A higher entropy loss weight value promotes agent exploration by
applying a penalty for being too certain about which action to take. Doing so can help
the agent move out of local optima.

When gradients are computed during training, an additional gradient component is computed for minimizing this loss function. For more information, see Entropy Loss.

**Example: **`EntropyLossWeight=0.02`

`NumEpoch`

— Number of epochs

`3`

(default) | positive integer

Number of epochs for which the actor and critic networks learn from the current experience set, specified as a positive integer.

**Example: **`NumEpoch=2`

`AdvantageEstimateMethod`

— Method for estimating advantage values

`"gae"`

(default) | `"finite-horizon"`

Method for estimating advantage values, specified as one of the following:

`"gae"`

— Generalized advantage estimator`"finite-horizon"`

— Finite horizon estimation

For more information on these methods, see the training algorithm information in Proximal Policy Optimization (PPO) Agents.

**Example: **`AdvantageEstimateMethod="finite-horizon"`

`GAEFactor`

— Smoothing factor for generalized advantage estimator

`0.95`

(default) | scalar value between `0`

and `1`

Smoothing factor for generalized advantage estimator, specified as a scalar value between `0`

and `1`

, inclusive. This option applies only when the `AdvantageEstimateMethod`

option is `"gae"`

**Example: **`GAEFactor=0.97`

`NormalizedAdvantageMethod`

— Method for normalizing advantage function

`"none"`

(default) | `"current`

| `"moving"`

Method for normalizing advantage function values, specified as one of the following:

`"none"`

— Do not normalize advantage values`"current"`

— Normalize the advantage function using the mean and standard deviation for the current mini-batch of experiences.`"moving"`

— Normalize the advantage function using the mean and standard deviation for a moving window of recent experiences. To specify the window size, set the`AdvantageNormalizingWindow`

option.

In some environments, you can improve agent performance by normalizing the advantage function during training. The agent normalizes the advantage function by subtracting the mean advantage value and scaling by the standard deviation.

**Example: **`NormalizedAdvantageMethod="moving"`

`AdvantageNormalizingWindow`

— Window size for normalizing advantage function

`1e6`

(default) | positive integer

Window size for normalizing advantage function values, specified as a positive integer. Use this option when the `NormalizedAdvantageMethod`

option is `"moving"`

.

**Example: **`AdvantageNormalizingWindow=1e5`

`ActorOptimizerOptions`

— Actor optimizer options

`rlOptimizerOptions`

object

Actor optimizer options, specified as an `rlOptimizerOptions`

object. It allows you to specify training parameters of
the actor approximator such as learning rate, gradient threshold, as well as the
optimizer algorithm and its parameters. For more information, see `rlOptimizerOptions`

and `rlOptimizer`

.

**Example: **```
ActorOptimizerOptions =
rlOptimizerOptions(LearnRate=2e-3)
```

`CriticOptimizerOptions`

— Critic optimizer options

`rlOptimizerOptions`

object

Critic optimizer options, specified as an `rlOptimizerOptions`

object. It allows you to specify training parameters of
the critic approximator such as learning rate, gradient threshold, as well as the
optimizer algorithm and its parameters. For more information, see `rlOptimizerOptions`

and `rlOptimizer`

.

**Example: **```
CriticOptimizerOptions =
rlOptimizerOptions(LearnRate=5e-3)
```

`SampleTime`

— Sample time of agent

`1`

(default) | positive scalar | `-1`

Sample time of agent, specified as a positive scalar or as `-1`

. Setting this
parameter to `-1`

allows for event-based simulations.

Within a Simulink^{®} environment, the RL Agent block
in which the agent is specified to execute every `SampleTime`

seconds
of simulation time. If `SampleTime`

is `-1`

, the
block inherits the sample time from its parent subsystem.

Within a MATLAB^{®} environment, the agent is executed every time the environment advances. In
this case, `SampleTime`

is the time interval between consecutive
elements in the output experience returned by `sim`

or
`train`

. If
`SampleTime`

is `-1`

, the time interval between
consecutive elements in the returned output experience reflects the timing of the event
that triggers the agent execution.

**Example: **`SampleTime=-1`

`DiscountFactor`

— Discount factor

`0.99`

(default) | positive scalar less than or equal to 1

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

**Example: **`DiscountFactor=0.9`

## Object Functions

`rlPPOAgent` | Proximal policy optimization (PPO) reinforcement learning agent |

## Examples

### Create PPO Agent Options Object

Create a PPO agent options object, specifying the experience horizon.

opt = rlPPOAgentOptions(ExperienceHorizon=256)

opt = rlPPOAgentOptions with properties: SampleTime: 1 DiscountFactor: 0.9900 EntropyLossWeight: 0.0100 ExperienceHorizon: 256 MiniBatchSize: 128 NumEpoch: 3 ActorOptimizerOptions: [1x1 rl.option.rlOptimizerOptions] CriticOptimizerOptions: [1x1 rl.option.rlOptimizerOptions] ClipFactor: 0.2000 AdvantageEstimateMethod: "gae" GAEFactor: 0.9500 NormalizedAdvantageMethod: "none" AdvantageNormalizingWindow: 1000000 InfoToSave: [1x1 struct]

You can modify options using dot notation. For example, set the agent sample time to `0.5`

.

opt.SampleTime = 0.5;

## Version History

**Introduced in R2019b**

### R2022a: Simulation and deployment: `UseDeterministicExploitation`

will be removed

The property `UseDeterministicExploitation`

of the
`rlPPOAgentOptions`

object will be removed in a future release. Use the
`UseExplorationPolicy`

property of `rlPPOAgent`

instead.

Previously, you set `UseDeterministicExploitation`

as follows.

Force the agent to always select the action with maximum likelihood, thereby using a greedy deterministic policy for simulation and deployment.

agent.AgentOptions.UseDeterministicExploitation = true;

Allow the agent to select its action by sampling its probability distribution for simulation and policy deployment, thereby using a stochastic policy that explores the observation space.

agent.AgentOptions.UseDeterministicExploitation = false;

Starting in R2022a, set `UseExplorationPolicy`

as follows.

Force the agent to always select the action with maximum likelihood, thereby using a greedy deterministic policy for simulation and deployment.

agent.UseExplorationPolicy = false;

Allow the agent to select its action by sampling its probability distribution for simulation and policy deployment, thereby using a stochastic policy that explores the observation space.

agent.UseExplorationPolicy = true;

Similarly to `UseDeterministicExploitation`

,
`UseExplorationPolicy`

affects only simulation and deployment; it does
not affect training.

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)