[英]How to tune hyperparameters of tf-agents and policies in Tensor Flow?
I have set up a python environment that is wrapped in a tensor flow class to make it a tensor flow environment.我已经建立了一个包含在张量流类中的 python 环境,使其成为一个张量流环境。 Then I set up the learning as per the collab notebooks listedhere .然后我按照此处列出的协作笔记本设置学习。 Currently, I am using the dqn and REINFORCE agent.目前,我正在使用 dqn 和 REINFORCE 代理。
The setup works well and the results are somewhat as expected.设置运行良好,结果有点符合预期。 Now I want to go into the tuning of the hyperparameters like decaying epsilon greedy, weights etc.现在我想调整超参数,例如衰减的 epsilon greedy、权重等。
I need some pointers on how to use the documentation on how to access these hyperparameters.我需要一些有关如何使用有关如何访问这些超参数的文档的指示。
Reinforce doesn't not support epsilon greedy policy, I suggest switching to DQN agent or DDQN. Reinforce 不支持 epsilon 贪婪策略,我建议切换到 DQN 代理或 DDQN。
To pass a specified Q-Network you can use something like:要传递指定的 Q-Network,您可以使用以下内容:
q_network=q_network.QNetwork(
environment.time_step_spec().observation['observations'],
environment.action_spec(),
fc_layer_params=fc_layer_params)
and pass that to your agent on initialization.并在初始化时将其传递给您的代理。 For a decaying epsilon-greedy policy you can define your own function decaying_epsilon(train_step, *kwargs)
as you prefer.对于衰减的 epsilon-greedy 策略,您可以根据自己的decaying_epsilon(train_step, *kwargs)
定义自己的函数decaying_epsilon(train_step, *kwargs)
。 Then initialize your train_step tensor and pass it through functools.partial
like this:然后初始化你的 train_step 张量并通过functools.partial
像这样传递它:
train_step = tf.Variable(0, trainable=False, name='global_step', dtype=tf.int64)
partial_decaying_eps = partial(decaying_epsilon, train_step *kwargs)
You can now pass partial_decaying_eps
to your agent and it will work as expected, updating with your train_step
Tensor progressively.您现在可以将partial_decaying_eps
传递给您的代理,它会按预期工作,并逐步更新您的train_step
张量。 Be sure to pass this same train_step
Tensor to your agent though.不过,请务必将相同的train_step
张量传递给您的代理。
Other HP can be modified easily, just look at the DQN documentation in its __init__
function其他HP可以轻松修改,只需查看其__init__
函数中的DQN文档即可
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.