Example #1
0
def main():
    args = parse_args()
    process_args(args)
    misc_utils.print_args(args)

    if args.seed is not None:
        np.random.seed(args.seed)

    asimov_paramset, hypo_paramset = get_paramsets(args, define_nuisance())

    prefix = ''
    outfile = args.datadir + '/mc_unitary' + prefix + gen_identifier(args)
    print('== {0:<25} = {1}'.format('outfile', outfile))

    print('asimov_paramset', asimov_paramset)
    print('hypo_paramset', hypo_paramset)

    if args.run_mcmc:
        ln_prob_eval = partial(
            ln_prob,
            hypo_paramset  = hypo_paramset,
            args           = args,
        )

        if args.mcmc_seed_type == MCMCSeedType.UNIFORM:
            p0 = mcmc_utils.flat_seed(
                hypo_paramset, nwalkers=args.nwalkers
            )
        elif args.mcmc_seed_type == MCMCSeedType.GAUSSIAN:
            p0 = mcmc_utils.gaussian_seed(
                hypo_paramset, nwalkers=args.nwalkers
            )

        samples = mcmc_utils.mcmc(
            p0       = p0,
            ln_prob  = ln_prob_eval,
            ndim     = len(hypo_paramset),
            nwalkers = args.nwalkers,
            burnin   = args.burnin,
            nsteps   = args.nsteps,
            threads  = args.threads
        )

        mmxs = map(fr_utils.angles_to_u, samples)
        frs = np.array(
            [fr_utils.u_to_fr(args.source_ratio, x) for x in mmxs]
        )
        mcmc_utils.save_chains(frs, outfile)

    print("DONE!")
Example #2
0
def main():
    args = parse_args()
    process_args(args)
    misc_utils.print_args(args)

    if args.seed is not None:
        np.random.seed(args.seed)

    asimov_paramset, hypo_paramset = get_paramsets(args, define_nuisance())

    prefix = ''
    outfile = args.datadir + '/mc_x' + prefix
    print('== {0:<25} = {1}'.format('outfile', outfile))

    print('asimov_paramset', asimov_paramset)
    print('hypo_paramset', hypo_paramset)

    if args.run_mcmc:
        ln_prob_eval = partial(
            ln_prob,
            hypo_paramset=hypo_paramset,
            args=args,
        )

        if args.mcmc_seed_type == MCMCSeedType.UNIFORM:
            p0 = mcmc_utils.flat_seed(hypo_paramset, nwalkers=args.nwalkers)
        elif args.mcmc_seed_type == MCMCSeedType.GAUSSIAN:
            p0 = mcmc_utils.gaussian_seed(hypo_paramset,
                                          nwalkers=args.nwalkers)

        samples = mcmc_utils.mcmc(p0=p0,
                                  ln_prob=ln_prob_eval,
                                  ndim=len(hypo_paramset),
                                  nwalkers=args.nwalkers,
                                  burnin=args.burnin,
                                  nsteps=args.nsteps,
                                  args=args,
                                  threads=args.threads)

        nsamples = len(samples)
        srcs = [fr_utils.normalize_fr((x, 1 - x, 0)) for x in samples.T[-1]]
        mmxs = map(fr_utils.angles_to_u, samples.T[:-1].T)
        frs = np.array(
            [fr_utils.u_to_fr(srcs[i], mmxs[i]) for i in range(nsamples)],
            dtype=np.float64)
        mcmc_utils.save_chains(frs, outfile)

    print("DONE!")
Example #3
0
def main():
    args = parse_args()
    process_args(args)
    misc_utils.print_args(args)

    if args.seed is not None:
        np.random.seed(args.seed)

    asimov_paramset, llh_paramset = get_paramsets(args, define_nuisance())

    prefix = ''
    outfile = args.datadir + '/mc_texture' + prefix + gen_identifier(args)
    print('== {0:<25} = {1}'.format('outfile', outfile))

    print('asimov_paramset', asimov_paramset)
    print('llh_paramset', llh_paramset)

    if args.run_mcmc:
        ln_prob_eval = partial(
            ln_prob,
            llh_paramset=llh_paramset,
            args=args,
        )

        if args.mcmc_seed_type == MCMCSeedType.UNIFORM:
            p0 = mcmc_utils.flat_seed(llh_paramset, nwalkers=args.nwalkers)
        elif args.mcmc_seed_type == MCMCSeedType.GAUSSIAN:
            p0 = mcmc_utils.gaussian_seed(llh_paramset, nwalkers=args.nwalkers)

        samples = mcmc_utils.mcmc(p0=p0,
                                  ln_prob=ln_prob_eval,
                                  ndim=len(llh_paramset),
                                  nwalkers=args.nwalkers,
                                  burnin=args.burnin,
                                  nsteps=args.nsteps,
                                  threads=args.threads)

        frs = np.array(map(
            lambda x: fr_utils.flux_averaged_BSMu(x, args, args.spectral_index,
                                                  llh_paramset), samples),
                       dtype=float)
        frs_scale = np.vstack((frs.T, samples[:-1].T)).T
        mcmc_utils.save_chains(frs_scale, outfile)

    print("DONE!")
