def evidence_for_3770(): nSamples = 2000 model_keys = ['XsL', 'XsXs'] channels = [0, 1, 2, 3] directory_labels = [ 'small_box_log_flat_nr', 'mid_box_log_flat_nr', 'large_box_log_flat_nr', 'small_box_flat_nr', 'mid_box_flat_nr', 'large_box_flat_nr', 'delta_nr', 'gaussian_nr' ] model_dict = {} for key in model_keys: for directory_label in directory_labels: m_key = f'{key}_{directory_label}' model_dict[m_key] = create_model_from_key( key, custom_name=f'{key}_{directory_label}') models = [model for key, model in model_dict.items()] GRB = PulseFitter(3770, times=(-.1, 1), datatype='tte', nSamples=nSamples, sampler=SAMPLER, priors_pulse_start=-.1, priors_pulse_end=0.6, priors_td_lo=0, priors_td_hi=0.5) GRB.offsets = [0, 4000, 8000, -3000] for model in models: GRB.get_residuals(channels=[0, 1, 2, 3], model=model) GRB.lens_calc(channels=[0, 1, 2, 3], model=model) GRB.get_evidence_from_models(model_dict)
def run_gaussian_priors(indices, model_keys, channels, nSamples, n_per_split, test): directory_label = 'gaussian_nr' if not test: GRB_wrap = PulseFitter(3770, times=(-.1, 1), datatype='tte', nSamples=nSamples, sampler=SAMPLER, priors_pulse_start=-.1, priors_pulse_end=0.6, priors_td_lo=0, priors_td_hi=0.5, directory_label=directory_label) GRB_wrap.offsets = [0, 4000, 8000, -3000] else: print('Currently running Gaussian priors') model_dict = {} for key in model_keys: model_dict[key] = create_model_from_key( key, custom_name=f'{key}_{directory_label}') models = [model for key, model in model_dict.items()] for mm, model in enumerate(models): if not test: GRB_wrap._setup_labels(model) overwrite_priors = dict() for n in range(1, GRB_wrap.num_pulses + 1): overwrite_priors[f'gamma_{n}_a'] = bilbyGaussian( mu=0.7, sigma=2.5, latex_label=f'$\\gamma$ {n} a') overwrite_priors[f'gamma_{n}_b'] = bilbyGaussian( mu=0.3, sigma=0.4, latex_label=f'$\\gamma$ {n} b') overwrite_priors[f'gamma_{n}_c'] = bilbyGaussian( mu=0.38, sigma=0.3, latex_label=f'$\\gamma$ {n} c') overwrite_priors[f'gamma_{n}_d'] = bilbyGaussian( mu=0.5, sigma=5, latex_label=f'$\\gamma$ {n} d') overwrite_priors[f'nu_{n}_a'] = bilbyGaussian( mu=2, sigma=2, latex_label=f'$\\nu$ {n} a') overwrite_priors[f'nu_{n}_b'] = bilbyGaussian( mu=3.3, sigma=1.2, latex_label=f'$\\nu$ {n} b') overwrite_priors[f'nu_{n}_c'] = bilbyGaussian( mu=2.74, sigma=0.8, latex_label=f'$\\nu$ {n} c') overwrite_priors[f'nu_{n}_d'] = bilbyGaussian( mu=2.7, sigma=5, latex_label=f'$\\nu$ {n} d') GRB_wrap.overwrite_priors = overwrite_priors loop_idx = np.arange(4 * mm, 4 * (mm + 1)) if test: print(indices) print(mm) print('loop_idx = ', loop_idx) indx = np.intersect1d(indices, loop_idx) % 4 if not test: GRB_wrap._split_array_job_to_4_channels(models=[model], indices=indx, channels=channels) else: print('index passed = ', indx)
def main_two_pulse_models(): """ These are the most relevant models to the analysis of GRB 950830. """ lens_keys = ['FL', 'FsL', 'XL', 'XsL'] null_keys = ['FF', 'FsFs', 'XX', 'XsXs'] keys = lens_keys + null_keys model_dict = {} for key in keys: model_dict[key] = create_model_from_key(key) return model_dict
def test_parameter_recovery(self): model_dict = {} for key in self.keys: model_dict[key] = create_model_from_key(key) models = [model for key, model in model_dict.items()] for model in models: self.discsc_fit.main_multi_channel(channels=[0, 1, 2, 3], model=model) lens_bounds = [(0.37, 0.42), (0.60, 1.8)] # lens calc doesnt work because it is trying to multiply together 4 posteriors # WHICH DO NOT OVERLAP # they do now 3770 is being tested self.discsc_fit.lens_calc(model=model, lens_bounds=lens_bounds) self.discsc_fit.get_evidence_from_models(model_dict=model_dict) shutil.rmtree('test_products/3770_model_comparison_201')
def evidence_for_973(): num_samples = [2000] for samples in num_samples: GRB = load_973(sampler=SAMPLER, nSamples=samples) keys = ['FL', 'FF'] model_dict = {} for key in keys: model_dict[key] = create_model_from_key(key) models = [model for key, model in model_dict.items()] for model in models: GRB.main_multi_channel(channels = [0, 1, 2, 3], model = model) lens_bounds = [(21, 22.6), (0.25, 0.55)] GRB.lens_calc(model = model, lens_bounds = lens_bounds) GRB.get_evidence_from_models(model_dict = model_dict)
def run_delta_priors(indices, model_keys, channels, nSamples, n_per_split, test): directory_label = 'delta_nr' if not test: GRB_wrap = PulseFitter(3770, times=(-.1, 1), datatype='tte', nSamples=nSamples, sampler=SAMPLER, priors_pulse_start=-.1, priors_pulse_end=0.6, priors_td_lo=0, priors_td_hi=0.5, directory_label=directory_label) GRB_wrap.offsets = [0, 4000, 8000, -3000] else: print('Currently running delta function priors') model_dict = {} for key in model_keys: model_dict[key] = create_model_from_key( key, custom_name=f'{key}_{directory_label}') models = [model for key, model in model_dict.items()] for mm, model in enumerate(models): if not test: GRB_wrap._setup_labels(model) overwrite_priors = dict() for n in range(1, GRB_wrap.num_pulses + 1): for k in ['a', 'b', 'c', 'd']: overwrite_priors[f'gamma_{n}_{k}'] = bilbyDeltaFunction( 1, latex_label=f'$\\gamma$ {n} {k}') overwrite_priors[f'nu_{n}_{k}'] = bilbyDeltaFunction( 1, latex_label=f'$\\nu$ {n} {k}') GRB_wrap.overwrite_priors = overwrite_priors loop_idx = np.arange(4 * mm, 4 * (mm + 1)) if test: print(indices) print(mm) print('loop_idx = ', loop_idx) indx = np.intersect1d(indices, loop_idx) % 4 if not test: GRB_wrap._split_array_job_to_4_channels(models=[model], indices=indx, channels=channels) else: print('index passed = ', indx)
def evidence_for_3770(): num_samples = [500] for samples in num_samples: GRB = load_3770(sampler=SAMPLER, nSamples=samples) GRB.offsets = [0, 4000, 8000, -3000] keys = ['FL', 'FF'] model_dict = {} for key in keys: model_dict[key] = create_model_from_key(key) models = [model for key, model in model_dict.items()] for model in models: GRB.main_multi_channel(channels=[0, 1, 2, 3], model=model) lens_bounds = [(0.37, 0.42), (0.60, 1.8)] GRB.lens_calc(model=model, lens_bounds=lens_bounds) GRB.get_evidence_from_models(model_dict=model_dict)
def test_parameter_recovery(self): model = create_model_from_key(self.key) self.discsc_fit.main_1_channel(channel=1, model=model) result_label = f'{self.discsc_fit.fstring}{self.discsc_fit.clabels[1]}' open_result = f'{self.discsc_fit.outdir}/{result_label}_result.json' result = bilby.result.read_in_result(filename=open_result) prior_shell = MakePriors(priors_pulse_start=self.priors_pulse_start, priors_pulse_end=self.priors_pulse_end, channel=1, **model) priors = prior_shell.return_prior_dict() posteriors = dict() for parameter in priors: posteriors[parameter] = np.median( result.posterior[parameter].values) for parameter in priors: assert ((abs(posteriors[parameter] - self.parameters[parameter])) / self.parameters[parameter]) < 0.1
def run_flat_priors(indices, model_keys, channels, nSamples, n_per_split, test): directory_labels = [ 'small_box_flat_nr', 'mid_box_flat_nr', 'large_box_flat_nr' ] prior_sets = [ { 'priors_gamma_min': 1e-1, ## generic 'priors_gamma_max': 1e1, 'priors_nu_min': 1e-1, 'priors_nu_max': 1e1 }, { 'priors_gamma_min': 1e-2, 'priors_gamma_max': 1e2, 'priors_nu_min': 1e-2, 'priors_nu_max': 1e2 }, { 'priors_gamma_min': 1e-3, 'priors_gamma_max': 1e3, 'priors_nu_min': 1e-3, 'priors_nu_max': 1e3 } ] for ii, prior_set in enumerate(prior_sets): if not test: GRB_wrap = PulseFitter(3770, times=(-.1, 1), datatype='tte', nSamples=nSamples, sampler=SAMPLER, priors_pulse_start=-.1, priors_pulse_end=0.6, priors_td_lo=0, priors_td_hi=0.5, directory_label=directory_labels[ii]) GRB_wrap.offsets = [0, 4000, 8000, -3000] else: print('Currently running flat priors') model_dict = {} for key in model_keys: model_dict[key] = create_model_from_key( key, custom_name=f'{key}_{directory_labels[ii]}') models = [model for key, model in model_dict.items()] for mm, model in enumerate(models): if not test: GRB_wrap._setup_labels(model) overwrite_priors = dict() for n in range(1, GRB_wrap.num_pulses + 1): for k in ['a', 'b', 'c', 'd']: overwrite_priors[f'gamma_{n}_{k}'] = bilbyUniform( minimum=prior_set['priors_gamma_min'], maximum=prior_set['priors_gamma_max'], latex_label=f'$\\gamma_{n} {k}$', unit=' ') overwrite_priors[f'nu_{n}_{k}'] = bilbyUniform( minimum=prior_set['priors_nu_min'], maximum=prior_set['priors_nu_max'], latex_label=f'$\\nu_{n} {k}$', unit=' ') GRB_wrap.overwrite_priors = overwrite_priors loop_idx = np.arange(8 * ii + 4 * mm, 8 * ii + 4 * (mm + 1)) if test: print(indices) print(ii, mm) print('loop_idx = ', loop_idx) indx = np.intersect1d(indices, loop_idx) % 4 if not test: GRB_wrap._split_array_job_to_4_channels(models=[model], indices=indx, channels=channels) else: print('index passed = ', indx)
def run_log_flat_priors(indices, model_keys, channels, nSamples, n_per_split, test): directory_labels = [ 'small_box_log_flat_nr', 'mid_box_log_flat_nr', 'large_box_log_flat_nr' ] prior_sets = [ { 'priors_gamma_min': 1e-1, ## generic 'priors_gamma_max': 1e1, 'priors_nu_min': 1e-1, 'priors_nu_max': 1e1 }, { 'priors_gamma_min': 1e-2, 'priors_gamma_max': 1e2, 'priors_nu_min': 1e-2, 'priors_nu_max': 1e2 }, { 'priors_gamma_min': 1e-3, 'priors_gamma_max': 1e3, 'priors_nu_min': 1e-3, 'priors_nu_max': 1e3 } ] for ii, prior_set in enumerate(prior_sets): if not test: GRB_wrap = PulseFitter(3770, times=(-.1, 1), datatype='tte', nSamples=nSamples, sampler=SAMPLER, priors_pulse_start=-.1, priors_pulse_end=0.6, priors_td_lo=0, priors_td_hi=0.5, directory_label=directory_labels[ii], **prior_set) GRB_wrap.offsets = [0, 4000, 8000, -3000] else: print('Currently running log-flat priors') model_dict = {} for key in model_keys: model_dict[key] = create_model_from_key( key, custom_name=f'{key}_{directory_labels[ii]}') models = [model for key, model in model_dict.items()] indx = np.intersect1d( indices, np.arange(n_per_split * ii, n_per_split * (ii + 1))) % n_per_split ## given 2 models and 4 channels should be passed indx in [0-7] if not test: GRB_wrap._split_array_job_to_4_channels(models=models, indices=indx, channels=channels) else: print(indx)
from PyGRB.main.fitpulse import PulseFitter from PyGRB.backend.makemodels import create_model_from_key GRB = PulseFitter(7475, times = (-2, 60), datatype = 'discsc', nSamples = 200, sampler = 'nestle', priors_pulse_start = -5, priors_pulse_end = 30, p_type = 'docs', HPC = False, ) keys = ['G', 'F', 'X', 'Gs', 'Fs', 'Xs'] # the last three models will take a non-trivial time to run model_dict = {} for key in keys: model_dict[key] = create_model_from_key(key) models = [model for key, model in model_dict.items()] for model in models: GRB.main_multi_channel(channels = [0, 1, 2, 3], model = model) GRB.get_evidence_from_models(model_dict = model_dict)