keras-ddpg

本文详细介绍了如何利用Keras库来实现Deep Deterministic Policy Gradient (DDPG)算法,这是一种用于连续动作空间强化学习的方法。通过实例代码,展示了从环境设置到模型构建、训练过程,帮助读者理解DDPG在实际问题中的应用。
摘要由CSDN通过智能技术生成
import os
import time

import numpy as np

import gym
import tensorflow as tf
from keras.models import Sequential, Model
from keras.layers import Dense, Dropout, Input
from keras.layers.merge import Add, Concatenate
from keras.optimizers import Adam
import keras.backend as K

import random
from collections import deque

def stack_samples(samples):
    array = np.array(samples)
    s_ts = np.stack(array[:,0]).reshape((array.shape[0],-1))
    actions = np.stack(array[:,1]).reshape((array.shape[0],-1))
    rewards = np.stack(array[:,2]).reshape((array.shape[0],-1))
    s_ts1 = np.stack(array[:,3]).reshape((array.shape[0],-1))
    dones = np.stack(array[:,4]).reshape((array.shape[0],-1))
    return s_ts, actions, rewards, s_ts1, dones

class Agent(object):
    def __init__(self,sess):
        self.sess = sess
        self.epsilon = 0.9
        self.gamma = 0.99
        self.epsilon_decay = 0.99995
        self.tau = 0.01
        self.memory = deque(maxlen=4000)

        self.actor_state_input, self.actor_model = self.create_actor_model()
        _, self.target_actor_model = self.create_actor_model()
        self.actor_critic_grad = tf.placeholder(tf.float32,[None,1])
        actor_model_w
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值