Skip to content

Commit

Permalink
Fixed likelihood, added GetDist plotting scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
mbustama authored Nov 14, 2019
1 parent 9586147 commit d32a174
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 7 deletions.
47 changes: 47 additions & 0 deletions dev-likelihood-sl/all_param_marg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Show plots inline, and load main getdist plot module and samples class
from __future__ import print_function
#%matplotlib inline
#%config InlineBackend.figure_format = 'retina'
import sys
# sys.path.insert(0,os.path.realpath(os.path.join(os.getcwd(),'..')))
import os
from getdist import plots, MCSamples
import getdist
# use this *after* importing getdist if you want to use interactive plots
# %matplotlib notebook
import matplotlib.pyplot as plt
# import IPython
import numpy as np
from global_tools import *



names = ["gamma", "log_{10}(g)", "log_{10}(M[GeV])", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]
labels = ["gamma", "log_{10}(g)", "log_{10}(M[GeV])", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]

gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu, something_1, something_2, \
something_3 = Read_Data_File(os.getcwd()+'/out/likelihood/ev.dat')

samps = np.array([gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu]).T


# names = ["gamma", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]
# labels = ["gamma", "N_a", "N_{conv}", "N_{pr}", "N_{mu}"]

# gamma, N_a, N_conv, N_pr, N_mu, something_1, something_2, \
# something_3 = Read_Data_File(os.getcwd()+'/out/likelihood/ev.dat')

# samps = np.array([gamma, N_a, N_conv, N_pr, N_mu]).T


samples = MCSamples(samples = samps, names = names, labels = labels)


plt.figure()
g = plots.get_subplot_plotter()
samples.updateSettings({'contours': [0.68, 0.90], 'fine_bins_2D': 40, 'smooth_scale_2D': 0.6})
g.settings.num_plot_contours = 3
g.triangle_plot(samples, shaded=True)
#plt.plot(-2.37, -1.80, 'X', color = 'black', markersize=14)
# g.export(os.getcwd()+'/out/plots/all_param_marg.pdf')
g.export(os.getcwd()+'/out/plots/all_param_marg.png')
44 changes: 40 additions & 4 deletions dev-likelihood-sl/full_likelihood.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import numpy as np

from libc.math cimport log
from libc.math cimport exp

# from functools import reduce

from global_tools import Write_Data_File


Expand All @@ -17,7 +20,18 @@ from global_tools import Write_Data_File
# declination_tr, RA_tr, Med_tr = \
# Read_Data_File(os.getcwd()+'/ic_data/data_track.txt')

# ll_den = 273.673 # Log(80!)
# ll_den = 228.927 # Log(58!*22!)


cdef multiply_manual(iterable):

cdef double prod = 1.0
cdef double x

for x in iterable:
prod *= x

return prod


