Last active
November 5, 2019 17:53
-
-
Save willzeng/4860df0a7b46b62803ebd3b1357292c4 to your computer and use it in GitHub Desktop.
Plotting of an example Porter-Thomas distribution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| n_qubits = 4 | |
| porter_thomas = quantum_sample_probability(n_qubits, 10_000) | |
| # theoretical Porter-Thomas distribution | |
| dim = 2**n_qubits | |
| xspace = np.linspace(0.0, 1.0, 100) | |
| yspace = dim * np.exp(-dim*xspace) | |
| # plot both empirical and theoretical calculations | |
| plt.figure(figsize=(9, 6)) | |
| plt.hist(porter_thomas, bins=50, density=True, label='Empirical Distribution') | |
| plt.plot(xspace, yspace, label='Theoretical Porter-Thomas Distribution') | |
| # plot the uniform distribution for reference | |
| plt.axvline(x=1/dim, linestyle='dotted', color='r', label='Uniform Distribution') | |
| plt.xlabel("Probability p") | |
| plt.ylabel("Probability that the random bistring occurs with probability p") | |
| plt.legend(loc='best') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment