In [1]:
from pymisca.util import *
from pymisca.vis_util import *
import IPython.display as ipd
import KBs
import random
DIR = 'data_pdist'
!mkdir -p {DIR}
appx 10 rule per sec caching time is 1 min then 600 rules per cache
In [ ]:
%%time
import os
import workers
import time
ts = []
t0 = time.time()
oit = list(range(471,60*24))
for seed in oit:
bsize= 600
worker = workers.worker0323
kb = KBs.kb_2dntca()
it = kb.bulk_rstr(seed=seed,bsize=bsize)
out = mp_map(worker,it,n_cpu=6)
fname = os.path.join(DIR,'seed%d_size%d.npy'%(seed,bsize))
np.save(fname,out)
print "finished %d of %d"%(seed,len(oit))
t = time.time()
ts.append(t-t0)
t0 = t
# break
print 'finished'
print 'avgtime:%.5fs'%(np.mean(ts))
In [ ]:
print 'avgtime:%.5fs'%(np.mean(ts))
In [10]:
# tst_dct = [{'family':'2dntca','rulestr':x[1]} for x in KBs.tst_data]
# tst_out = mp_map(worker,tst_dct,n_cpu=12)
# print 'finished'
# plt.figure(figsize=(12,7))
# dt = map(lambda x:x.get('data').get('med'),tst_out)
# xs,ys = zip(*dt)
# plt.scatter(*zip(*dt),color='red')
# for i,(x,y) in enumerate(dt):
# x = x+(np.random.random()-0.5)/50.
# y = y+(np.random.random()-0.5)/50.
# plt.text(x,y,i )
# plt.plot([0,1],[0,1],'r--')
# dt = map(lambda x:x.get('data').get('med'),out)
# xs,ys = zip(*dt)
# plt.scatter(*zip(*dt),color='blue')
# for i,(x,y) in enumerate(dt):
# x = x+(np.random.random()-0.5)/50.
# y = y+(np.random.random()-0.5)/50.
# plt.text(x,y,i)
# plt.plot([0,1],[0,1],'r--')
# plt.grid()
# plt.show()
In [24]:
tst_dct = [{'family':'2dntca','rulestr':x[1]} for x in KBs.tst_data]
tst_out = mp_map(worker,tst_dct,n_cpu=8)
print 'finished'
In [ ]:
c1='''
0
5
10
11
13
15
16
19
21
26'''
c2='''
6
1
27
31'''
c3='''
3
8
25'''
c4='''
17
18
20
28'''
In [ ]:
6
1
27
31
In [ ]:
2
4
7
9
29
30
12
14
22
23
24
In [ ]:
3
8
25
In [ ]:
17
18
20
28
In [91]:
KBs.lview(KBs.guess(dct=tst_dct[16]))
Out[91]: