This repository contains the Python code that implements a Genetic Algorithm (GA) for the optimization of the seven parameters of the Stern & Svensson (1996) (SS96) stochastic pulse avalanche model, for the generation of simulated gamma-ray burst (GRB) light curves (LCs), developed in this paper (arXiv version).
-
Reference Paper: Long gamma-ray burst light curves as the result of a common stochastic pulse-avalanche process.
-
Corresponding Author: Lorenzo Bazzanini, University of Ferrara (
bzzlnz[at]unife[dot]it
) -
Code Contributors (in alphabetical order): G. Angora, L. Bazzanini, L. Ferro, C. Guidorzi, and A. Tsvetkova.
The light curves of long GRBs show a wide variety of morphologies, which current LC simulation models based on the internal shock paradigm still fail to fully reproduce. The reason is that, despite the recent significant advance in understanding the energetics and dynamics of long GRBs, the nature of their inner engine, how the relativist outflow is powered, and the dissipation mechanisms are still not understood. This limits our ability to properly describe and simulate those transients.
A promising way to gain insights into these topics is modeling of GRB light curves as the result of a common stochastic process. In the Burst And Transient Source Experiment (BATSE) era, a stochastic pulse avalanche model was proposed and tested by comparing ensemble-average properties of simulated and real light curves, proposed by SS96.
Using machine learning, we optimized this stochastic model's parameters by exploiting the GA's capability to thoroughly explore the parameter space. We revived this model by applying it to two independent datasets, BATSE and Swift/BAT. The average properties are successfully reproduced. Notwithstanding the different populations and passbands of both data sets, the corresponding optimal parameters are interestingly similar. In particular, for both sets the dynamics appears to be close to a critical state, which is key to reproduce the observed variety of time profiles. Our results propel the avalanche character in a critical regime as a key trait of the energy release in GRB engines, which underpins some kind of instability.
The GA has been implemented using PyGAD
(Gad 2023), a FOSS Python library containing a collection of several machine learning algorithms.
The Python code that implements the SS96 stochastic model is also contained in this repo; it was originally forked from this public repository by one of the co-authors, but has undergone significant changes.
To identify the statistically significant peaks in the LCs we have used MEPSA
(Guidorzi 2015), an algorithm aimed at identifying peaks within a uniformly sampled, background subtracted/detrended time series affected by statistical uncorrelated Gaussian noise, conceived specifically for the analysis of GRB LCs.
To run the code, it is advised to create a self-contained conda
environment with all the required libraries installed. To create the aformentioned environment (which we called pygad3
) just run the following four lines of code (or follow the instructions in the file ./conda_pygad3_env.txt
, which contains also the version of all the installed packages):
# 1. create the conda environment
conda create -n pygad3 python=3.10
# 2. activate the environment
conda activate pygad3
# 3. install all the required libraries (with the required version)
pip install numpy==1.26.4 matplotlib==3.8.3 seaborn==0.13.2 pandas==2.2.0 astropy==6.0.0 pygad==3.3.1 tqdm==4.66.2 scipy==1.12.0 cloudpickle==3.0.0 h5py==3.10.0 astroml==1.0.2.post1 scikit-learn==1.4.1.post1
# 4. install some extra utilities for VSCode
conda install ipykernel --update-deps --force-reinstall
In order to run the GA minimization procedure, the BATSE or the Swift/BAT light curves are needed. Instead, if you just want to simulate a new set of LCs (given a set of seven SS96 parameters) the code in this repository should be sufficient.
#NOTE: before running anything, you have to unzip all the nine archives in the ./lc_pulse_avalance
folder (seven swift_errs_*.txt.zip
, kde_pdf_Swift_peak_count_rates.txt.zip
, and kde_pdf_BATSE_peak_count_rates.txt.zip
). To do that, you can just run the following command:
# move to the right directory
cd ./lc_pulse_avalance
# extract all the files
tar -xzf swift_errs_1.txt.zip; tar -xzf swift_errs_2.txt.zip; tar -xzf swift_errs_3.txt.zip; tar -xzf swift_errs_4.txt.zip; tar -xzf swift_errs_5.txt.zip; tar -xzf swift_errs_6.txt.zip; tar -xzf swift_errs_7.txt.zip; tar -xzf kde_pdf_Swift_peak_count_rates.txt.zip; tar -xzf kde_pdf_BATSE_peak_count_rates.txt.zip
To generate the LCs, edit the config.ini
file (./lc_pulse_avalanche/config.ini
) by choosing the instrument (instrument = batse
or instrument = swift
, if you want to simulate BATSE or Swift LCs, respectively), the number of LCs (N_grb = XXX
), and assign the value to the seven SS96 parameters. Make sure that the variable user
is set to user='external_user'
at the beginning of both simulate_GRBs.py
and statistical_test.py
files. Then run:
# move to the right directory
cd ./lc_pulse_avalanche
# activate the conda env
conda activate pygad3
# simulate a set of LCs
python simulate_GRBs.py config.ini
The code will create a directory (./simulated_LCs
), and inside, each time you call the code it will create a directory named Year-Month-Day_Hour_Minute_Second
with all the requested simulated LCs. Moreover, a copy of the config file (config_Year-Month-Day_Hour_Minute_Second.txt
) will be created in ./simulated_LCs
for later reference.
The value of the optimized parameters (see our paper above) are:
# BATSE
mu = 1.10
mu0 = 0.91
alpha = 2.57
delta1 = -1.28
delta2 = 0.28
tau_min = 0.02
tau_max = 40.2
# Swift/BAT
mu = 1.34
mu0 = 1.16
alpha = 2.53
delta1 = -0.75
delta2 = 0.27
tau_min = 0.03
tau_max = 56.8
# move to the right directory
cd ./genetic_algorithm
# set the `user` variable (`geneticgrbs.py`, line 41; `avalanche.py`, `statistical_test.py`)
user={'bach','gravity'}
# set the `instrument` variable (`geneticgrbs.py`, line 98)
instrument={'batse','swift'}
# set the parameters of the model (`geneticgrbs.py`)
{'num_generations','N_grb','range_PARAMS', etc.}
# activate the conda env
conda activate pygad3
# run the GA
python geneticgrbs.py
If you have any question or you are interested in contributing do not hesitate to contact the authors.
Please cite the following associated paper if you use this code in your work:
@ARTICLE{2024A&A...689A.266B,
author = {{Bazzanini}, L. and {Ferro}, L. and {Guidorzi}, C. and {Angora}, G. and {Amati}, L. and {Brescia}, M. and {Bulla}, M. and {Frontera}, F. and {Maccary}, R. and {Maistrello}, M. and {Rosati}, P. and {Tsvetkova}, A.},
title = "{Long gamma-ray burst light curves as the result of a common stochastic pulse{\textendash}avalanche process}",
journal = {\aap},
keywords = {methods: statistical, gamma-ray burst: general, Astrophysics - High Energy Astrophysical Phenomena, Astrophysics - Instrumentation and Methods for Astrophysics},
year = 2024,
month = sep,
volume = {689},
eid = {A266},
pages = {A266},
doi = {10.1051/0004-6361/202450150},
archivePrefix = {arXiv},
eprint = {2403.18754},
primaryClass = {astro-ph.HE},
adsurl = {https://ui.adsabs.harvard.edu/abs/2024A&A...689A.266B},
adsnote = {Provided by the SAO/NASA Astrophysics Data System}
}