Distance between bitstrings

Here we will draw the histogram of the distance between two random bitstrings.


In [1]:
import sdm as sdmlib
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
#%matplotlib inline

In [2]:
distances = []
for i in xrange(10000):
    b1 = sdmlib.Bitstring.init_random(1000)
    b2 = sdmlib.Bitstring.init_random(1000)
    distances.append(b1.distance_to(b2))

In [3]:
mu = 500
sigma = (1000**(0.5))/2.0
x = np.linspace(0, 1000, 1000)
y = mlab.normpdf(x, mu, sigma)

In [4]:
plt.hist(distances, bins=range(1001), density=True)
plt.plot(x, y, 'r', linewidth=2.0)
plt.xlim(0, 1000)
plt.show()



In [5]:
plt.hist(distances, bins=range(1001), density=True)
plt.plot(x, y, 'r', linewidth=2.0)
plt.xlim(400, 600)
plt.show()



In [ ]: