深度Q学习-测试问题导航

时间:2021-01-09 09:34:32

标签: python neural-network reinforcement-learning q-learning

我正在尝试使用深度 q 网络来解决一个优化问题,其中我的状态(即 21 个输入)与操作(即 20 个输出)相关。我的问题没有终端,即代理实时移动而没有任何边界来选择最佳位置(这是一个导航问题)。

训练深度Q网络后,我的网络只为不同的状态选择一个输出。谁能帮我解决这个问题?我检查了用于训练的 Q 值,所有值都以相似的方式一起变化。

Q-values in training

另外,我还有一个疑问。当我看到奖励时:

Reward

似乎奖励正在收敛,但 Q 值在初始情节有一个尖峰:

Q values with peak

我不知道为什么会这样?

我的测试代码如下:

def test(env, agent, test_runtime, ref_idx):
    saving_optdata = [0 for _ in range(test_runtime)]

    print("\n---- TEST ----\n")
    energy = 0
    for t in range(start_time, start_time + test_runtime, 1):
        env.reset(ref_idx=ref_idx)  # reset the environment
        time_window = env.time_window(1 + 1, t)
        state = hstack((ref_idx, time_window[55:60, 0]))
        action, q_values = agent.act(state, 0, False)
        opt_idx = len(env.arr_depth) - action_size + action

        next_idx, done = env.next_timestep(action, action_size)  # send action to environment
        next_state = hstack((next_idx, time_window[55:60, 1]))
        reward = net_power(ref_idx, next_idx, time_window[next_idx, 1], k1, 1)  # - \
        agent.step(action, reward, next_state, done, False)

        opt_vel = env.arr_velocity[opt_idx, t + 1]
        opt_p = net_power(ref_idx, opt_idx, opt_vel, k1, 1)
        energy += opt_p
        saving_optdata[t - start_time] = [ref_idx, opt_idx, env.arr_depth[opt_idx], opt_vel, opt_p, energy, q_values]
        print("time = {:3d}, Index= {:2d}, Power = {:9.3f},   Velocity = {},".format(t - start_time, opt_idx, opt_p,
                                                                                    opt_vel))
        ref_idx = opt_idx

0 个答案:

没有答案