File:Donsker theorem for normal distributions.gif
Original file (2,000 × 600 pixels, file size: 4.5 MB, MIME type: image/gif, looped, 132 frames, 11 s)
Note: Due to technical limitations, thumbnails of high resolution GIF images such as this one will not be animated. The limit on Wikimedia Commons is width × height × number of frames ≤ 100 million.
Captions
Summary
[edit]DescriptionDonsker theorem for normal distributions.gif |
English: ```python
import numpy as np import matplotlib.pyplot as plt import scipy import tempfile import os import imageio
def plot_bridge(samples=None, n=1000, dist=scipy.stats.norm, dist_name="normal", low=-3, high=+3): fig, axes = plt.subplot_mosaic("ABB", figsize=(20, 6)) ax1 = axes["A"] ax2 = axes["B"] if samples is None: samples = dist.rvs(size=n) else: n = len(samples) x = sorted(samples) y = dist.cdf(x) ref_x = np.linspace(low,high, 1000) ref_y = dist.cdf(ref_x) # calculate empirical cdf ecdf = np.arange(n) / len(samples) # plot cdf of standard normal distribution and empirical cdf of samples ax1.plot(ref_x, ref_y, label='Standard CDF') ax1.plot(x, ecdf, label='Empirical CDF') ax1.set_title() ax1.set_xlim(low,high) ax1.legend() ax1.set_ylim(0,1) ax2.plot([0.0] + dist.cdf(x) .tolist() + [1.0], [0.0] + (np.sqrt(n) * (ecdf - dist.cdf(x))).tolist() + [0.0]) ax2.set_title('centered, scaled, and re-timed') ax2.set_ylim(-0.9, 0.9) fig.suptitle(f"{dist_name}, with n = {n}") return fig def interpolate_counts(counts, frames_per_step): interpolated_counts = [counts[0]] for i in range(1,len(counts)): interval = (counts[i] - counts[i-1]) // i interpolated_counts += list(range(counts[i-1], counts[i], interval)) return interpolated_counts + [counts[-1]] with tempfile.TemporaryDirectory() as temp_dir: dist = scipy.stats.norm dist_name = "normal" low, high = -3.5, +3.5 n_steps = 16 frames_per_step = 10 sample_counts = interpolate_counts([2**n for n in range(n_steps)], frames_per_step) n_frames = len(sample_counts)-1 samples = dist.rvs(size=sample_counts[0]).tolist() for i in range(n_frames): samples += dist.rvs(size=sample_counts[i+1]-sample_counts[i]).tolist() fig = plot_bridge(samples, dist=dist, dist_name=dist_name, low=low,high=high) filename = os.path.join(temp_dir, f"plot_{i:03d}.png") fig.savefig(filename) plt.close(fig) # Compile images into GIF fps = 12 images = [] for i in range(n_frames): filename = os.path.join(temp_dir, f"plot_{i:03d}.png") images.append(imageio.imread(filename)) imageio.mimsave(f"{dist_name} Donsker theorem.gif", images, duration=1/fps)``` |
Date | |
Source | Own work |
Author | Cosmia Nebula |
Licensing
[edit]- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 06:09, 4 March 2023 | 2,000 × 600 (4.5 MB) | Cosmia Nebula (talk | contribs) | Uploaded own work with UploadWizard |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on en.wikipedia.org