In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [3]:
import sklearn
from sklearn import preprocessing,decomposition,datasets
import seaborn as sns

In [36]:
%cd /home/chiroptera/workspace/QCThesis/Horn
import HornAlg
reload(HornAlg)


/home/chiroptera/workspace/QCThesis/Horn
Out[36]:
<module 'HornAlg' from 'HornAlg.py'>

In [6]:
%cd /home/chiroptera/workspace/QCThesis/cluster\ consistency
import determine_ci
reload(determine_ci)


/home/chiroptera/workspace/QCThesis/cluster consistency
Out[6]:
<module 'determine_ci' from 'determine_ci.pyc'>

In [47]:
# These are the "Tableau 20" colors as RGB.  
tableau20 = [(31, 119, 180), (174, 199, 232), (255, 127, 14), (255, 187, 120),  
             (44, 160, 44), (152, 223, 138), (214, 39, 40), (255, 152, 150),  
             (148, 103, 189), (197, 176, 213), (140, 86, 75), (196, 156, 148),  
             (227, 119, 194), (247, 182, 210), (127, 127, 127), (199, 199, 199),  
             (188, 189, 34), (219, 219, 141), (23, 190, 207), (158, 218, 229)]
# Scale the RGB values to the [0, 1] range, which is the format matplotlib accepts.  
for i in range(len(tableau20)):  
    r, g, b = tableau20[i]  
    tableau20[i] = (r / 255., g / 255., b / 255.)

In [7]:
crabsPCA=True
crabsNormalize=False

crabs=np.genfromtxt('/home/chiroptera/workspace/datasets/crabs/crabs.dat')
crabsData=crabs[1:,3:]

# PCA
if crabsPCA:
    ncrabsData1, cComps,cEigs=HornAlg.pcaFun(crabsData,whiten=True,center=False,
                                             method='eig',type='cov',normalize=crabsNormalize)
    ncrabsData2, cComps,cEigs=HornAlg.pcaFun(crabsData,whiten=True,center=True,
                                             method='eig',type='corr',normalize=crabsNormalize)
    ncrabsData3, cComps,cEigs=HornAlg.pcaFun(crabsData,whiten=True,center=True,
                                             method='eig',type='cov',normalize=crabsNormalize)

# real assignment
crabsAssign=np.ones(200)
crabsAssign[50:99]=2
crabsAssign[100:149]=3
crabsAssign[150:199]=4

In [37]:
sigma=1.0/sqrt(2)
steps=20
crab2cluster=ncrabsData1
crabD,V,E,listStep=HornAlg.graddesc(crab2cluster[:,1:3],sigma=sigma,steps=steps,timelapse=True,timelapse_percent=0.5)

In [56]:
%%debug
fig = pyplot.figure(figsize=(16,6*6))

for i in range(11):
    ax = fig.add_subplot(6,2,i+1)
    ax.set_title('Step ' + str(listStep[i])
    
    ax.plot(crabD[i][:,0],crabD[i][:,1],marker='.', color=tableau20[i*2], lw=1)
    ax.set_yscale('linear')


NOTE: Enter 'c' at the ipdb>  prompt to continue execution.
---------------------------------------------------------------------------
SyntaxError                               Traceback (most recent call last)
SyntaxError: invalid syntax (<string>, line 8)

In [53]:
plot(crabD[0][:,0],crabD[0][:,1], color=tableau20[0], lw=1,marker='.')


Out[53]:
[<matplotlib.lines.Line2D at 0x7f2dd0279b90>]

In [35]:
timelapse_percent=0.5
timelapse_list=range(steps)[::int(steps/(steps*timelapse_percent))]
timelapse_list


Out[35]:
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]