Last active
May 15, 2019 11:59
-
-
Save grey-area/f2d29431e747a264c438f450e37bf027 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.special import gamma | |
trials = 200 | |
steps = 1000 | |
xs = np.arange(steps) | |
ds = [1, 10, 100] | |
fig, axes = plt.subplots(1, 3, sharey=True) | |
for d, ax in zip(ds, axes): | |
ys = np.cumsum(np.random.normal(size=(trials, steps, d)), axis=1) | |
dists = np.sqrt(np.sum(ys**2, axis=-1)) | |
mean = np.sqrt(2 * xs) * gamma((d + 1) / 2) / gamma(d / 2) | |
ax.plot(xs, dists.T, c='k', alpha=0.02) | |
ax.plot(xs, mean, c='r') | |
ax.set_xlabel('Time') | |
ax.set_ylabel('Distance from origin') | |
ax.set_title(f'{d} dimensions') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment