【问题标题】:Can contextual bandit rewards be changed over time?上下文强盗奖励可以随着时间而改变吗?
【发布时间】:2022-01-07 03:38:13
【问题描述】:

我正在使用 Vowpal Wabbit 实现一个上下文强盗,用于动态定价,其中武器代表价格利润。成本/回报由价格 - 预期成本决定。成本最初是未知的,因此它是一个预测并且有可能发生变化。我的问题是,如果您的成本/回报会随时间变化,您能否更新成本/回报以反映实际成本并重新训练模型?

下面是一个带有 1 个特征(用户)的训练集和一个测试集的示例。成本基于预期的净收入。该模型经过训练并用于预测为测试集中的客户采取的行动。

import pandas as pd
import sklearn as sk
import numpy as np
from vowpalwabbit import pyvw

train_data = [{'action': 1, 'cost': -150, 'probability': 0.4, 'user': 'a'},
              {'action': 3, 'cost': 0, 'probability': 0.2, 'user': 'b'},
              {'action': 4, 'cost': -250, 'probability': 0.5, 'user': 'c'},
              {'action': 2, 'cost': 0, 'probability': 0.3, 'user': 'a'},
              {'action': 3, 'cost': 0, 'probability': 0.7, 'user': 'a'}]

train_df = pd.DataFrame(train_data)

# Add index to data frame
train_df['index'] = range(1, len(train_df) + 1)
train_df = train_df.set_index("index")

# Test data
test_data = [{'user': 'b'},
            {'user': 'a'},
            {'user': 'b'},
            {'user': 'c'}]

test_df = pd.DataFrame(test_data)

# Add index to data frame
test_df['index'] = range(1, len(test_df) + 1)
test_df = test_df.set_index("index")

# Create python model and learn from each trained example
vw = pyvw.vw("--cb 4")

for i in train_df.index:
  action = train_df.loc[i, "action"]
  cost = train_df.loc[i, "cost"]
  probability = train_df.loc[i, "probability"]
  user = train_df.loc[i, "user"]

  # Construct the example in the required vw format.
  learn_example = str(action) + ":" + str(cost) + ":" + str(probability) + " | " + str(user) 

  # Here we do the actual learning.
  vw.learn(learn_example)
  
# Predict actions
for j in test_df.index:
  user = test_df.loc[j, "user"]

  test_example = "| " + str(user)

  choice = vw.predict(test_example)
  print(j, choice)  

但是,一周后我们收到了新信息,训练集中索引 0 的成本高于预期,而索引 2 的成本低于预期。这些新信息能否用于重新训练模型和预测动作?

## Reward/cost changed after 1 week once cost was realized
train_data = [{'action': 1, 'cost': 200, 'probability': 0.4, 'user': 'a'}, # Lost money
              {'action': 3, 'cost': 0, 'probability': 0.2, 'user': 'b'},
              {'action': 4, 'cost': -350, 'probability': 0.5, 'user': 'c'}, # Made more than exp.
              {'action': 2, 'cost': 0, 'probability': 0.3, 'user': 'a'},
              {'action': 3, 'cost': 0, 'probability': 0.7, 'user': 'a'}]

【问题讨论】:

    标签: python reinforcement-learning vowpalwabbit reward


    【解决方案1】:

    是的,我不明白为什么随着时间的推移改变奖励会有问题。这当然也是现实世界的运作方式。在不断变化的世界中,行动可能不太合适或更合适。 Contextual bandits 在非平稳环境中运行良好,所以应该没问题。

    需要注意的一点是,如果您的环境是非固定的,您可能希望将--power_t 选项提供为0。默认情况下,VW 的学习率会随着时间的推移而衰减 (t),就好像您的问题是静止的,您希望收敛到一个解决方案。

    【讨论】:

    • 感谢您的回复!如果我使用--cb_explore_adf,这也适用吗?为简单起见,我在此示例中使用了 --cb 4。此外,是否有某个地方列出了默认超参数设置的内容?我很难找到这些信息。
    • 是的,ADF 也是如此。您可以查看 here 以获取默认选项值。有些东西不是以这样的方式编写的,即它们的默认值在该列表中,此时它正在查看不太好的代码,对此感到抱歉。我现在做一个传递,看看我可以在那个 wiki 页面上展示什么。
    猜你喜欢
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 2019-12-22
    • 1970-01-01
    相关资源
    最近更新 更多