Module contents¶
This module simulates branching Brownian motions and includes a variety of functionalities:
Simulate the Motion: Create simulations of branching Brownian motions.
Plot Paths: Plot the paths of the motion and save them in JPEG and PNG formats.
Export Data: Export the sample paths to CSV files for further analysis.
Generate Animation: Create an animation of the branching Brownian motion process.
Credits:
Author: Le Chen
Contact: chenle02@gmail.com / le.chen@auburn.edu
Creation Date: Created at Tue 23 Jan 2024 04:50:37 PM CST
Acknowledgments: Special thanks to Yimin Zhong (yzz0225@auburn.edu) and Panqiu Xia (pqxia@auburn.edu) for their helpful discussions.
- class super_bm_simulation.Branching_BM(num_steps=301, update_steps=100, branching_prob=0.5, scale=10, seed=42)¶
Bases:
objectInitialize the Super Brownian Motion simulation with given parameters.
- Parameters:
num_steps (int) – Number of steps in the simulation. Default is 301.
update_steps (int) – Number of steps between each update. Default is 100.
branching_prob (float) – Probability of branching at each step. Default is 0.5.
scale (float) – Scale factor for the motion. Default is 10.
seed (int) – Seed for random number generation. Default is 42.
- Animation(dpi=150)¶
Generate an animation of the branching Brownian motion.
This method creates an animation of the branching Brownian motion, visualizing the paths over time. The animation is saved as a GIF file with the specified DPI (dots per inch).
- Parameters:
dpi (int, optional) – The DPI (dots per inch) for the animation. Default is 150.
- Returns:
None
- Branch_or_Die(path_id, step)¶
Update the specified path based on the branching and dying logic.
This method applies the branching and dying logic to the path identified by path_id at the given simulation step. It determines whether the path should branch, continue, or die.
- Parameters:
path_id – The identifier of the path to be updated.
step – The current step in the simulation process.
- Returns:
A boolean value; True if the path is still alive after this step, False if it has died.
- One_Step(path_id, step)¶
Update the position for a given path for one step.
- Parameters:
path_id (int) – The ID of the path to update.
step (int) – The current step in the simulation.
This method updates the position of a specific path after one step of the simulation based on a random normal increment.
- Returns:
None
- export_paths()¶
Export sample paths to a CSV file.
This method exports the sample paths of Brownian motion with branching to a CSV file. Each row in the CSV file represents a time step, and each column represents a different path.
- Returns:
None
- plot_paths()¶
Plot sample paths of Brownian motion.
This method creates a plot of sample paths for Brownian motion with branching. It visualizes the paths over time, sets plot limits, labels, and saves the plot as image files in JPEG and PNG formats.
- Returns:
None
- simulate()¶
Run a simulation of the super Brownian motion.
This method simulates the Brownian motion process with branching for a specified number of steps. It iterates through each step and each path, updating the paths based on branching conditions and random steps.
- Returns:
None
- super_bm_simulation.main()¶
Run the simulation of branching Brownian motion.
This script simulates branching Brownian motion with customizable parameters using command-line arguments.
Command Line Options:
- -s, --seed INT
Random seed (use -1 for a random seed based on current time)
- -n, --num-steps INT
Maximum number of steps in the simulation
- -u, --update-steps INT
Number of steps between each branching event
-p, –branching-prob FLOAT Probability of branching at each step
- -c, --scale FLOAT
Scale of the Brownian motion
- -d, --dpi INT
The dpi parameter for the animation
- -a, --save-animation
Save the animation as a GIF
Example Usage:
` python super_bm_simulation.py -s 42 -n 301 -u 100 -p 0.5 -c 10.0 -d 150 -a `