cdef double Partial_Likelihood_Showers(int event_index, double gamma,
Expand Down Expand Up @@ -76,21 +90,43 @@ def Log_Likelihood(double gamma, double log10_g, double log10_M,
cdef double fl_sh
cdef double fl_tr
cdef double log_likelihood
# cdef double tt
cdef int i

# Showers
fl_sh = sum([Partial_Likelihood_Showers(i, gamma, log10_g, log10_M, N_a,
fl_sh = multiply_manual( \
[Partial_Likelihood_Showers(i, gamma, log10_g, log10_M, N_a,
N_conv, N_pr, N_mu, interp_astro_pdf_sh, pdf_atm_conv_sh,
pdf_atm_pr_sh, verbose=verbose) for i in range(num_ic_sh)])
# fl_sh = reduce(lambda x, y: x*y, \
# [Partial_Likelihood_Showers(i, gamma, log10_g, log10_M, N_a,
# N_conv, N_pr, N_mu, interp_astro_pdf_sh, pdf_atm_conv_sh,
# pdf_atm_pr_sh, verbose=verbose) for i in range(num_ic_sh)])
# fl_sh = np.prod([Partial_Likelihood_Showers(i, gamma, log10_g, log10_M, N_a,
# N_conv, N_pr, N_mu, interp_astro_pdf_sh, pdf_atm_conv_sh,
# pdf_atm_pr_sh, verbose=verbose) for i in range(num_ic_sh)])

# Tracks
fl_tr = sum([Partial_Likelihood_Tracks(i, gamma, log10_g, log10_M, N_a,
fl_tr = multiply_manual( \
[Partial_Likelihood_Tracks(i, gamma, log10_g, log10_M, N_a,
N_conv, N_pr, N_mu, interp_astro_pdf_tr, pdf_atm_conv_tr,
pdf_atm_pr_tr, pdf_atm_muon_tr, verbose=verbose) \
for i in range(num_ic_tr)])
# fl_tr = reduce(lambda x, y: x*y, \
# [Partial_Likelihood_Tracks(i, gamma, log10_g, log10_M, N_a,
# N_conv, N_pr, N_mu, interp_astro_pdf_tr, pdf_atm_conv_tr,
# pdf_atm_pr_tr, pdf_atm_muon_tr, verbose=verbose) \
# for i in range(num_ic_tr)])
# fl_tr = np.prod([Partial_Likelihood_Tracks(i, gamma, log10_g, log10_M, N_a,
# N_conv, N_pr, N_mu, interp_astro_pdf_tr, pdf_atm_conv_tr,
# pdf_atm_pr_tr, pdf_atm_muon_tr, verbose=verbose) \
# for i in range(num_ic_tr)])


log_likelihood = log(exp(-N_a-N_conv-N_pr-N_mu)*fl_sh*fl_tr) + 400.0 #-ll_den

log_likelihood = log(exp(-N_a-N_conv-N_pr-N_mu)*fl_sh*fl_tr)
# tt = N_a+N_conv+N_pr+N_mu-80.0
# log_likelihood = log(exp(-N_a-N_conv-N_pr-N_mu)*fl_sh*fl_tr/tt)-ll_den

return log_likelihood

Expand Down
38 changes: 38 additions & 0 deletions dev-likelihood-sl/gMmarg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Show plots inline, and load main getdist plot module and samples class
from __future__ import print_function
#%matplotlib inline
#%config InlineBackend.figure_format = 'retina'
# import sys, os
# sys.path.insert(0,os.path.realpath(os.path.join(os.getcwd(),'..')))
import os
from getdist import plots, MCSamples
import getdist
# use this *after* importing getdist if you want to use interactive plots
# %matplotlib notebook
import matplotlib.pyplot as plt
# import IPython
import numpy as np
from global_tools import *



names = ["gamma", "log_{10}(g)", "log_{10}(M[GeV])", "N_a", "N_conv", "N_pr", "N_mu"]
labels = ["gamma", "log_{10}(g)", "log_{10}(M[GeV])", "N_a", "N_conv", "N_pr", "N_mu"]

gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu, something_1, something_2, \
something_3 = Read_Data_File(os.getcwd()+'/out/likelihood/ev.dat')

samps = np.array([gamma, log10_g, log10_M, N_a, N_conv, N_pr, N_mu]).T

samples = MCSamples(samples = samps, names = names, labels = labels)


plt.figure()
g = plots.get_single_plotter()
samples.updateSettings({'contours': [0.68, 0.90], 'fine_bins_2D': 20, 'smooth_scale_2D': 0.6})
g.settings.num_plot_contours = 2
g.plot_2d(samples, 'log_{10}(M[GeV])', 'log_{10}(g)', shaded=True)
plt.plot(-1.94, -1.16, 'X', color = 'black', markersize=14)
g.export(os.getcwd()+'/out/plots/gMmarg.png')


12 changes: 9 additions & 3 deletions dev-likelihood-sl/likelihood_analysis_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ def Prior(cube, ndim, nparams):

# Expected number of astrophysical neutrinos. Uniform distribution between 0 and 80.
cube[3] = cube[3]*80
# cube[1] = cube[1]*80
# cube[3] = 10.**(cube[3]*(1.9084+3.0)-3.0)

# Expected number of conv. atm. neutrinos. Uniform distribution between 0 and 80.
cube[4] = cube[4]*80
# cube[4] = 10.**(cube[4]*(1.9084-3.0)+3.0)

# Expected number of prompt atm. neutrinos. Uniform distribution between 0 and 80.
cube[5] = cube[5]*80
cube[5] = cube[5]*1
# cube[5] = 10.**(cube[5]*(1.9084-3.0)+3.0)

# Expected number of atm. muons. Uniform distribution between 0 and 80.
cube[6] = cube[6]*80
# cube[6] = 10.**(cube[6]*(1.9084-3.0)+3.0)

return 0

Expand Down Expand Up @@ -95,14 +100,15 @@ def Log_Likelihood_MultiNest(cube, ndim, nparams):
parameters = ["gamma", "log10_g", "log10_M", "N_a", "N_conv", "N_pr", "N_mu"]
n_params = len(parameters)


# Run MultiNest
pymultinest.run(Log_Likelihood_MultiNest, Prior, n_params,
outputfiles_basename='out/likelihood/',
resume=resume, verbose=verbose, n_live_points=n_live_points,
seed=-1, evidence_tolerance=evidence_tolerance,
sampling_efficiency=0.8,
importance_nested_sampling=True, log_zero=-300.0)
importance_nested_sampling=True,
const_efficiency_mode=False)
#, log_zero=-300.0)
# const_efficiency_mode=True, sampling_efficiency=1)

json.dump(parameters, open('out/likelihood/params.json', 'w')) # Save parameter names
Expand Down

0 comments on commit d32a174

Please sign in to comment.