Skip to content

Instantly share code, notes, and snippets.

@kretes
Created April 26, 2017 15:37
Show Gist options
  • Save kretes/b2b7e6df925350ccde963bd4b3f91945 to your computer and use it in GitHub Desktop.
Save kretes/b2b7e6df925350ccde963bd4b3f91945 to your computer and use it in GitHub Desktop.
understanding stratium linucb bandit API
from striatum.storage import history
from striatum.storage import model
from striatum.bandit import linucb
from striatum.storage.action import ActionStorage, MemoryActionStorage, Action
historystorage = history.MemoryHistoryStorage()
modelstorage = model.MemoryModelStorage()
actionstorage = MemoryActionStorage()
actionstorage.add([Action(1),Action(2),Action(3)])
actionstorage.count()
policy = linucb.LinUCB(historystorage, modelstorage, actionstorage, alpha=0.3, context_dimension=3)
ct = [0.5,-0.1,1]
ctx = {
1: ct,
2: ct,
3: ct,
}
hist_id, recs = policy.get_action(ctx,5)
print(hist_id)
for rec in recs:
print(rec.action.id, rec.estimated_reward, rec.uncertainty, rec.score, rec.reward)
policy.reward(11,{3:1})
policy.add_action([Action(4)])
modelstorage.get_model()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment