parl.Algorithm

class Algorithm(model=None, hyperparas=None)[source]
alias: parl.Algorithm
alias: parl.core.fluid.algorithm.Algorithm
Algorithm defines the way how to update the parameters of the Model. This is where we define loss functions and the optimizer of the neural network. An Algorithm has at least a model.
PARL has implemented various algorithms(DQN/DDPG/PPO/A3C/IMPALA) that can be reused quickly, which can be accessed with parl.algorithms.

Example:

import parl

model = Model()
dqn = parl.algorithms.DQN(model, lr=1e-3)
Variables:model (parl.Model) – a neural network that represents a policy or a Q-value function.
Pulic Functions:
  • get_weights: return a Python dictionary containing parameters of the current model.
  • set_weights: copy parameters from get_weights() to the model.
  • sample: return a noisy action to perform exploration according to the policy.
  • predict: return an action given current observation.
  • learn: define the loss function and create an optimizer to minized the loss.

Note

Algorithm defines all its computation inside a fluid.Program, such that the returns of functions(sample, predict, learn) are tensors. Agent also has functions like sample, predict, and learn, but they return numpy array for the agent.

__init__(model=None, hyperparas=None)[source]
Parameters:
  • model (parl.Model) – a neural network that represents a policy or a Q-value function.
  • hyperparas (dict) – a dict storing the hyper-parameters relative to training.
get_params()[source]

Get parameters of self.model.

Deprecated since version 1.2: This will be removed in 1.3, please use get_weights instead.

Returns:a Python List containing the parameters of self.model.
Return type:params(dict)
learn(*args, **kwargs)[source]

Define the loss function and create an optimizer to minize the loss.

predict(*args, **kwargs)[source]

Refine the predicting process, e.g,. use the policy model to predict actions.

sample(*args, **kwargs)[source]

Define the sampling process. This function returns an action with noise to perform exploration.

set_params(params)[source]

Set parameters from get_params to the model.

Deprecated since version 1.2: This will be removed in 1.3, please use set_weights instead.

Parameters:params (dict) – a Python List containing the parameters of self.model.