Skip to content

Instantly share code, notes, and snippets.

@evanbiederstedt
Created November 22, 2015 18:43
Show Gist options
  • Save evanbiederstedt/092866cc951dd0d8e490 to your computer and use it in GitHub Desktop.
Save evanbiederstedt/092866cc951dd0d8e490 to your computer and use it in GitHub Desktop.
-2LogLF function with Planck map values
# The -2 log-likelihood
#
# -2lnL \propto m^T C^-1 m + ln det C + N ln (2pi)
#
# First term, m^T C^-1 m is the "model fit term"
# Second term, lndetC is the "complexity penalty"
# Third term, N ln 2pi, a constant
#
# m = tempval
# C = Sij + N_ij
tempp = patch # shape (768,)
# e.g. values:
# 72.88291049, 76.82649994, 11.31249934, -11.75291294,
# -23.46053075, 22.16308705, 21.45570391, -21.91874249,
# 62.40692039, 91.91584206
noisepatch # corresponding noise values, shape (768,)
# e.g. values:
# 3.02168953, -12.46713406, 7.32537 , 1.7936974 ,
# 2.54476212, -4.8399158 , 1.17796342, -4.80521029,
# -2.31289673, 5.95576501
Npix2pi = (len(patch))*2*math.pi # LF constant
def LogLikehood_wNoise(param, sig):
# param is our parameter, C_3
Sij = param[:, None, None] * correctmatrix[None, :, :]
#newSij = (1e12)*Sij # multiply S_ij by 1e12
Nij = sig * id_mat[None, :, :]
#newNij = (1e12)*Nij
# Format 7/4pi * param * P_3(M) where param is the parameter we vary, C_l
# Sij.shape = (20, 3072, 3072)
Cij = Sij + Nij
#invCij = np.linalg.inv(Cij)
logdetC = np.linalg.slogdet(Cij) # returns sign and determinant; use logdetC[1]
# model_fit_terms = m^T C^-1 m
model_fit_terms = np.array([np.dot(tempp.T , np.linalg.solve(Cij[i], tempp) ) for i in range(Cij.shape[0]) ])
return model_fit_terms + logdetC[1] + Npix2pi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment