如何提升机器学习 – DQ学习模型的性能

DQlearning中的月球着陆器表现不佳,因此我尝试通过优化参数来提升月球着陆器(dq学习)的性能。请问我可以调整哪些部分?有人能提供一些建议吗?是增加更多层、更改激活类型还是其他方法?

这是代码:

import numpy as npimport gymimport csvfrom keras.models import Sequentialfrom keras.layers import Dense, Activation, Flattenfrom keras.optimizers import Adamfrom rl.agents.dqn import DQNAgentfrom rl.policy import BoltzmannQPolicy, EpsGreedyQPolicyfrom rl.memory import SequentialMemoryimport ioimport sysimport csv# Path environment changed to make things work properly# export DYLD_FALLBACK_LIBRARY_PATH=$DYLD_FALLBACK_LIBRARY_PATH:/usr/lib# Get the environment and extract the number of actions.ENV_NAME = 'LunarLander-v2'env = gym.make(ENV_NAME)np.random.seed(123)env.seed(123)nb_actions = env.action_space.n# Next, we build a very simple model.model = Sequential()model.add(Flatten(input_shape=(1,) + env.observation_space.shape))model.add(Dense(16))model.add(Activation('relu'))model.add(Dense(16))model.add(Activation('relu'))model.add(Dense(16))model.add(Activation('tanh'))model.add(Dense(nb_actions))model.add(Activation('linear'))print(model.summary())# Finally, we configure and compile our agent. You can use every built-in Keras optimizer and# even the metrics!memory = SequentialMemory(limit=300000, window_length=1)policy = EpsGreedyQPolicy()dqn = DQNAgent(model=model, nb_actions=nb_actions, memory=memory, nb_steps_warmup=10,               target_model_update=1e-2, policy=policy)dqn.compile(Adam(lr=1e-3), metrics=['mae'])dqn.fit(env, nb_steps=30000, visualize=True, verbose=2)# After training is done, we save the final weights.dqn.save_weights('dqn_{}_weights.h5f'.format(ENV_NAME))# Redirect stdout to capture test resultsold_stdout = sys.stdout sys.stdout = mystdout = io.StringIO()# Evaluate our algorithm for a few episodes.dqn.test(env, nb_episodes=200, visualize=False)# Reset stdoutsys.stdout = old_stdoutresults_text = mystdout.getvalue()# Print results textprint("results")print(results_text)# Extact a rewards list from the resultstotal_rewards = list()for idx, line in enumerate(results_text.split('\n')):    if idx > 0 and len(line) > 1:        reward = float(line.split(':')[2].split(',')[0].strip())        total_rewards.append(reward)# Print rewards and averageprint("total rewards", total_rewards)print("average total reward", np.mean(total_rewards))# Write total rewards to filef = open("lunarlander_rl_rewards.csv",'w')wr = csv.writer(f)for r in total_rewards:     wr.writerow([r,])f.close()

谢谢~


回答:

首先,尝试调整奖励。我记得月球着陆器的奖励输出相当奇怪,最高可达100。强化学习的奖励最好在-1到1的范围内。尝试将其缩小或进行更改。

其他值得首先优化的参数是学习率和探索率。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注