Tuesday, July 30, 2013

GUI Progress

I've come down with strep throat, and I won't be able to make it in today.

There have been a few bug fixes, as well as changing the centroid selection. The user clicks on the graph and a new box will appear overlapping the selected centroid (there will be a better indicator later. It's a placeholder for now).

A new window will be launched so that there will be proper room to see the deltas. Only deltas that are above a threshold will be visible.

I still need to work out bugs, and change it so that the user can pick the threshold. I also intend on adding the ability to see the attributes of a single centroid, as well as making the color of a point on the graph variable to reflect the defect class

Thursday, July 11, 2013

This weeks progress - Erin

I still have pneumonia, so I am not attending the meeting.

Prelic match score compares the rows in each bicluster to all other biclusters from the competing biclustering solution, and keeps the highest match score.  This is done for all of the clusters in the first biclustering solution.

The match score for all of the biclusters are averaged to give a final score.

I have the match score implemented and ran it to compare all of the algorithms solutions.
I do not have the analysis of these numbers complete.
I plan on running Wilcoxon against the population of match scores to see if there is a statistical difference between the scores.

I will add in the Jaccard Index and Liu's index to the code to provide additional match measurements. I will also compute Hedges' g for effect size.

Peeker GUI Progress

 Your Centroid Selection Method May Vary


Code 'n Stuff:


Centroid data:

clusterId, x, y, class, lcom3, ce, rfc, cbm, loc
0, 1.58397211319, -0.0432681148317, 0.914285714286, 5, 1, 1, 2, 1
1, 2.58774373831, 0.471971285372, 1.0, 5, 1, 1, 2, 1
2, 1.16517561376, -0.371146048932, 0.432432432432, 5, 1, 1, 1, 1
3, 2.08134724468, 0.182633950752, 0.758620689655, 5, 1, 1, 2, 1
4, 3.07060918722, 0.803626419167, 0.903225806452, 4, 1, 2, 2, 1
5, 2.55082940399, 0.261739913349, 0.75, 5, 1, 1, 2, 1
6, 2.16558214132, 0.480240059556, 0.833333333333, 5, 1, 1, 1, 1
7, 1.29619823833, -0.111457622989, 0.714285714286, 6, 1, 1, 1, 1
8, 1.63873965905, -0.305464834941, 0.285714285714, 3, 1, 1, 1, 1
9, 0.357360583273, -0.912243253683, 0.212121212121, 7, 1, 1, 1, 1
10, 3.20012449807, 0.433418626026, 0.833333333333, 4, 1, 1, 2, 1
11, 3.53375557599, 0.919199863541, 1.0, 5, 1, 2, 2, 1
12, 3.99132169835, 1.5743692604, 0.866666666667, 5, 2, 4, 3, 2
13, 3.17288399009, 1.35969003729, 0.777777777778, 4, 2, 3, 1, 1
14, 2.4873847976, 0.827375341413, 0.777777777778, 4, 1, 2, 2, 1
15, 0.87040871737, -0.342411732755, 0.153846153846, 6, 1, 1, 1, 1
16, -0.477507070513, -1.07814368133, 0.2, 9, 1, 1, 1, 1
17, 1.3265291435, -0.931907015429, 0.230769230769, 5, 1, 1, 1, 1
18, -1.8907652395, -2.92230373138, 0.228571428571, 10, 1, 1, 0, 1
19, 1.67894614243, 0.0792276010178, 0.909090909091, 4, 1, 1, 2, 1
20, 0.363484115168, -1.4811137624, 0.555555555556, 7, 1, 1, 0, 1
21, 2.31618438716, -0.238127701786, 0.434782608696, 5, 1, 1, 1, 1

Code:

from SimPy.SimPlot import *
from ScrolledText import ScrolledText
from tkFileDialog import askopenfilename
import fileinput

plt = SimPlot()
root = plt.root

class TopLevel:
    def __init__(self, root):
        self.filename = StringVar()
       
        self.fileSelect = Menu(root)
        self.fileSelect.add_command(label="Open", command=self.getFile)
        root.config(menu=self.fileSelect)
       
        self.header = Frame(root, width=500, height=20)
        self.topFrame = Frame(root, width=500, height=200, bg="green")
        self.botLeftFrame = Frame(root, width=250, height=200, bg="orange")
        self.botRightFrame = Frame(root, width=250, height=200, bg="yellow")
        self.giveCentroids = Button(root, text="Compare Selected Centroids", command=self.giveCentroids)
       
        self.giveCentroids.grid(columnspan=2,column=0, row=2)
        self.header.grid(columnspan=2, column=0, row=0)
        self.topFrame.grid(columnspan=2, column=0, row=1)
        self.botLeftFrame.grid(column=0, row=3)
        self.botRightFrame.grid(column=1, row=3)
       
        self.grid = Grid(self.topFrame)
        self.list = List(self.botLeftFrame)
        self.compare = Compare(self.botRightFrame)

        self.fDisplay = Label(self.header, textvariable=self.filename)
        self.fDisplay.pack()

    def getFile(self):
        self.filename.set(askopenfilename())
        self.fDisplay.update()
        self.parseFile()
        self.list.setInitialList(self.centroids)
        self.grid.drawGraph(self.centroids)
       

    def parseFile(self):
        # retrieves data points from file. returns list of centroid list of attributes
        for line in open(self.filename.get()):
            if(line[0]=="c"):
                continue
            centroid = []
            for a in line.strip().split(", "):
                centroid.append(a)
            self.centroids.append(centroid)
        # Centroid element: numeric identifier, x, y, defect class, {attributes}
        # print self.centroids
        return self.centroids

    def giveCentroids(self):
        if(len(self.list.selectedCentroids)==2):
            self.compare.giveCentroids(self.list.selectedCentroids)
   
    centroids = []
   
   
class Grid:
    centroids = []
    defectivePoints = []
    nonDefectivePoints = []
   
    def __init__(self, frame):
        self.frame = frame
        self.graph = plt.makeGraphBase(frame, 500, 200)
        self.graph.pack()

    def drawGraph(self, centroids):
        for c in centroids:
            if float(c[3])<.5:
                self.nonDefectivePoints.append([float(c[1]),float(c[2])])
            else:
                self.defectivePoints.append([float(c[1]),float(c[2])])
        self.noDefectSymbols = plt.makeSymbols(self.nonDefectivePoints, marker="square", size=1,fillcolor="blue")
        self.defectSymbols = plt.makeSymbols(self.defectivePoints, marker="square", size=1, fillcolor="red")
        self.obj = plt.makeGraphObjects([self.noDefectSymbols, self.defectSymbols])
        self.graph.draw(self.obj)
       

class List:
    curCentroids = [] #Displayed centroids
    selectedCentroids = [] #Centroids that have been picked
   
    def __init__(self, frame):
        self.frame = frame
       
        self.firstLabel = StringVar()
        self.firstVar = IntVar()
        self.firstCheck = Checkbutton(self.frame, textvariable=self.firstLabel,
                                      variable=self.firstVar, command=self.selectFirstCentroid)
        self.firstCheck.grid(columnspan=2, column=0, row=1)

        self.secondLabel = StringVar()
        self.secondVar = IntVar()
        self.secondCheck = Checkbutton(self.frame, textvariable=self.secondLabel,
                                       variable=self.secondVar, command=self.selectSecondCentroid)
        self.secondCheck.grid(columnspan=2, column=0, row=2)
       
        self.thirdLabel = StringVar()
        self.thirdVar = IntVar()
        self.thirdCheck = Checkbutton(self.frame, textvariable=self.thirdLabel,
                                      variable=self.thirdVar, command=self.selectThirdCentroid)
        self.thirdCheck.grid(columnspan=2, column=0, row=3)

        self.fourthLabel = StringVar()
        self.fourthVar = IntVar()
        self.fourthCheck = Checkbutton(self.frame, textvariable=self.fourthLabel,
                                       variable=self.fourthVar, command=self.selectFourthCentroid)
        self.fourthCheck.grid(columnspan=2, column=0, row=4)
       
        self.prevButton = Button(self.frame, text="Previous", command=self.setPrevList)
        self.nextButton = Button(self.frame, text="Next", command=self.setNextList)
        Label(self.frame, text="Select Centroids").grid(columnspan=2, column=0, row=0)
        self.prevButton.grid(column=0, row=5)
        self.nextButton.grid(column=1, row=5)

    def setInitialList(self, centroids):
        self.centroids = centroids
        for i in range(0,4):
            self.curCentroids.append(centroids[i])
        self.firstLabel.set(self.curCentroids[0][0])
        self.secondLabel.set(self.curCentroids[1][0])
        self.thirdLabel.set(self.curCentroids[2][0])
        self.fourthLabel.set(self.curCentroids[3][0])

    def updateList(self):
        self.firstCheck.update()
        self.secondCheck.update()
        self.thirdCheck.update()
        self.fourthCheck.update()
   
    def setPrevList(self):
        print "filler"

    def setNextList(self):
        print "filler"

    #So I can't get it to pass the relevant centroid. So I need a bunch of functions.
    def selectFirstCentroid(self):
        if len(self.selectedCentroids)>=2:
            self.firstCheck.deselect()
            return
        for i in range(0, len(self.selectedCentroids)):
            if self.curCentroids[0][0]==self.selectedCentroids[i][0]:
                self.firstCheck.deselct()
                return
        # If we're here, we know there aren't too many and the thing isn't already selected
        self.selectedCentroids.append(self.curCentroids[0])

    def selectSecondCentroid(self):
        if len(self.selectedCentroids)>=2:
            self.secondCheck.deselect()
            return
        for i in range(0, len(self.selectedCentroids)):
            if self.curCentroids[1][0]==self.selectedCentroids[i][0]:
                self.secondCheck.deselect()
                return
        self.selectedCentroids.append(self.curCentroids[1])

    def selectThirdCentroid(self):
        if len(self.selectedCentroids)>=2:
            self.thirdCheck.deselect()
            return
        for i in range(0, len(self.selectedCentroids)):
            if self.curCentroids[2][0]==self.selectedCentroids[i][0]:
                self.thirdCheck.deselect()
                return
        self.selectedCentroids.append(self.curCentroids[2])

    def selectFourthCentroid(self):
        if len(self.selectedCentroids)>=2:
            self.fourthCheck.deselect()
            return
        for i in range(0, len(self.selectedCentroids)):
            if self.curCentroids[3][0]==self.selectedCentroids[i][0]:
                self.fourthCheck.deselect()
                return
        self.selectedCentroids.append(self.curCentroids[3])
       
class Compare:
    centroid1 = []
    centroid2 = []
   
    def __init__(self, frame):
        self.frame = frame
        self.display = ScrolledText(frame, width=25, height=7)
        self.display['font'] = ('consolas', '12')
        self.display.pack()
        self.display.insert(END, "Attributes Deltas\n")
        self.display.config(state=DISABLED)

    def giveCentroids(self, centroids):
        self.centroid1 = centroids[0]
        self.centroid2 = centroids[1]
        self.displayDelta()

    def displayDelta(self):
        self.display.config(state=NORMAL)
        for i in range(1,len(self.centroid1)):
            printed = float(self.centroid1[i])-float(self.centroid2[i])
            self.display.insert(END, format(printed)+"\n")
        self.display.config(state=DISABLED)

window=TopLevel(root)

root.mainloop()

Tuesday, July 2, 2013

Python Development






Retrieving/parsing data from a (junk) file, posting it to a graph(canvas)