<s> '''<STR_LIT>''' <EOL> import time , logging , random <EOL> from hashlib import sha1 <EOL> import matplotlib <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> import matplotlib . pyplot as plt <EOL> import numpy as np <EOL> from datasketch import WeightedMinHashGenerator <EOL> logging . basicConfig ( level = logging . INFO ) <EOL> def run_perf ( dim , num_rep , sample_size ) : <EOL> wmg = WeightedMinHashGenerator ( dim , sample_size = sample_size ) <EOL> logging . info ( "<STR_LIT>" % sample_size ) <EOL> data = np . random . uniform ( <NUM_LIT:0> , dim , ( num_rep , dim ) ) <EOL> durs = [ ] <EOL> for i in range ( num_rep ) : <EOL> start = time . clock ( ) <EOL> wmg . minhash ( data [ i ] ) <EOL> duration = ( time . clock ( ) - start ) * <NUM_LIT:1000> <EOL> durs . append ( duration ) <EOL> ave = np . mean ( durs ) <EOL> logging . info ( "<STR_LIT>" % ( num_rep , ave ) ) <EOL> return ave <EOL> def jaccard ( v1 , v2 ) : <EOL> min_sum = np . sum ( np . minimum ( v1 , v2 ) ) <EOL> max_sum = np . sum ( np . maximum ( v1 , v2 ) ) <EOL> return float ( min_sum ) / float ( max_sum ) <EOL> def run_acc ( dim , num_rep , sample_size ) : <EOL> logging . info ( "<STR_LIT>" % sample_size ) <EOL> wmg = WeightedMinHashGenerator ( dim , sample_size = sample_size ) <EOL> data1 = np . random . uniform ( <NUM_LIT:0> , dim , ( num_rep , dim ) ) <EOL> data2 = np . random . uniform ( <NUM_LIT:0> , dim , ( num_rep , dim ) ) <EOL> errs = [ ] <EOL> for i in range ( num_rep ) : <EOL> wm1 = wmg . minhash ( data1 [ i ] ) <EOL> wm2 = wmg . minhash ( data2 [ i ] ) <EOL> j_e = wm1 . jaccard ( wm2 ) <EOL> j = jaccard ( data1 [ i ] , data2 [ i ] ) <EOL> errs . append ( abs ( j - j_e ) ) <EOL> ave = np . mean ( errs ) <EOL> logging . info ( "<STR_LIT>" % ( num_rep , ave ) ) <EOL> return ave <EOL> sample_sizes = range ( <NUM_LIT:10> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> num_rep = <NUM_LIT:100> <EOL> dim = <NUM_LIT> <EOL> output = "<STR_LIT>" <EOL> logging . info ( "<STR_LIT>" ) <EOL> run_times = [ run_perf ( dim , num_rep , n ) for n in sample_sizes ] <EOL> logging . info ( "<STR_LIT>" ) <EOL> errs = [ run_acc ( dim , num_rep , n ) for n in sample_sizes ] <EOL> logging . info ( "<STR_LIT>" ) <EOL> fig , axe = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:2> , sharex = True , figsize = ( <NUM_LIT:10> , <NUM_LIT:4> ) ) <EOL> ax = axe [ <NUM_LIT:1> ] <EOL> ax . plot ( sample_sizes , run_times , marker = '<STR_LIT:+>' ) <EOL> ax . set_xlabel ( "<STR_LIT>" ) <EOL> ax . set_ylabel ( "<STR_LIT>" ) <EOL> ax . set_title ( "<STR_LIT>" ) <EOL> ax . grid ( ) <EOL> ax = axe [ <NUM_LIT:0> ] <EOL> ax . plot ( sample_sizes , errs , marker = '<STR_LIT:+>' ) <EOL> ax . set_xlabel ( "<STR_LIT>" ) <EOL> ax . set_ylabel ( "<STR_LIT>" ) <EOL> ax . set_title ( "<STR_LIT>" ) <EOL> ax . grid ( ) <EOL> fig . savefig ( output , bbox_inches = "<STR_LIT>" ) <EOL> logging . info ( "<STR_LIT>" % output ) </s>
