Jump to content

File:Inverse gaussian as stopping time of random walk.png

Page contents not supported in other languages.
This is a file from the Wikimedia Commons
From Wikipedia, the free encyclopedia

Original file (1,200 × 1,200 pixels, file size: 290 KB, MIME type: image/png)

Summary

Description
English: ```python

import numpy as np import matplotlib.pyplot as plt

  1. Parameters

N = 10000 # Number of simulations mu = 0.1 threshold = 1.0 sigma = 0.2 dt = 0.01 max_wait = 40

  1. Plotting

fig, axes = plt.subplots(2, 1, figsize=(12, 12))

  1. Subplot 1: Trajectories

ax = axes[1] ax.plot([0, max_wait], [1, 1], 'r--') waiting_times = [] for _ in range(N):

   X = 0
   t = 0
   X_values = [X]
   t_values = [t]
   while X < threshold and t < max_wait:
       X += mu * dt + sigma * np.random.normal(0, np.sqrt(dt))
       t += dt
       X_values.append(X)
       t_values.append(t)
   if t < max_wait:
     waiting_times.append(t)
     ax.plot(t_values, X_values, alpha=20/N, c='b')

ax.set_xlim(0, max_wait) ax.set_ylim(-1, threshold + 0.02) ax.set_xlabel('Time') ax.set_ylabel('X') ax.set_title(rf'Brownian motion with drift. (N={N}, $\mu$={mu}, $\sigma$={sigma})')

  1. Subplot 2: Histogram

ax = axes[0] ax.hist(waiting_times, bins=100, density=True) ax.set_xlabel('Waiting Time') ax.set_ylabel('Frequency') ax.set_title('Waiting time distribution')

def f(x, mu, lambda_):

 return np.sqrt(lambda_ / (2 * np.pi * x**3)) * np.exp(-(lambda_ * (x - mu)**2) / (2 * mu**2 * x))

x = np.linspace(0.1, 40, 400) y = f(x, threshold / mu, (threshold / sigma)**2) ax.plot(x, y, 'r--')

plt.tight_layout() plt.savefig("inverse_gaussian.png") plt.show()

```
Date
Source Own work
Author Cosmia Nebula

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
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

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

28 June 2024

image/png

File history

Click on a date/time to view the file as it appeared at that time.

Date/TimeThumbnailDimensionsUserComment
current18:56, 28 June 2024Thumbnail for version as of 18:56, 28 June 20241,200 × 1,200 (290 KB)Cosmia NebulaUploaded while editing "Inverse Gaussian distribution" on en.wikipedia.org

The following page uses this file:

Metadata