-
-
Save nishio/d57e424dafa9b0bb2b86ed31468e0e6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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