In [123]:
%pylab inline
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']
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'])
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'])
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]:
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]:
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)
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]: