Esempio n. 1
0
def lnlike(theta, y, errs_l, errs_h):
    global step, mcmc_count, value
    om, w, h0 =theta
    rzs=vec_r(zs,om,w)
    model = (1+zs)*c*rzs/h0             #133 numbers of the models
    #print theta
    ps=pz(om,w,h0)
    for i in range(20):
        err = errs_l + (errs_h - errs_l)*i/19.
        twod_like = np.exp(-0.5*(pow((y[:,None]-model),2)/pow(err[:,None],2)))*ps[:,1]
        likh=twod_like[:,:-1]*ddz.T     #the sub of the intergral
        if i ==0:
            int_likh=np.sum(likh[:,:],axis=1)
        else:
            int_likh += int_likh
    if mcmc_count == 1:
        count=np.sum(sampler.flatchain!=0)/(ndim*nwalkers)
        if count!=step:
            step = count
            ticks2=time.time()
            print "step:",count,"percent",round(count/(Nburn/100),2),"%"
            if step !=0:
                print "remain time:", round((ticks2-ticks1)/step*(Nburn-step)/60,2), "mins;"
            if step/10 > (step-1)/10 :
                print "To write the value", value
    #print np.shape(int_likh)
    return np.sum(np.log(int_likh))
Esempio n. 2
0
def twod_like(
    theta, y, err
):  #set zs to be 2D to get 2D sub_int, from (len(data)) to (len(data),133)
    om, w, h0 = theta
    rzs = vec_r(zs, om, w)
    model = (1 + zs) * c * rzs / h0  #133 numbers of the models
    #print np.shape(y),np.shape(model)
    ps = pz(om, w, h0)
    likh = np.exp(-0.5 * (pow(
        (y[:, None] - model), 2) / pow(err[:, None], 2))) * ps[:, 1]
    #print likh[1,:]
    return likh
Esempio n. 3
0
def lnlike(theta, y, errs_l, errs_h):
    om, w, h0 = theta
    rzs = vec_r(zs, om, w)
    model = (1 + zs) * c * rzs / h0  #133 numbers of the models
    #print theta
    ps = pz(om, w, h0)
    for i in range(20):
        err = errs_l + (errs_h - errs_l) * i / 19.
        twod_like = np.exp(-0.5 * (pow(
            (y[:, None] - model), 2) / pow(err[:, None], 2))) * ps[:, 1]
        likh = twod_like[:, :-1] * ddz.T  #the sub of the intergral
        if i == 0:
            int_likh = np.sum(likh[:, :], axis=1)
        else:
            int_likh += int_likh
    #print np.shape(int_likh)
    return np.sum(np.log(int_likh))
Esempio n. 4
0
@author: dartoon
"""

import numpy as np
from scipy import integrate
import matplotlib.pyplot as plt
import sys
from pz_wcdm import pz
sys.path.insert(0, '../')
from gene_data import gene_data
##########to generate the lnPossible funtction, one need the Ka_square; P(zl|zs); P(zs).
#########to get the P(zs):#################
om = 0.3
h0 = 70
w = -1
ps = pz(om, w, h0)
zs = ps[:, 0]

################to get the ka^2 and combine together to get likehood for one data###################
c = 299790.


def Ez(z, om, w):
    return 1 / np.sqrt(om * (1 + z)**3 + (1 - om) * (1 + z)**(3 * (1 + w)))


def r(z, om, w):
    #if z < 20:
    return integrate.quad(Ez, 0, z, args=(om, w))[0]  #use the cos distance r

#else: