[英]How to get probability vector for all actions in tf-agents?
我正在使用LinearUCBAgent
和LinearThompsonSamplingAgent
解決多臂強盜問題,但它們都返回單個動作進行觀察。 我需要的是可用於排名的所有動作的概率。
您需要在定義代理時添加emit_policy_info
參數。 具體值(封裝在元組中)將取決於代理:對於predicted_rewards_sampled
的LinearThompsonSamplingAgent
和對於predicted_rewards_optimistic
的LinearUCBAgent
。
例如:
agent = LinearThompsonSamplingAgent(
time_step_spec=time_step_spec,
action_spec=action_spec,
emit_policy_info=("predicted_rewards_sampled")
)
然后,在推理過程中,您需要訪問這些字段並對其進行規范化(通過 softmax):
action_step = agent.collect_policy.action(observation_step)
scores = tf.nn.softmax(action_step.info.predicted_rewards_sampled)
其中tf
來自import tensorflow as tf
, observation_step
是封裝在 TimeStep 中的觀察數組( from tf_agents.trajectories.time_step import TimeStep
)
注意:這些不是概率,它們是標准化分數; 類似於全連接層的歸一化輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.