-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
55 lines (50 loc) · 1.58 KB
/
utils.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
import csv
from grakel import Graph
import numpy as np
def readFromFile(numbers,labelsFile,folder):
files = list()
graphs = list()
labels = list()
for el in numbers:
string = "datasets/"+folder+"/graph"+el+".csv"
files.append(string)
for el in files:
file = open(el, "r")
csvreader = csv.reader(file)
rows = []
for row in csvreader:
rows.append(row)
matrix_size = len(rows)
edges = list()
for i in range(0,matrix_size):
for j in range(0,matrix_size):
if(rows[i][j] == "1"):
edges.append((i,j))
graphs.append(Graph(edges))
file = open(labelsFile, "r")
csvreader = csv.reader(file)
for el in csvreader:
labels.append(int(el[0]))
return (graphs,np.array(labels))
def prepareResults(scores,neighbors,dim,labels):
res = labels
res = res + "\nMin: "+str(np.min(scores))
res = res + "\nMean:"+str(np.mean(scores))
res = res + "\nMax: "+str(np.max(scores))
if neighbors != 0:
res = res + "\nNeighbors: "+str(neighbors)
if dim != 0:
res = res + "\nDimension: "+str(dim)
return res
def writeToFile(stringToWrite):
f = open("results.txt", "a")
f.write(stringToWrite)
f.close()
def printResults(scores,neighbors,dim):
print("Min: "+str(np.min(scores)))
print("Mean:"+str(np.mean(scores)))
print("Max: "+str(np.max(scores)))
if neighbors != 0:
print("Neighbors: "+str(neighbors))
if dim != 0:
print("Dimension: "+str(dim))