parl.Agent

class Agent(algorithm)[源代码]
alias: parl.Agent
alias: parl.core.paddle.agent.Agent
Agent is one of the three basic classes of PARL.
It is responsible for interacting with the environment and collecting

data for training the policy. | To implement a customized Agent, users can:

import parl

class MyAgent(parl.Agent):
    def __init__(self, algorithm, act_dim):
        super(MyAgent, self).__init__(algorithm)
        self.act_dim = act_dim
变量
  • alg (parl.algorithm) – algorithm of this agent.

  • place – can automatically specify device when creating a tensor.

Public Functions:
  • sample: return a noisy action to perform exploration according to the policy.

  • predict: return an action given current observation.

  • learn: update the parameters of self.alg using the learn_program defined in build_program().

  • save: save parameters of the agent to a given path.

  • restore: restore previous saved parameters from a given path.

__init__(algorithm)[源代码]
参数

algorithm (parl.Algorithm) – an instance of parl.Algorithm. This algorithm is then passed to self.alg.

learn(*args, **kwargs)[源代码]

The training interface for Agent.

predict(*args, **kwargs)[源代码]

Predict an action when given the observation of the environment.

restore(save_path, model=None)[源代码]

Restore previously saved parameters. This method requires a program that describes the network structure. The save_path argument is typically a value previously passed to save_params().

参数
  • save_path (str) – path where parameters were previously saved.

  • model (parl.Model) – model that describes the neural network structure. If None, will use self.alg.model.

引发

ValueError – if program is None and self.learn_program does not exist.

Example:

agent = AtariAgent()
agent.save('./model_dir')
agent.restore('./model_dir')
sample(*args, **kwargs)[源代码]

Return an action with noise when given the observation of the environment.

In general, this function is used in train process as noise is added to the action to preform exploration.

save(save_path, model=None)[源代码]

Save parameters.

参数
  • save_path (str) – where to save the parameters.

  • model (parl.Model) – model that describes the neural network structure. If None, will use self.alg.model.

引发

ValueError – if program is None and self.learn_program does not exist.

Example:

agent = AtariAgent()
agent.save('./model_dir')