forked from bwilder0/clusternet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflumax.py
50 lines (46 loc) · 1.41 KB
/
influmax.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
import numpy as np
def rounding(x):
def pipage_round(x):
y = x.clone()
T = []
for i in range(len(y)):
if (0 < y[i] and y[i] < 1):
T.append(i)
try:
while (len(T) > 0):
i, j = T[0], T[1]
if (y[i] + y[j] < 1):
p = y[j] / (y[i] + y[j])
if (np.random.rand() < p):
y[j] += y[i]
y[i] = 0.
del T[0]
else:
y[i] += y[j]
y[j] = 0.
del T[1]
else:
p = (1. - y[i]) / (2. - y[i] - y[j])
if (np.random.rand() < p):
y[i] += y[j] - 1.
y[j] = 1.
del T[1]
if (y[i] == 0.):
del T[0]
else:
y[j] += y[i] - 1.
y[i] = 1.
del T[0]
if (y[j] == 0.):
del T[0]
except:
return y
return y
def regularize_answer(ans):
pp = pipage_round(ans)
pp[pp < 1] = 0.
return pp
px = regularize_answer(x)
return px
# v = [i for i in range(len(x)) if px[i] != 0]
# return v[0]