-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfull_relationship.py
80 lines (76 loc) · 2.65 KB
/
full_relationship.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
import snap
from datetime import datetime
import matplotlib.pyplot as plt
import util
import numpy as np
from scipy.stats.stats import pearsonr
edgeFile = 'brightkite/loc-brightkite_edges.txt'
checkinFile = 'brightkite/loc-brightkite_totalCheckins.txt'
# Build the Graphs
userGraph, geoGraph, visitGraph, coordinates, checkins = util.buildGraphs(edgeFile, checkinFile)
userList = []
for node in userGraph.Nodes():
Id = node.GetId()
if visitGraph.IsNode(Id):
userList.append(Id)
locList = []
for node in geoGraph.Nodes():
Id = node.GetId()
locNI = visitGraph.GetNI(Id)
deg = locNI.GetDeg()
if deg != 0:
locList.append(Id)
EiFiles = ['degreeIndex_part.txt', 'newRateIndex_part.txt', 'dominanceI2.txt']
BiFiles = ['loc_degreeI.txt', 'loc_edgenumI.txt', 'loc_entropyI.txt']
userMeanCorr = np.zeros((3, 3))
userMeanPvalue = np.zeros((3, 3))
userMedianCorr = np.zeros((3, 3))
userMedianPvalue = np.zeros((3, 3))
locMeanCorr = np.zeros((3, 3))
locMeanPvalue = np.zeros((3, 3))
locMedianCorr = np.zeros((3, 3))
locMedianPvalue = np.zeros((3, 3))
for i in xrange(3):
for j in xrange(3):
EiFile = EiFiles[i]
BiFile = BiFiles[j]
EiList = []
with open(EiFile) as f:
for line in f: EiList.append(float(line.split()[0]))
Eis = {userList[i]:EiList[i] for i in xrange(len(userList))}
BiList = []
with open(BiFile) as f:
for line in f: BiList.append(float(line.split()[0]))
Bis = {locList[i]:BiList[i] for i in xrange(len(locList))}
userMeanBi = []
userMedianBi = []
for userId in userList:
NI = visitGraph.GetNI(userId)
deg = NI.GetDeg()
BiList = []
for k in xrange(deg):
BiList.append(Bis[NI.GetNbrNId(k)])
userMeanBi.append(np.average(BiList))
userMedianBi.append(np.median(BiList))
c, p = pearsonr(EiList, userMeanBi)
userMeanCorr[i][j] = c
userMeanPvalue[i][j] = p
c, p = pearsonr(EiList, userMedianBi)
userMedianCorr[i][j] = c
userMedianPvalue[i][j] = p
locMeanEi = []
locMedianEi = []
for locId in locList:
NI = visitGraph.GetNI(locId)
deg = NI.GetDeg()
EiList = []
for k in xrange(deg):
EiList.append(Eis[NI.GetNbrNId(k)])
locMeanEi.append(np.average(EiList))
locMedianEi.append(np.median(EiList))
c, p = pearsonr(BiList, locMeanEi)
locMeanCorr[i][j] = c
locMeanPvalue[i][j] = p
c, p = pearsonr(BiList, locMedianEi)
locMedianCorr[i][j] = c
locMedianPvalue[i][j] = p