File:Donsker theorem for normal distributions.gif

Size of this preview: 800 × 240 pixels. Other resolution: 640 × 192 pixels.
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.
Summary
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
I, the copyright holder of this work, hereby publish it under the following license:



This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
- 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.
Captions
Donsker-Skorokhod-Kolmogorov theorem for normal distributions
depicts<\/a>"}},"text\/plain":{"en":{"":"depicts"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":3527064,\"id\":\"Q3527064\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P180":"Donsker's theorem<\/a>"}},"text\/plain":{"en":{"P180":"Donsker's theorem"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":178036,\"id\":\"Q178036\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P180":"Brownian motion<\/a>"}},"text\/plain":{"en":{"P180":"Brownian motion"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":628309,\"id\":\"Q628309\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P180":"Brownian bridge<\/a>"}},"text\/plain":{"en":{"P180":"Brownian bridge"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":386228,\"id\":\"Q386228\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P180":"distribution function<\/a>"}},"text\/plain":{"en":{"P180":"distribution function"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":1339385,\"id\":\"Q1339385\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P180":"empirical distribution function<\/a>"}},"text\/plain":{"en":{"P180":"empirical distribution function"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P180 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
Items portrayed in this file
depicts
Donsker's theorem
Brownian motion
Brownian bridge
distribution function
empirical distribution function
creator
some value
author name string: Cosmia Nebula
Wikimedia username: Cosmia Nebula
copyright status<\/a>"}},"text\/plain":{"en":{"":"copyright status"}}},"{\"value\":{\"entity-type\":\"item\",\"numeric-id\":50423863,\"id\":\"Q50423863\"},\"type\":\"wikibase-entityid\"}":{"text\/html":{"en":{"P6216":"copyrighted<\/a>"}},"text\/plain":{"en":{"P6216":"copyrighted"}}}}" class="wbmi-entityview-statementsGroup wbmi-entityview-statementsGroup-P6216 oo-ui-layout oo-ui-panelLayout oo-ui-panelLayout-framed">
copyright status
copyrighted
copyright license
Creative Commons Attribution-ShareAlike 4.0 International
source of file
original creation by uploader
inception
3 March 2023
media type
image/gif
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 | Uploaded own work with UploadWizard |
File usage
The following 2 pages use this file: