-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
53 lines (37 loc) · 1.11 KB
/
server.py
File metadata and controls
53 lines (37 loc) · 1.11 KB
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
from sklearn import tree, ensemble, neighbors, svm, linear_model
import math
import numpy as np
import pickle
def GenGlobal(errors, sizes):
errors = np.array(errors)
sizes = np.array(sizes)
errors = np.reshape(errors, (sizes.shape[0], sizes.shape[0]))
weights = []
sortedErrors = np.sort(errors, axis = 1)
mydict = dict()
rows = errors.shape[0]
cols = errors.shape[1]
for i in range(rows):
firstValue = 1
if(sortedErrors[i][0] == -np.inf):
firstValue = 0
for j in range(cols):
key = mydict.get(str(sortedErrors[i][j]))
if key == None:
mydict[str(sortedErrors[i][j])] = firstValue
firstValue += 1
for j in range(cols):
errors[i][j] = mydict[str(errors[i][j])]
mydict.clear()
for i in range(len(sizes)):
currWeight = 0.0
if sizes[i] != 0.0:
for j in range(cols):
if(errors[i][j] != 0):
currWeight += math.pow(2, -errors[i][j])
currWeight *= sizes[i]
weights.append(currWeight)
weights = np.array(weights)
weights[weights < np.median(weights)] = 0.0
weights = weights / np.sum(weights)
return weights