深度强化学习高级包PTAN-1. Agent, Experience

PTAN是一个开源的强化学习库,提供DQNAgent、PolicyAgent等预封装的Agent类,方便复用和减少开发工作。Agent类根据Observation产生action,如DNQAgent适用于离散型动作,PolicyAgent则处理连续分布的action。Experience类封装了agent与环境的交互信息,ExperienceSource和ExperienceSourceFirstLast分别用于不同方式的交互记录。ExperienceSourceFirstLast特别地,它累积多步reward并展示头尾状态。
摘要由CSDN通过智能技术生成


PTAN简介

ptan是一个开源的RL封装包(Github地址),用于封装常用的RL代码,以便提高复用性,减少开发量。安装方法如下:

  • 从pypi安装: pip install ptan
  • 从github安装:pip install pip install git+https://github.com/Shmuma/ptan.git

ptan中常用的封装类包括:

  • Agent:根据输入的Observation得到action
  • Experience:得到agent和环境交互的信息

Agent

Agent包装类内部的工作流程如下:

Observation
Net
Output
Selector
Action

ptan中已经封装好了一些常用的Agent类:DQNAgent,PolicyAgent。如果想自己自定义,可以继承基类BaseAgent

DNQAgent

主要用于dqn族的算法,Net输出的是离散型的actions。使用方法如下:

import torch.nn as nn
import torch.nn.functional as F
import torch
import ptan

#### 构建一个简单模型
class DQNModel(nn.Module):
    def __init__(self, n_actions):
        super().__init__()
        self.n_actions = n_actions
        
    def forward(self, x):
        return torch.eye(x.size()[0], self.n_actions)
    
net = DQNModel(n_actions=5)
x = torch.zeros(3, 9)
print("input is:\n", x)
print("output is:\n", net(x))

-- 输出 --
input is:
 tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0.],
        [0., 0., 0., 0., 0., 0., 0., 0., 0.]])
output is:
 tensor([[1., 0., 0., 0., 0.],
        [0., 1., 0.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值