Skip to content

Instantly share code, notes, and snippets.

@harisankarh
Last active September 28, 2018 21:15
Show Gist options
  • Save harisankarh/b69d780c12b903af94fbc40107edf534 to your computer and use it in GitHub Desktop.
Save harisankarh/b69d780c12b903af94fbc40107edf534 to your computer and use it in GitHub Desktop.
vowpal wabbit test
import os
import random as rand
iters = 1000
actual_threshold = 70
for i in range(iters):
score_sampled = rand.randint(0,100)
get_prob_command = " echo \" | f1:{} \" | netcat localhost 26542".format(score_sampled)
print(get_prob_command)
output = os.popen(get_prob_command).read()
prob_vector = output.split('\n')[0]
block_prob = float(output.split()[0])
rand_uni = rand.uniform(0.0,1.0)
update_template = " echo \" {action}:{action_cost}:{action_prob} | f1:{score_sampled} \" | netcat localhost 26542"
update_command = None
cost = None
action = None
if block_prob >= rand_uni:
#block
action = 'block'
if score_sampled >= actual_threshold:
#successful block
cost = 0
else:
#fp
cost = 1
update_command = update_template.format(action=1,action_cost=cost,action_prob=block_prob,score_sampled=score_sampled)
else:
#do not block
action = 'allow'
if score_sampled >= actual_threshold:
#fn
cost = 1
else:
#successful no action
cost = 0
update_command = update_template.format(action=2,action_cost=cost,action_prob=(1.0 - block_prob),score_sampled=score_sampled)
print(update_command)
op2 = os.popen(update_command).read()
print(actual_threshold,score_sampled,block_prob,action,cost)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment