-
Notifications
You must be signed in to change notification settings - Fork 2
/
batest.py
69 lines (60 loc) · 2.06 KB
/
batest.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
import sys
from utils import evaluateEM_NMI
import Cons
from cData import *
import RepPoints
import Starts
def parseCommandLine (D,argv):
if len(argv) != 2 and len(argv) != 3:
print("Error - usage is " + argv[0] + " <data_file> <startingdatapoints> ")
sys.exit(1)
RP = RepPoints.RepPoints()
EmAlg = cEM(D)
if len(argv)>2:
f = open(argv[2],"r")
EmAlg = pickle.load(f)
EmAlg.EM(len(D.classlist))
EmAlg.bPPC = True
emclusts = RP.createClusters(EmAlg)
RP.repPoints(EmAlg, emclusts)
else:
EmAlg.EM(len(D.classlist))
EmAlg.bPPC = True
# Creates clusters depending on what EM guessed.
emclusts = RP.createClusters(EmAlg)
# Finds the outerpoints and the midpoints and assigns them in emclusters.
RP.repPoints(EmAlg, emclusts)
# This makes the algorithm start with good initial points.
starter = Starts.starts()
EmAlg = starter.goodInitial(D, EmAlg, emclusts, RP, 0)
f = open("pickles/"+argv[1].split('/')[-1]+"pickle","w")
pickle.dump(EmAlg,f)
EmAlg.EM(len(D.classlist))
f.close()
return EmAlg
def main():
# Takes in the file and parses into datum's.
D = cData(sys.argv[1])
# Starting points from the pickle or not.
EmAlg = parseCommandLine(D, sys.argv)
prevCons = 0
totalcons = 0
nmiResult = evaluateEM_NMI(D, EmAlg)
print "Initial nmi: ",nmiResult
consobj = Cons.cCons(D)
for numCons in range(1,len(D.data)/4,1):
consobj.constype = Cons.cCons.eConsType.TripCenterChunk
consobj.centerChunkSize = 0.2
cons = consobj.tripCons(EmAlg.mGammas,numCons-prevCons)
prevCons = numCons
totalcons += len(cons)
for i in cons:
EmAlg.mCij[i[0]][i[1]] = i[2]
EmAlg.mCij[i[1]][i[0]] = i[2]
EmAlg.EM(len(D.classlist))
nmiresult = evaluateEM_NMI(D, EmAlg)
print numCons, ",", nmiresult, ",", totalcons
if(nmiresult > 0.999 or len(D.data)==numCons):
break
if __name__ == "__main__":
main()