In [123]:

%pylab inline




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



### Read data & results



In [5]:

import pickle

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




In [130]:

data=[None]*6

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'
return HTML(styles)

css_styling()




Out[1]:

div.cell{
width: 850px;
margin-left: 10% !important;
margin-right: auto;
}
h1 {
font-family: "Open sans",verdana,arial,sans-serif;
}
.text_cell_render h1 {
font-weight: 200;
font-size: 40pt;
line-height: 100%;
margin-bottom: 0em;
margin-top: 0em;
display: block;
white-space: nowrap;
}
h2 {
font-family: "Open sans",verdana,arial,sans-serif;
text-indent:1em;
}
.text_cell_render h2 {
font-weight: 200;
font-size: 20pt;
font-style: italic;
line-height: 100%;
margin-bottom: 1.5em;
margin-top: 0.5em;
display: block;
white-space: nowrap;
}
h3 {
font-family: "Open sans",verdana,arial,sans-serif;
}
.text_cell_render h3 {
font-weight: 300;
font-size: 18pt;
line-height: 100%;
margin-bottom: 0.5em;
margin-top: 2em;
display: block;
white-space: nowrap;
}
h4 {
font-family: "Open sans",verdana,arial,sans-serif;
}
.text_cell_render h4 {
font-weight: 300;
font-size: 16pt;
margin-bottom: 0.5em;
margin-top: 0.5em;
display: block;
white-space: nowrap;
}
h5 {
font-family: "Open sans",verdana,arial,sans-serif;
}
.text_cell_render h5 {
font-weight: 300;
font-style: normal;
color: #1d3b84;
font-size: 16pt;
margin-bottom: 0em;
margin-top: 1.5em;
display: block;
white-space: nowrap;
}
div.text_cell_render{
font-family: "Open sans",verdana,arial,sans-serif;
line-height: 135%;
font-size: 125%;
width:750px;
margin-left:auto;
margin-right:auto;
text-align:justify;
text-justify:inter-word;
}
div.output_subarea.output_text.output_pyout {
overflow-x: auto;
overflow-y: scroll;
max-height: 300px;
}
div.output_subarea.output_stream.output_stdout.output_text {
overflow-x: auto;
overflow-y: scroll;
max-height: 300px;
}
div.output_subarea.output_html.rendered_html {
overflow-x: scroll;
max-width: 100%;
/*  overflow-y: scroll; */
/*  max-height: 300px;   */
}
code{
font-size: 78%;
}
.rendered_html code{
background-color: transparent;
white-space: inherit;
}
ul{
margin: 2em;
}
ul li{
margin-bottom: 0.5em;
margin-top: 0.5em;
}
ul li li{
margin-bottom: 0.2em;
margin-top: 0.2em;
}
ol{
margin: 2em;
}
ol li{
margin-bottom: 0.5em;
margin-top: 0.5em;
}
/*.prompt{
display: None;
} */
ul li{
margin-bottom: 0.5em;
margin-top: 0.2em;
}
font-weight: bold;
}
a:visited{
font-weight: bold;
color: #1d3b84;
}
a:hover{
font-weight: bold;
color: #1d3b84;
}
a:focus{
font-weight: bold;
}
a:active{
font-weight: bold;
}
text-decoration: none;
}
.rendered_html :hover {
text-decoration: none;
}
.rendered_html :visited {
text-decoration: none;
}
.rendered_html :focus {
text-decoration: none;
}
.rendered_html :active {
text-decoration: none;
}
.warning{
color: rgb( 240, 20, 20 )
}
hr {
color: #f3f3f3;
background-color: #f3f3f3;
height: 1px;
}
blockquote{
display:block;
background: #f3f3f3;
font-family: "Open sans",verdana,arial,sans-serif;
width:610px;
padding: 15px 15px 15px 15px;
text-align:justify;
text-justify:inter-word;
}
blockquote p {
margin-bottom: 0;
line-height: 125%;
font-size: 100%;
text-align: center;
}
/* element.style {
} */

MathJax.Hub.Config({
TeX: {
extensions: ["AMSmath.js"]
},
tex2jax: {
inlineMath: [ ["$","$"], ["\$","\$"] ],
displayMath: [ ["$$","$$"], ["\$","\$"] ]
},
displayAlign: "center", // Change this to "center" to center equations.
"HTML-CSS": {
styles: {".MathJax_Display": {"margin": 4}}
}
});