Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlotteRosenstroem authored Sep 10, 2019
1 parent 0431b8c commit 7eca32d
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 62 deletions.
68 changes: 30 additions & 38 deletions Likelihood/Full_likelihood.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
from Prob_dist_astro import *
from Prob_dist_atm import *

ID_sh, lst_energy_sh, uncertainty_minus_sh, uncertainty_plus_sh, time_sh, declination_sh, RA_sh, Med_sh = Read_Data_File(os.getcwd()+'/'+'data_shower.txt')

ID_tr, lst_energy_tr, uncertainty_minus_tr, uncertainty_plus_tr, time_tr, declination_tr, RA_tr, Med_tr = Read_Data_File(os.getcwd()+'/'+'data_track.txt')

Initialize_All_Cross_Sections(prefix_dsdy_nu_nucleon='dsdy_ct14nn',
prefix_dsdy_nu_electron='dsdy_electron',
prefix_cs_nu_electron='cs_electron', kx=1, ky=1, k=1, s=0,
verbose=0)


def Partial_likelihood_showers(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
def Partial_likelihood_showers(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose):

pdastro_sh = Prob_dist_astro(g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,
log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
pdastro_sh = Prob_dist_astro(g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,
log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose, flag_compute_shower_rate = True, flag_compute_track_rate = False)

pdatm_conv_sh = Prob_dist_atm_conv_pr(nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,log10_energy_dep_int_min, log10_energy_dep_int_max,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = True, flag_use_atm_fluxes_pr = False, flag_apply_self_veto = True, flag_compute_shower_rate = True, flag_compute_track_rate = False)


pdatm_pr_sh = Prob_dist_atm_conv_pr(nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,log10_energy_dep_int_min, log10_energy_dep_int_max,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = False, flag_use_atm_fluxes_pr = True, flag_apply_self_veto = True, flag_compute_shower_rate = True, flag_compute_track_rate = False)
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = False, flag_use_atm_fluxes_pr = True, flag_apply_self_veto = True, flag_compute_shower_rate = True, flag_compute_track_rate = False)


pdatm_muon_sh = 0 #Probabillity distribution of atmospheric muons (showers)
Expand All @@ -35,22 +30,22 @@ def Partial_likelihood_showers(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_mi



def Partial_likelihood_tracks(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
def Partial_likelihood_tracks(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose):

pdastro_tr = Prob_dist_astro(g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,
log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
pdastro_tr = Prob_dist_astro(g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,
log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose, flag_compute_shower_rate = False, flag_compute_track_rate = True)

pdatm_conv_tr = Prob_dist_atm_conv_pr(nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,log10_energy_dep_int_min, log10_energy_dep_int_max,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = True, flag_use_atm_fluxes_pr = False, flag_apply_self_veto = True, flag_compute_shower_rate = False, flag_compute_track_rate = True)


pdatm_pr_tr = Prob_dist_atm_conv_pr(nu_energy_min, nu_energy_max, nu_energy_num_nodes, costhz_val, costhz_npts, energy_dep,log10_energy_dep_int_min, log10_energy_dep_int_max,
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = False, flag_use_atm_fluxes_pr = True, flag_apply_self_veto = True, flag_compute_shower_rate = False, flag_compute_track_rate = True)
log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose,
flag_use_atm_fluxes_conv = False, flag_use_atm_fluxes_pr = True, flag_apply_self_veto = True, flag_compute_shower_rate = False, flag_compute_track_rate = True)


pdatm_muon_tr = Prob_dist_atm_muon(energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts, epsabs, epsrel, verbose)
Expand All @@ -60,33 +55,30 @@ def Partial_likelihood_tracks(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min
return likelihood


def Full_likelihood(N_a, N_conv, N_pr, N_mu, g, M, gamma, nu_energy_min, nu_energy_max, z_min, z_max, E_min, E_max, E_npts, nu_energy_num_nodes,
costhz_npts, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose):

def Full_likelihood(N_a, N_conv, N_pr, N_mu, g, M, gamma, nu_energy_min, nu_energy_max, z_min, z_max, E_min, E_max, E_npts, nu_energy_num_nodes,
costhz_npts, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose):

ID_sh, lst_energy_sh, uncertainty_minus_sh, uncertainty_plus_sh, time_sh, declination_sh, RA_sh, Med_sh = Read_Data_File(os.getcwd()+'/'+'data_shower.txt')

ID_tr, lst_energy_tr, uncertainty_minus_tr, uncertainty_plus_tr, time_tr, declination_tr, RA_tr, Med_tr = Read_Data_File(os.getcwd()+'/'+'data_track.txt')

FL_sh = 1
for i in range(3): #len(lst_energy_sh)):
for i in range(3): #len(lst_energy_sh)):
costhz_val = np.cos((declination_sh[i] + 90)*np.pi/180)
energy_dep = lst_energy_sh[i]*1000

FL_sh = FL_sh * Partial_likelihood_showers(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
FL_sh = FL_sh * Partial_likelihood_showers(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose)


FL_tr = 1
FL_tr = 1

for i in range(3): #len(lst_energy_tr)):
for i in range(3): #len(lst_energy_tr)):
costhz_val = np.cos((declination_tr[i] + 90)*np.pi/180)
energy_dep = lst_energy_tr[i]*1000

FL_tr = FL_tr * Partial_likelihood_tracks(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
FL_tr = FL_tr * Partial_likelihood_tracks(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_val, costhz_npts, energy_dep, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose)

FL = np.exp(- N_a - N_conv - N_pr - N_mu) * FL_sh * FL_tr
Expand All @@ -97,10 +89,10 @@ def Full_likelihood(N_a, N_conv, N_pr, N_mu, g, M, gamma, nu_energy_min, nu_ener
log10_nu_energy_min = 2.8
log10_nu_energy_max = 9.2
test = Full_likelihood(20, 20, 20, 20, 0.03, 0.01, 2, nu_energy_min = 10**log10_nu_energy_min, nu_energy_max = 10**log10_nu_energy_max,
z_min = 0, z_max = 4, E_min = 3, E_max = 8, E_npts = 10, nu_energy_num_nodes = 150,
costhz_npts = 2, log10_energy_dep_int_min = 4, log10_energy_dep_int_max = 7, log10_energy_dep_min = 3.8, log10_energy_dep_max = 7.2, log10_energy_dep_npts = 50,
test = Full_likelihood(20, 20, 20, 20, 0.03, 0.01, 2, nu_energy_min = 10**log10_nu_energy_min, nu_energy_max = 10**log10_nu_energy_max,
z_min = 0, z_max = 4, E_min = 3, E_max = 8, E_npts = 10, nu_energy_num_nodes = 150,
costhz_npts = 2, log10_energy_dep_int_min = 4, log10_energy_dep_int_max = 7, log10_energy_dep_min = 3.8, log10_energy_dep_max = 7.2, log10_energy_dep_npts = 50,
time_det_yr = 8, volume_total = 6.44e14, energy_nu_max = 1e8, epsabs =1e-3, epsrel = 1e-3, verbose=1)
print(test)
"""
"""
93 changes: 93 additions & 0 deletions Likelihood/Likelihood_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import json
import numpy
from numpy import *
import scipy.stats, scipy
import pymultinest
from Full_likelihood import *


def Prior(cube, ndim, nparams):

#Spectral index. Uniform prior between 2 and 3.
cube[0] = cube[0] + 2

#Mass of mediator. Log uniform prior between 10^-5 and 10^2
cube[1] = 10**(cube[1]*7 - 5)

#Coupling constant. Log uniform prior between 10^-3 and 1.
cube[2] = 10**(cube[2]*3 -3)

#Expected number of astrophysical neutrinos. Uniform distribution between 0 and 80.
cube[3] = cube[3] * 80

#Expected number of conv. atm. neutrinos. Uniform distribution between 0 and 80.
cube[4] = cube[4] * 80

#Expected number of prompt atm. neutrinos. Uniform distribution between 0 and 80.
cube[5] = cube[5] * 80

#Expected number of atm. muons. Uniform distribution between 0 and 80.
cube[6] = cube[6] * 80

return 0


def Log_Like(cube, ndim, nparams):

gamma = cube[0]
M = cube[1]
g = cube[2]
N_a = cube[3]
N_conv = cube[4]
N_pr = cube[5]
N_mu = cube[6]

z_min = 0
z_max = 4
E_min = 3
E_max = 8
E_npts = 5 #200

log10_nu_energy_min = 2.8
log10_nu_energy_max = 9.2

nu_energy_min = 10**log10_nu_energy_min
nu_energy_max = 10**log10_nu_energy_max
nu_energy_num_nodes = 20 #150
costhz_npts = 2 #50
log10_energy_dep_int_min = 4
log10_energy_dep_int_max = 7
log10_energy_dep_min = 3.8
log10_energy_dep_max = 7.2
log10_energy_dep_npts = 10 #50
time_det_yr = 8
volume_total = 6.44e14
energy_nu_max = 1e8
epsabs = 1e-3
epsrel = 1e-3
verbose = 1

likelihood = Full_likelihood(N_a, N_conv, N_pr, N_mu, g, M, z_min, z_max, E_min, E_max, E_npts, gamma, nu_energy_min, nu_energy_max, nu_energy_num_nodes,
costhz_npts, log10_energy_dep_int_min, log10_energy_dep_int_max, log10_energy_dep_min, log10_energy_dep_max, log10_energy_dep_npts,
time_det_yr, volume_total, energy_nu_max, epsabs, epsrel, verbose)

log_l = np.log10(likelihood)
print('Log_l=',log_l)
return log_l




parameters = ["gamma", "M", "g", "N_a", "N_conv", "N_pr", "N_mu"]
n_params = len(parameters)




# Run MultiNest
pymultinest.run(Log_Like, Prior, n_params, outputfiles_basename='out/',
resume=True, verbose=True, n_live_points=100, seed=1,
evidence_tolerance=0.1, importance_nested_sampling=True)

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

17 changes: 12 additions & 5 deletions Likelihood/Likelihood_analysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
#SBATCH --job-name=likelihood # shows up in the output of 'squeue'
#SBATCH --time=4-23:59:59 # specify the requested wall-time
#SBATCH --partition=astro_long # specify the partition to run on
#SBATCH --nodes=4 # number of nodes allocated for this job
#SBATCH --nodes=1 # number of nodes allocated for this job
#SBATCH --ntasks-per-node=20 # number of MPI ranks per node
#SBATCH --cpus-per-task=1 # number of OpenMP threads per MPI rank
#SBATCH --mail-type=ALL,TIME_LIMIT_90,TIME_LIMIT,ARRAY_TASKS
#SBATCH --mail-user=vkc652@alumni.ku.dk
#SBATCH -o %A_%a.out # Standard output
#SBATCH -e %A_%a.err # Standard error
#SBATCH -o %A.out # Standard output
#SBATCH -e %A.err # Standard error
##SBATCH --exclude=<node list> # avoid nodes (e.g. --exclude=node786)


# Move to directory job was submitted from
cd $SLURM_SUBMIT_DIR

# Command to run
mpiexec -n 4 python Likelihood_analysis_parser.py --E_npts=2 --nu_energy_num_nodes=10 --costhz_npts=2 --log10_energy_dep_npts=5 --epsabs=1.e-1 --epsrel=1.e-1 --n_live_points=5 --evidence_tolerance=0.5
export LD_LIBRARY_PATH=/groups/astro/vkc652/MultiNest/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/groups/astro/vkc652/nuSQuIDS/lib/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/groups/astro/vkc652/SQuIDS/lib/

# Command to run
python -u Likelihood_analysis_parser.py --E_npts=10 --costhz_npts=3 --log10_energy_dep_npts=5 --epsabs=1.e-1 --epsrel=1.e-1 --n_live_points=5 --evidence_tolerance=5 --verbose=2

# python -u Likelihood_analysis_parser.py --E_npts=3 --nu_energy_num_nodes=10 --costhz_npts=3 --log10_energy_dep_npts=5 --epsabs=1.e-1 --epsrel=1.e-1 --n_live_points=5 --evidence_tolerance=0.5 --verbose=2

# mpiexec -n 1 python Likelihood_analysis_parser.py --E_npts=2 --nu_energy_num_nodes=10 --costhz_npts=2 --log10_energy_dep_npts=5 --epsabs=1.e-1 --epsrel=1.e-1 --n_live_points=5 --evidence_tolerance=0.5 --verbose=2


Loading

0 comments on commit 7eca32d

Please sign in to comment.