Main Content

getLearnableParameters

Obtain learnable parameter values from agent, function approximator, or policy object

Description

Agent

pars = getLearnableParameters(agent) returns the learnable parameter values from the agent object agent.

Actor or Critic

example

pars = getLearnableParameters(fcnAppx) returns the learnable parameter values from the actor or critic function approximator object fcnAppx.

Policy

pars = getLearnableParameters(policy) returns the learnable parameters values from the policy object policy.

Examples

collapse all

Assume that you have an existing trained reinforcement learning agent. For this example, load the trained agent from Train DDPG Agent to Control Double Integrator System.

load('DoubleIntegDDPG.mat','agent') 

Obtain the critic function approximator from the agent.

critic = getCritic(agent);

Obtain the learnable parameters from the critic.

params = getLearnableParameters(critic)
params=2×1 cell array
    {[-4.9889 -1.5548 -0.3434 -0.1111 -0.0500 -0.0035]}
    {[                                              0]}

Modify the parameter values. For this example, simply multiply all of the parameters by 2.

modifiedParams = cellfun(@(x) x*2,params,'UniformOutput',false);

Set the parameter values of the critic to the new modified values.

critic = setLearnableParameters(critic,modifiedParams);

Set the critic in the agent to the new modified critic.

setCritic(agent,critic);

Display the new parameter values.

getLearnableParameters(getCritic(agent))
ans=2×1 cell array
    {[-9.9778 -3.1095 -0.6867 -0.2223 -0.1000 -0.0069]}
    {[                                              0]}

Assume that you have an existing trained reinforcement learning agent. For this example, load the trained agent from Train DDPG Agent to Control Double Integrator System.

load('DoubleIntegDDPG.mat','agent') 

Obtain the actor function approximator from the agent.

actor = getActor(agent);

Obtain the learnable parameters from the actor.

params = getLearnableParameters(actor)
params=2×1 cell array
    {[-15.4622 -7.2252]}
    {[               0]}

Modify the parameter values. For this example, simply multiply all of the parameters by 2.

modifiedParams = cellfun(@(x) x*2,params,'UniformOutput',false);

Set the parameter values of the actor to the new modified values.

actor = setLearnableParameters(actor,modifiedParams);

Set the actor in the agent to the new modified actor.

setActor(agent,actor);

Display the new parameter values.

getLearnableParameters(getActor(agent))
ans=2×1 cell array
    {[-30.9244 -14.4504]}
    {[                0]}

Input Arguments

collapse all

Reinforcement learning agent, specified as one of the following objects:

Actor or critic function object, specified as one of the following:

To create an actor or critic function object, use one of the following methods.

  • Create a function object directly.

  • Obtain the existing critic from an agent using getCritic.

  • Obtain the existing actor from an agent using getActor.

Reinforcement learning policy, specified as one of the following objects:

Output Arguments

collapse all

Learnable parameter values for the function object, returned as a cell array. You can modify these parameter values and set them in the original agent or a different agent using the setLearnableParameters function.

Version History

Introduced in R2019a

expand all