Пример #1
0
    def computeLikelihood(self, ctx):
        """
        call the native code to compute log likelihood
        
        :param ctx: an instance of a ChainContext
        
        :returns: the log likelihood 
        
        :raises InvalidLikelihoodException: in case the log likelihood from the 
                wmapWrapper is smaller than 0.0001
        """
        cl_tt =ctx.get(CL_TT_KEY)
        cl_te =ctx.get(CL_TE_KEY)
        cl_ee =ctx.get(CL_EE_KEY)
        cl_bb =ctx.get(CL_BB_KEY)
        
        loglike = -wmapWrapperManager.computewmaplikelihood(cl_tt,cl_te,cl_ee,cl_bb)
        
        if(abs(loglike)<0.0001):
            raise InvalidLikelihoodException()

        return loglike
from wmap3Wrapper import wmapWrapperManager

import numpy as np

def copyArray(src, trg, index):
    lenght= min(len(src),len(trg))
    for i in xrange(0,lenght):
        trg[i]=src[i,index]
    

data = np.loadtxt("lensedcls.dat")

size = 1199

cl_tt = np.zeros(size)
cl_te = np.zeros(size)
cl_ee = np.zeros(size)
cl_bb = np.zeros(size)
#
copyArray(data, cl_tt, 1)
copyArray(data, cl_te, 4)
copyArray(data, cl_ee, 2)
copyArray(data, cl_bb, 3)

wmapWrapperManager.setup()

likelihood = wmapWrapperManager.computewmaplikelihood(cl_tt,cl_te,cl_ee,cl_bb)
print likelihood