bjet_mcmc.blazar_run_mcmc module
Program Purpose: Implement the mcmc. Run the file to run the MCMC as a script using a parameter file.
Parameters are always listed in the following order: [delta, K, n1, n2, gamma_min, gamma_max, gamma_break, B, R]
All parameters are the logarithm of the true value except for delta, n1, and n2
Parameter |
Description |
Scale |
|---|---|---|
delta |
doppler factor |
linear |
K |
particle density [cm^-3] |
log |
n1 |
n_1 (first index) |
linear |
n2 |
n_2 (second index) |
linear |
gamma_min |
low-energy cutoff |
log |
gamma_max |
high-energy cutoff |
log |
gamma_break |
energy break |
log |
B |
magnetic field strength [G] |
log |
R |
blob radius (cm) |
log |
- bjet_mcmc.blazar_run_mcmc.mcmc(config_file=None, directory=None, folder_label=None, p0=None, p0_label=None, p0_file=None, eic_p0_from_std=False, description=None, prev_files=False, use_param_file=False)
The MCMC function that will run just given a configuration file–this is the function called by the main method.
- Parameters:
config_file (str) – Absolute path to configuration file; default is None; if none, it will be set to “mcmc_config.txt”
directory (str) – Location for results; default is none; if none, it will be in <RESULTS_FOLDER>/run_YYYY-mm-dd-hh:mm:ss. This will be set with configs if possible.
folder_label (str) – If directory is None and folder_label is not None, results will be saved in a folder named <folder_label>_YYYY-mm-dd-hh:mm:ss
p0 (list or None) – numpy arr of floats, n_walkers x NUM_DIM). Initial positions of the walkers; default is None; if none, random positions will be used. Usually only set this if continuing a run from a past MCMC run.
p0_label (str) – The label for the initial parameter values.
p0_file (str or None) – Label describing where the p0 values came from; default is none; if none, the label will be “random”
eic_p0_from_std (bool) – A flag indicating whether to use EIC p0 values from standard deviations.
description (str or None) – A description of the MCMC analysis.
prev_files (bool) – A flag indicating whether to use previous files.
use_param_file (bool) – A flag indicating whether to use a parameter file.
- Returns:
The MCMC sampler and the directory where the results are saved.
- Return type:
- bjet_mcmc.blazar_run_mcmc.run_mcmc(configs, param_min_vals=None, param_max_vals=None, backend_file='local_results/backend.h5', p0=None, p0_file=None, eic_p0_from_std=False, min_freq=None, max_freq=None, prev_files=False, use_param_file=True, eic=False)
This function runs an MCMC simulation using the emcee package.
Config dictionary keys and values: Keys are strings, value format is mixed
Key (str)
Value
data_file
(str) relative path to data
n_steps
(int) number of num to run
n_walkers
(int) number of walkers
discard
(int) how many num are discarded before analysis
parallel
(bool) whether parallel processing will be used
cores
(int) NOT PRESENT IF PARALLEL IS FALSE; # of cores if absent and parallel TRUE, (# cores on machine - 1) used
tau_variability
(float) time in hours for variability constraint
- Parameters:
configs (dict) – keys are strings, value types are mixed Configurations usually obtained with read_configs. See below for necessary dictionary elements.
param_min_vals (numpy array, optional) – A numpy array (NUM_DIM,) of the minimum values for each parameter. If None, default values will be used.
param_max_vals (numpy array, optional) – A numpy array (NUM_DIM,) of the maximum values for each parameter. If None, default values will be used.
backend_file (str, optional) – The file name of the backend HDF5 file. Default is ‘backend.h5’.
p0 (numpy array, optional) – 2D np array of floats, shape (n_walkers, NUM_DIM) initial locations. Default is none; then, random start parameters will be used. Usually only specify this if you would like to continue a previous run from the last state of a chain. The starting positions for the walkers. If None, random positions will be generated. If eic_p0_from_std is True, these positions will be used to generate the starting positions. Otherwise, if p0_file is provided, positions from this file will be used. If p0 is provided, these positions will be used. Else, random positions will be generated based on the parameter limits.
p0_file (str, optional) – The file name of the HDF5 file containing the starting positions for the walkers. If provided, the positions from this file will be used. If not, random positions will be generated.
eic_p0_from_std (bool, optional) – If True, starting positions will be generated based on the standard deviation of the parameters specified in p0_file. This option is only valid for EIC mode. Default is False.
min_freq (float, optional) – The minimum frequency to be considered in the blazar SED model. If None, the minimum frequency in the data file will be used.
max_freq (float, optional) – The maximum frequency to be considered in the blazar SED model. If None, the maximum frequency in the data file will be used.
prev_files (bool, optional) – If True, previous output files will be read and used as additional data points. Default is False.
use_param_file (bool, optional) – If True, the param_file will be used to store the walker positions. Default is True.
eic (bool, optional) – If True, the model will be run in EIC mode. Otherwise, non-EIC mode will be used. Default is False.
- Returns:
The sampler object containing information about the MCMC run, and the duration of the run as a string (string of how long the MCMC took in hh:mm:ss.ssssss).
- Return type:
tuple(emcee.EnsembleSampler, time)