-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
85 lines (71 loc) · 2.63 KB
/
plot.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#-*- coding: utf-8 -*-
import matplotlib
matplotlib.use("TkAgg")
import matplotlib.pyplot as plot
import math
import random as rd
import numpy as np
def plot_curves(adamic, cosine, jaccard, PA, hub, ylabel, title, loc):
x = [1,5,10,20]
maximums = [max(adamic), max(cosine), max(jaccard), max(PA), max(hub)]
plot.figure()
plot.title(title)
plot.ylim(-0.2, max(maximums)+0.2)
plot.xlabel('Top-N Produtos')
plot.ylabel(ylabel)
plot.grid()
plot.margins(y=1)
plot.plot(x, adamic, 'bo-', label='Adamic-Adar')
plot.plot(x, cosine, 'go-', label='Cosseno')
plot.plot(x, jaccard,'ro-', label='Jaccard')
plot.plot(x, PA, 'ko-', label='Preferential Attachment')
plot.plot(x, hub, 'mo-', label='Hub Depressed')
plot.legend(loc=loc)
plot.show()
def plot_curve(adamic, cosine, jaccard, PA, hub, N, degrees, ylabel, loc):
maximums = [max(adamic), max(cosine), max(jaccard), max(PA), max(hub)]
plot.figure()
plot.title('Top-' + N + ' Produto(s)')
plot.ylim(max(maximums))
plot.xlabel('Graus')
plot.ylabel(ylabel)
plot.grid()
plot.margins(y=1)
plot.plot(degrees, adamic, 'bo-', label='Adamic-Adar')
plot.plot(degrees, cosine, 'go-', label='Cosseno')
plot.plot(degrees, jaccard,'ro-', label='Jaccard')
plot.plot(degrees, PA, 'ko-', label='Preferential Attachment')
plot.plot(degrees, hub, 'mo-', label='Hub Depressed')
plot.legend(loc=loc)
plot.show()
def plot_distribution(n_vertices, all_measure, xlabel, filename, metric='degree'):
freq = freq_relative(n_vertices, all_measure, metric)
plot.xscale('log')
plot.yscale('log')
plot.ylabel('CDF')
plot.xlabel(xlabel)
plot.plot(range(len(freq)), freq, 'o', clip_on=False)
plot.savefig('graficos/'+filename+'_cdf.jpg')
plot.clf()
def plot_ccdf(n_vertices, all_measure, xlabel, filename, metric='degree'):
_ccdf = ccdf(n_vertices, all_measure, metric)
#plot.xscale('log')
#plot.yscale('log')
plot.ylabel('CCDF')
plot.xlabel(xlabel)
plot.plot(range(len(_ccdf)), _ccdf, 'o', clip_on=False)
plot.savefig('graficos/'+filename+'_ccdf.jpg')
plot.clf()
def freq_relative(n_vertices, all_measure, metric='degree'):
if metric == 'degree':
degree_distribution = np.bincount(list(all_measure))
return degree_distribution/n_vertices
elif metric == 'distance':
distance_distribution = np.bincount(list(all_measure))
return distance_distribution/comb(n_vertices, 2)
else:
all_measure = np.array(all_measure)
all_sum = float(all_measure.sum())
return all_measure.cumsum(0)/all_sum
def ccdf(n_vertices, all_measure, metric='degree'):
return 1 - freq_relative(n_vertices, all_measure, metric)