Skip to content

Instantly share code, notes, and snippets.

@nishio
Created November 27, 2017 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nishio/d57e424dafa9b0bb2b86ed31468e0e6e to your computer and use it in GitHub Desktop.
Save nishio/d57e424dafa9b0bb2b86ed31468e0e6e to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
import numpy as np
from collections import Counter
N = 100
D = 2
p = 0.5
q = 0.3
NUM_ITER = 100000
def score(actions, axis):
score = actions.dot(axis)
ret = np.zeros(N)
best = score.argsort()[:int(N * q)]
ret[best] = 1
return ret
def test():
buf = np.zeros((NUM_ITER, 3))
for i in range(NUM_ITER):
actions = np.random.normal(size=(N, D))
observable = np.random.binomial(1, p, size=N)
observed_actions = actions[observable == 1]
mean = observed_actions.mean(0)
axis = np.random.normal(size=D)
original = actions[0].copy()
for j, eta in enumerate([0.0, 0.5, -1.0]):
actions[0] = original + (mean - original) * eta
buf[i, j] = score(actions, axis)[0]
print(buf.mean(0))
test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment