def quantiles(fit): tab = fit.load_mnest_results() pars = tab.colnames weights = tab['weights'] sumweights = np.sum(weights) weights = weights / sumweights sig1 = 0.682689 sig2 = 0.9545 sig3 = 0.9973 sig1_lo = (1. - sig1) / 2. sig2_lo = (1. - sig2) / 2. sig3_lo = (1. - sig3) / 2. sig1_hi = 1. - sig1_lo sig2_hi = 1. - sig2_lo sig3_hi = 1. - sig3_lo # Calculate the median and quantiles. med_vals = {} for n in pars: # Calculate median, 1 sigma lo, and 1 sigma hi credible interval. med_vals[n] = model_fitter.weighted_quantile(tab[n], [0.5, sig1_lo, sig1_hi], sample_weight=weights) # Switch from values to errors. med_vals[n][1] = med_vals[n][0] - med_vals[n][1] med_vals[n][2] = med_vals[n][2] - med_vals[n][0] return pars, med_vals
def summarize_results(tab): if len(tab) < 1: print('Did you run multinest_utils.separate_mode_files yet?') # Which params to include in table parameters = tab.colnames parameters.remove('weights') parameters.remove('logLike') weights = tab['weights'] sumweights = np.sum(weights) weights = weights / sumweights sig1 = 0.682689 sig2 = 0.9545 sig3 = 0.9973 sig1_lo = (1.-sig1)/2. sig2_lo = (1.-sig2)/2. sig3_lo = (1.-sig3)/2. sig1_hi = 1.-sig1_lo sig2_hi = 1.-sig2_lo sig3_hi = 1.-sig3_lo print(sig1_lo, sig1_hi) # Calculate the median, best-fit, and quantiles. best_idx = np.argmax(tab['logLike']) best = tab[best_idx] best_errors = {} med_best = {} med_errors = {} for n in parameters: # Calculate median, 1 sigma lo, and 1 sigma hi credible interval. tmp = model_fitter.weighted_quantile(tab[n], [0.5, sig1_lo, sig1_hi], sample_weight=weights) # Switch from values to errors. err_lo = tmp[0] - tmp[1] err_hi = tmp[2] - tmp[0] # Store into dictionaries. med_best[n] = tmp[0] med_errors[n] = np.array([err_lo, err_hi]) #best_errors[n] = np.array([best[n] - tmp[1], tmp[2] - best[n]]) best_errors[n] = np.array([tmp[1], tmp[2]]) print('####################') print('Best-Fit Solution:') print('####################') fmt = ' {0:15s} best = {1:10.3f} 68\% low = {2:10.3f} 68% hi = {3:10.3f}' for n in parameters: print(fmt.format(n, best[n], best_errors[n][0], best_errors[n][1])) return
def table_phot_astrom(): """ I was in a rush and didn't have time to make a proper table, so this just prints out the values, and you manually type it into LaTeX itself. """ ##### # Comment out the target you aren't working on ##### target = 'MB10364' target_name = 'mb10364' # target='OB110462' # target_name='ob110462' mod_fit, data = lu_2019_lens.get_data_and_fitter(tdir[target_name]) mod_all = mod_fit.get_best_fit_modes_model(def_best='maxL') mod = mod_all[0] tab = mod_fit.load_mnest_results() tab['piE'] = np.hypot(tab['piE_E'], tab['piE_N']) tab['muRel'] = np.hypot(tab['muRel_E'], tab['muRel_N']) tab_best = {} tab_maxl = {} med_errors = {} sumweights = np.sum(tab['weights']) weights = tab['weights'] / sumweights sig1 = 0.682689 sig2 = 0.9545 sig3 = 0.9973 sig1_lo = (1. - sig1) / 2. sig2_lo = (1. - sig2) / 2. sig3_lo = (1. - sig3) / 2. sig1_hi = 1. - sig1_lo sig2_hi = 1. - sig2_lo sig3_hi = 1. - sig3_lo ##### # Comment out the target you aren't working on ##### # For MB10364 params = ['tE', 'thetaE', 'piE', 'muRel', 'mL', 'mag_src2', 'piL'] # For OB110462 # params = ['tE', 'thetaE', 'piE', 'muRel', 'mL', 'mag_src3', 'piL'] maxl_idx = tab['logLike'].argmax() for n in params: tab_maxl[n] = tab[n][maxl_idx] # Calculate median, 1 sigma lo, and 1 sigma hi credible interval. tmp = model_fitter.weighted_quantile(tab[n], [0.5, sig1_lo, sig1_hi], sample_weight=weights) tab_best[n] = tmp[0] # Switch from values to errors. # err_lo = tmp[0] - tmp[1] # err_hi = tmp[2] - tmp[0] # med_errors[n] = np.array([err_lo, err_hi]) err_lo = tab_maxl[n] - tmp[1] err_hi = tmp[2] - tab_maxl[n] med_errors[n] = np.array([err_lo, err_hi]) print(tab_maxl) print(med_errors) return