Hi, guys, I've been banging my head against a wall with this problem for about a week now, and though this doesn't really apply to this forum, I was hoping that those that browse this forum have the best chance of answering my question.
Anyway, here's the deal. I programmed a likelihood code, called a Blackwell-Rao estimator, for analyzing CMB data. It works great, as long as I only make use of the first few spherical harmonics. But it very quickly starts giving erroneous results as I include more l's. I need the code to work out to about l = 30, and right now it's only working properly up to roughly l=5-7 or so.
Here's the money shot of the essential code block:
A few notes: ldvector is my long double-precision array container class. In the class member function sum() of ldvector, the argument is just a flag passed to the function that describes how the array is summed.
I'm attempting to implement the estimator as described in the following paper:
http://www.arxiv.org/abs/astro-ph/0411737
The equations I'm attempting to implement with the above code are equations 11 and 13.
Anyway, I'd be appreciative if anybody here could help me brainstorm for other possible ways in which this code might possibly be breaking down. Thanks much.
Anyway, here's the deal. I programmed a likelihood code, called a Blackwell-Rao estimator, for analyzing CMB data. It works great, as long as I only make use of the first few spherical harmonics. But it very quickly starts giving erroneous results as I include more l's. I need the code to work out to about l = 30, and right now it's only working properly up to roughly l=5-7 or so.
Here's the money shot of the essential code block:
Code:
ldvector samplelikelihood(numsamples);
for (ii = 0; ii < numsamples; ii++)
{
ldvector thislnlike(lmax-1);
for (jj = 0; jj < lmax-1; jj++)
{
long double ll = lval.val[jj];
thislnlike.val[jj] = (2*ll+1.0)/2.0*(log((long double)sigmal[ii].val[jj]/Cl.val[jj]) - sigmal[ii].val[jj]/Cl.val[jj])
- log((long double)sigmal[ii].val[jj]);
}
//Total lnlikelihood for this sample:
samplelikelihood.val[ii] = thislnlike.sum(VSORT);
}
//ln(likelihoods) calculated, now calculate optimal offset
double maxlnlike = 10.0;
double offset = -1e100;
//Find maximum ln(likelihood) stored
for (jj = 0; jj < lmax-1; jj++)
if (offset < samplelikelihood.val[jj])
offset = samplelikelihood.val[jj];
//Set offset to a bit below this for maximal numerical stability
offset -= maxlnlike;
//Offset each ln(likelihood) and exponentiate
for (jj = 0; jj < numsamples; jj++)
samplelikelihood.val[jj] = exp(samplelikelihood.val[jj] - offset)/(long double)numsamples;
//Sum likelihoods for each l to get likelihood for this sample
likelihood = log(samplelikelihood.sum(VSORT)) + offset;
I'm attempting to implement the estimator as described in the following paper:
http://www.arxiv.org/abs/astro-ph/0411737
The equations I'm attempting to implement with the above code are equations 11 and 13.
Anyway, I'd be appreciative if anybody here could help me brainstorm for other possible ways in which this code might possibly be breaking down. Thanks much.