-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzipfnumber.py
50 lines (40 loc) · 1.2 KB
/
zipfnumber.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 re,math
from operator import itemgetter
from numpy.random import zipf
frequency = {}
file_name = 'caida.txt'
try:
file_path = "DataSet/"+file_name
ifile = open(file_path ,'r')
except:
print "can't open "+file_name
else:
text = ifile.read()
ifile.close()
if text:
print "zipf ... "
nodes_list = []
if file_name.split(".")[0] == 'caida':
pattern_meas = re.compile(r"^(\d+)\s+(\d+)\s+([-]?\d+)$", re.VERBOSE | re.MULTILINE)
if file_name.split(".")[0] == 'amazon':
pattern_meas = re.compile(r"^(\d+)\s+(\d+)", re.VERBOSE | re.MULTILINE)
for match in pattern_meas.finditer(text):
nodes_list.append("%s" % int(match.group(1)))
nodes_list.append("%s" % int(match.group(2)))
for node in nodes_list:
count = frequency.get(node,0)
frequency[node] = count + 1
node_ocurr = []
s = []
for key, value in reversed(sorted(frequency.items(), key = itemgetter(1))):
node_ocurr.append([key,value/2])
s.append(zipf(2.,value/2))
a=2
s = zipf(a, 10)
result = (s/float(max(s)))*5
for i in result:
print (result[i])
print s[i]
print '------'
print min(s), max(s)
print min(result),max(result)