-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalizations.py
37 lines (31 loc) · 1.63 KB
/
normalizations.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
#normalizations.py
def min_max(self,metric_name):
#perform min max normalization of specified metric for all nodes
#min_max normalization
#get min and max from redis
x_min = self.redis.zrange(self.metric_prefix+metric_name, 0, 0, withscores=True, score_cast_func=float)[0][1]
x_max = self.redis.zrange(self.metric_prefix+metric_name, -1, -1, withscores=True, score_cast_func=float)[0][1]
#print x_min
#print x_max
for node in self.nodes:
if x_min == x_max:
x_normalized = 1.0
else:
x = float(self.redis.hget(self.node_prefix+str(node), metric_name))
x_normalized = (x - x_min) / (x_max - x_min)
#store value for node and metric
self.redis.zadd(self.metric_prefix+metric_name+self.normalization_suffix, x_normalized, str(node))
self.redis.hset(self.node_prefix+str(node),metric_name+self.normalization_suffix, x_normalized)
#max min normalization
def max_min(self,metric_name):
x_min = self.redis.zrange(self.metric_prefix+metric_name, 0, 0, withscores=True, score_cast_func=float)[0][1]
x_max = self.redis.zrange(self.metric_prefix+metric_name, -1, -1, withscores=True, score_cast_func=float)[0][1]
for node in self.nodes:
if x_min == x_max:
x_normalized = 1.0
else:
x = float(self.redis.hget(self.node_prefix+str(node), metric_name))
x_normalized = (x_max - x) / (x_max - x_min)
#store value for node and metric
self.redis.zadd(self.metric_prefix+metric_name+self.normalization_suffix, x_normalized, str(node))
self.redis.hset(self.node_prefix+str(node),metric_name+self.normalization_suffix, x_normalized)