我是张量流的新手。我用涉及的部分试验了 DQN 算法
a = tf.placeholder(tf.int32, shape = [None],name='A')
q = tf.reduce_sum(critic_q * tf.one_hot(a,n_outputs),axis=1,keepdims=True,name='Q')#Q value for chosen action
y = tf.placeholder(tf.float32, shape = [None],name='Y')
learning_rate = 1e-4
cost = tf.reduce_mean(tf.square(y-q))#mean squared error
global_step = tf.Variable(0,trainable=False,name='global_step')
optimizer = tf.train.AdamOptimizer(learning_rate)
training_op = optimizer.minimize(cost,global_step=global_step)
Run Code Online (Sandbox Code Playgroud)
并用 初始化输入 y y_batch=np.zeros(nbatch)。该网络几乎没有经过训练。
然后,我切换到将 y 定义为
y = tf.placeholder(tf.float32, shape = [None,1],name='Y')
Run Code Online (Sandbox Code Playgroud)
并使用 初始化输入y_batch=np.zeros(nbatch).reshape(-1,1),效果很好。
第一个实现中发生了什么?