栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

深度强化学习 学术前沿与实战应用(一)——Dueling DQN

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

深度强化学习 学术前沿与实战应用(一)——Dueling DQN

class DuelingDQN:
 def __init__(self, …, dueling True, sess None):
 self.dueling dueling
 if sess is None:
 self.sess tf.Session()
 self.sess.run(tf.global_variables_initializer())
 else:
 self.sess sess
 #省略

 

def _build_net(self):
 def build_layers(s, c_names, n_l1, w_initializer, b_initializer):
 with tf.variable_scope( l1 ):
 w1 tf.get_variable( w1 , [self.n_features, n_l1], initializer w_initializer, collections c_names)
 b1 tf.get_variable( b1 , [1, n_l1], initializer b_initializer, collections c_names)
 l1 tf.nn.relu(tf.matmul(s, w1) b1)
 if self.dueling:
 # Dueling DQN
 with tf.variable_scope( Value ): # 专门分析state的Value
 w2 tf.get_variable( w2 , [n_l1, 1], initializer w_initializer, collections c_names)
 b2 tf.get_variable( b2 , [1, 1], initializer b_initializer, collections c_names)
 self.V tf.matmul(l1, w2) b2
 with tf.variable_scope( Advantage ): # 专门分析每种动作的Advantage
 w2 tf.get_variable( w2 , [n_l1, self.n_actions], initializer w_initializer, collections c_names)
 b2 tf.get_variable( b2 , [1, self.n_actions], initializer b_initializer, collections c_names)
 self.A tf.matmul(l1, w2) b2
 with tf.variable_scope( Q ):
 out self.V (self.A - tf.reduce_mean(self.A, axis 1, keep_dims True))
 else:
 with tf.variable_scope( Q ): #普通的DQN第二层
 w2 tf.get_variable( w2 , [n_l1, self.n_actions], initializer w_initializer, collections c_names)
 b2 tf.get_variable( b2 , [1, self.n_actions], initializer b_initializer, collections c_names)
 out tf.matmul(l1, w2) b2
 return out

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/267587.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号