-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
43 lines (37 loc) · 1.51 KB
/
main.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
from cluster import graphData, Cluster
from util import *
def experiment(gd,K,lam,reps,gradientReps,improveReps):
bestll = 0
seed = 42
edgeFeatures,edge_set,nEdgeFeatures,nNodes,clusters,NodeIndex = gd.file_process()
print(NodeIndex,nEdgeFeatures,nNodes,clusters)
C = Cluster(K,reps,gradientReps,improveReps,lam,seed,edgeFeatures,
edge_set,nEdgeFeatures,nNodes,clusters,whichLoss='SYMMETRICDIFF')
print('cluster',C.cluster)
nseeds = 1 # Number of random restarts
for seed in range(nseeds):
seed+=1
C.train()
ll = C.loglikelihood(C.theta,C.alpha,C.chat)
print(C.chat)
if ll>bestll or bestll==0:
bestll = ll
bestClusters = C.chat
bestTheta = C.theta
bestAlpha = C.alpha
file = open('result.txt','w')
print('ll = ',bestll,file=file)
print('loss_zeroone = ', totalLoss(clusters, bestClusters, nNodes, 'ZEROONE'), file=file)
print("loss_symmetric = ", totalLoss(clusters, bestClusters, nNodes, 'SYMMETRICDIFF'), file=file)
print("fscore = ", 1 - totalLoss(clusters, bestClusters, nNodes, 'FSCORE'), file=file)
print('Clusters:\n',bestClusters,file=file)
print('Theta:\n', bestTheta, file=file)
print('Alpha:\n', bestAlpha, file=file)
# if __name__=='main':
ID = 'facebook/'+'698'
nodefile = ID+'.feat'
selffeatfile = ID+'.egofeat'
clusfile = ID+'.circles'
edgefile = ID+'.edges'
gd = graphData(nodefile, selffeatfile, clusfile, edgefile, 'FRIEND')
experiment(gd,3,1,25,50,5)