Main Content

updatePolicyParameters

Update policy according to structure of policy parameters given as input argument

Since R2025a

    Description

    updatedPolicy = updatePolicyParameters(policy,params) updates policy according to the learnable and tunable parameters contained in the structure params, and returns as output the updated policy updatedPolicy.

    example

    Examples

    collapse all

    Assume that you have an existing trained reinforcement learning agent. For this example, load the trained agent from Compare DDPG Agent to LQR Controller.

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

    Obtain the exploration policy from the agent.

    policy = getExplorationPolicy(agent);

    Obtain the parameters structure from the policy.

    params = policyParameters(policy)
    params = struct with fields:
               Model_fc_Weights: [-15.4663 -7.2746]
                  Model_fc_Bias: 0
        Policy_EnableNoiseDecay: 0
          Policy_UseNoisyAction: 1
                             ID: 0
    
    

    Modify the parameter values. For this example, turn off the additive action noise to make the policy greedy.

    params.Policy_UseNoisyAction = false;

    Update the policy with the modified structure.

    policy = updatePolicyParameters(policy,params);

    Display the updated value of the policy parameter.

    policy.UseNoisyAction
    ans = logical
       0
    
    

    Input Arguments

    collapse all

    For more information on reinforcement learning policies, see Create Actors, Critics, and Policy Objects.

    Example: policy = getExplorationPolicy(rlPPOAgent(rlNumericSpec([2 1]),rlNumericSpec([1 1]))) extracts the object that implements the exploration policy from a default PPO agent and assigns it to the variable policy.

    Parameters of the policy, specified as a structure consistent with the bus object generated by a policy block. The data type and dimension of each field in params must be consistent with its corresponding policy parameter.

    To obtain a structure of parameters from a policy object use the policyParameters function.

    Example: prms = policyParameters(getExplorationPolicy(rlPPOAgent(rlNumericSpec([2 1]),rlNumericSpec([1 1])))) extracts policy parameters from the exploratory policy of an untrained default PPO agent and assigns them to the variable prms.

    Output Arguments

    collapse all

    Updated policy, returned as a reinforcement learning policy object of the same type as policy. Apart from the learnable and tunable parameter values, updatedPolicy is the same as policy.

    Version History

    Introduced in R2025a