Example #4
0
def main():
    args = parse_args()
    process_args(args)
    misc_utils.print_args(args)

    if args.seed is not None:
        np.random.seed(args.seed)

    asimov_paramset, llh_paramset = get_paramsets(args, define_nuisance())
    outfile = args.datadir + '/{0}/{1}/chains_'.format(
        *map(misc_utils.parse_enum,
             [args.stat_method, args.data])) + misc_utils.gen_identifier(args)
    print('== {0:<25} = {1}'.format('outfile', outfile))

    if args.run_mcmc:
        gf_utils.setup_fitter(args, asimov_paramset)

        print('asimov_paramset', asimov_paramset)
        print('llh_paramset', llh_paramset)

        ln_prob = partial(llh_utils.ln_prob,
                          args=args,
                          asimov_paramset=asimov_paramset,
                          llh_paramset=llh_paramset)

        if args.mcmc_seed_type == MCMCSeedType.UNIFORM:
            p0 = mcmc_utils.flat_seed(llh_paramset, nwalkers=args.nwalkers)
        elif args.mcmc_seed_type == MCMCSeedType.GAUSSIAN:
            p0 = mcmc_utils.gaussian_seed(llh_paramset, nwalkers=args.nwalkers)

        samples = mcmc_utils.mcmc(p0=p0,
                                  ln_prob=ln_prob,
                                  ndim=len(llh_paramset),
                                  nwalkers=args.nwalkers,
                                  burnin=args.burnin,
                                  nsteps=args.nsteps,
                                  threads=args.mcmc_threads)
        mcmc_utils.save_chains(samples, outfile)

    raw = np.load(outfile + '.npy')
    raw[:, 4] *= 1E23
    raw[:, 5] *= 1E21
    ranges = list(llh_paramset.ranges)
    ranges[4] = [x * 1E23 for x in ranges[4]]
    ranges[5] = [x * 1E21 for x in ranges[5]]

    labels = [
        r'${\rm sin}^2\theta_{12}$',
        r'${\rm cos}^4\theta_{13}$',
        r'${\rm sin}^2\theta_{23}$',
        r'$\delta$',
        r'$\Delta m_{21}^2\left[10^{-5}\,{\rm eV}^2\right]$',
        r'$\Delta m_{31}^2\left[10^{-3}\,{\rm eV}^2\right]$',
        r'$N_{\rm conv}$',
        r'$N_{\rm prompt}$',
        r'$N_{\rm muon}$',
        r'$N_{\rm astro}$',
        r'$\gamma_{\rm astro}$',
        r'${\rm log}_{10}\left[\Lambda^{-1}_{'+ \
        r'{0}'.format(args.dimension)+r'}'+ \
        misc_utils.get_units(args.dimension)+r'\right]$'
    ]

    plot_utils.chainer_plot(infile=raw,
                            outfile=outfile[:5] +
                            outfile[5:].replace('data', 'plots'),
                            outformat=['pdf'],
                            args=args,
                            llh_paramset=llh_paramset,
                            labels=labels,
                            ranges=ranges)
    print("DONE!")
Example #5
0
def main():
    args = parse_args()
    process_args(args)
    misc_utils.print_args(args)

    if args.seed is not None:
        np.random.seed(args.seed)

    asimov_paramset, hypo_paramset = get_paramsets(args, define_nuisance())
    hypo_paramset.extend(asimov_paramset.from_tag(ParamTag.BESTFIT))

    prefix = ''
    outfile = args.datadir + '/contour' + prefix + gen_identifier(args)
    print('== {0:<25} = {1}'.format('outfile', outfile))

    print('asimov_paramset', asimov_paramset)
    print('hypo_paramset', hypo_paramset)

    if args.run_mcmc:
        gf_utils.setup_fitter(args, asimov_paramset)

        ln_prob_eval = partial(
            ln_prob,
            hypo_paramset  = hypo_paramset,
            args           = args,
        )

        if args.mcmc_seed_type == MCMCSeedType.UNIFORM:
            p0 = mcmc_utils.flat_seed(
                hypo_paramset, nwalkers=args.nwalkers
            )
        elif args.mcmc_seed_type == MCMCSeedType.GAUSSIAN:
            p0 = mcmc_utils.gaussian_seed(
                hypo_paramset, nwalkers=args.nwalkers
            )

        samples = mcmc_utils.mcmc(
            p0       = p0,
            ln_prob  = ln_prob_eval,
            ndim     = len(hypo_paramset),
            nwalkers = args.nwalkers,
            burnin   = args.burnin,
            nsteps   = args.nsteps,
            threads  = args.mcmc_threads
        )
        mcmc_utils.save_chains(samples, outfile)

    labels = [
        r'$N_{\rm conv}$',
        r'$N_{\rm prompt}$',
        r'$N_{\rm muon}$',
        r'$N_{\rm astro}$',
        r'$\gamma_{\rm astro}$',
        r'$\text{sin}^4\phi_\oplus$',
        r'$\text{cos}\left(2\psi_\oplus\right)$',
    ]

    of = outfile[:5]+outfile[5:].replace('data', 'plots')+'_posterior'
    plot_utils.chainer_plot(
        infile       = outfile+'.npy',
        outfile      = of,
        outformat    = ['pdf'],
        args         = args,
        llh_paramset = hypo_paramset,
        fig_text     = gen_figtext(args),
        labels       = labels
    )

    print("DONE!")