In [123]:
%pylab inline


Using matplotlib backend: TkAgg
Populating the interactive namespace from numpy and matplotlib

Read data & results


In [5]:
import pickle

def readPickle(filename):
    # load data from file
    pkl_file = open(filename, 'rb')
    data = pickle.load(pkl_file)
    pkl_file.close()
    return data

In [130]:
data=[None]*6
data[0]=readPickle(b[6])
data[1]=readPickle(b[1])
data[2]=readPickle(b[5])
data[3]=readPickle(b[0])
data[4]=readPickle(b[13])
data[5]=readPickle(b[10])

gauss = readPickle(b[4])
label=['QK-Means','K-Means']

Timing statistics


In [12]:
print 'Algorithm','mean','variance','best','worst'
for i,d in enumerate(data):
    print label[i],
    print np.mean(d['total time']), 
    print np.var(d['total time']), 
    print np.min(d['total time']), 
    print np.max(d['total time'])
print label[i]+'fit time',
print np.mean(d['fitness times']),
print np.var(d['fitness times']),
print np.min(d['fitness times']),
print np.max(d['fitness times'])


Algorithm mean variance best worst
QK-Means 62.02642975 0.0770652119094 61.620424 62.579969
K-Means 6.4774672 0.00250165066026 6.352554 6.585451
K-Meansfit time 63.7463614 0.019722104537 63.536551 63.963121

In [15]:
print 'Algorithm','mean','variance','best','worst'
for i,d in enumerate(data):
    print label[i],
    print np.mean(d['fitness best']),
    print np.mean(d['fitness worst']),
    print np.mean(d['fitness mean']),
    print np.mean(d['fitness variance'])


Algorithm mean variance best worst
QK-Means 15.425319267 32.295774255 19.94704511 21.235445673
K-Means 15.425319267 25.4491381663 16.2501336483 1.21691927827

In [16]:
for i,var in enumerate(data[0]['pop variance'][0:3]):
    plt.plot(range(100),var,label='round '+str(i))
plt.title('Population variance evolution on each round')
plt.xlabel('Generation')
plt.ylabel('Variance')


Out[16]:
<matplotlib.text.Text at 0x7f191dac6590>

In [85]:
for i,var in enumerate(data[0]['pop mean'][0:3]):
    plt.plot(range(100),var,label='round '+str(i))

plt.title('Population mean evolution on each round')
plt.xlabel('Generation')
plt.ylabel('Mean')


Out[85]:
<matplotlib.text.Text at 0x7f1914a2ed10>

One would expect for the population's fitness variance to decrease over the generations, as the probabilities for previous known solutions increase. The convergence of the population mean would also be expected for the same reason. However, experimental results don't suggest any of these expectations. This may be due to low number of generations or simply because the random generation of initial centroids isn't influenced enough by the qubit probabilities.


In [81]:
convGen=[0]*len(data[0]['best evolution'])
for i,evo in enumerate(data[0]['best evolution']):
    convGen[i]=np.argmin(evo)

print "convergence speed"
print 'mean','variance','best','worst'
print np.mean(convGen),
print np.var(convGen),
print np.min(convGen),
print np.max(convGen)


convergence speed
mean variance best worst
17.25 70.2875 3 33

In [83]:
for i,evo in enumerate(data[0]['best evolution']):
    plt.plot(range(100),evo,label='round '+str(i))
plt.title('Fitness evolution on each round')
plt.xlabel('Generation')
plt.ylabel('Fitness')


Out[83]:
<matplotlib.text.Text at 0x7f191d9d6890>

In [1]:
# CSS styling within IPython notebook
from IPython.core.display import HTML
import urllib2
def css_styling():
    url = 'https://raw.githubusercontent.com/plotly/python-user-guide/master/custom.css'
    styles = urllib2.urlopen(url).read()
    return HTML(styles)

css_styling()


Out[1]: