-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_reducer.py
executable file
·56 lines (43 loc) · 1.27 KB
/
test_reducer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
import sys
import base64
import cPickle as pickle
#from mrjob.job import MRJob
import numpy as np
def main():
sum_ETE = None
sum_ETDe = None
old_key = 1
for line in sys.stdin:
line = line.strip()
#print line
key, values = line.split('\t', 1)
key = int(key)
if key == old_key:
key,result, sum_ETE, sum_ETDe = reducer(key,values, sum_ETE, sum_ETDe)
old_key = key
else:
print "$".join(result.split(','))
sum_ETE = None
sum_ETDe = None
key,result, sum_ETE, sum_ETDe = reducer(key,values, sum_ETE, sum_ETDe)
old_key = key
print "$".join(result.split(','))
def reducer(key, values, sum_ETE, sum_ETDe):
mu = 0.1
#print values
ETE, ETDe = pickle.loads(base64.b64decode(values))
if sum_ETE == None:
sum_ETE = np.matrix(np.eye(ETE.shape[1])/mu)
sum_ETE += ETE
if sum_ETDe == None:
sum_ETDe = ETDe
else:
sum_ETDe += ETDe
#print "sum_ETE",sum_ETE
#print "sum_ETDe",sum_ETDe
#print "sum_ETE.I",sum_ETE.I
result = sum_ETE.I * sum_ETDe
#print "result",result
return(key, str(result.tolist()), sum_ETE, sum_ETDe)
main()