Writing an algorithm to estimate the parameters of an Poisson distribution conditioned on a 2D Gaussian with MLE

2 ビュー (過去 30 日間)
Context of the problem
I am attempting to fit a custom probability distribution to a bright spot on a dark image background. For each pixel within the image, the distribution in question is a Poisson distribution conditioned on the value of a 2D Gaussian distribution at that pixel. I want to do this using Matlab's MLE function.
Issue
I get the error "Error evaluating the user-supplied nloglf function" when I try to supply my negative log-likelihood function to Matlab, described mathematically below:
Here, I(x, y) represents pixel intensity at (x, y) and PSF represents the 2D Gaussian function at that pixel. I've tried to use both named and anonymous functions but I keep getting the same error. I don't know what's wrong with my code or how to fix it. Any help would be greatly appreciated.
Named function approach:
function psf = twoD_Gaussian(y_guess, x_guess, size, count, bg) % when testing use count = 1500
x = x_guess - floor(size/2):x_guess + floor(size/2);
y = y_guess - floor(size/2):y_guess + floor(size/2);
[x, y] = meshgrid(x, y);
psf = count/(2 * pi * size^2);
psf = psf * exp(-((x - x_guess).^2 + (y - y_guess).^2)/(2 * size^2));
psf = psf + bg;
end
function nloglf = poiss(data, y_guess, x_guess, size, count, bg)
nloglf = sum(data .* log(psf(y_guess, x_guess, size, count, bg)) - psf(y_guess, x_guess, size, count, bg), 'all')
end
nloglf = poiss(data, y_guess, x_guess, size, count, bg);
params = [1 1 1 1 1];
final = mle(data, 'nloglf', nloglf, 'start', params);
Anonymous function approach (assume size is known):
xr = x - floor(size/2):x + floor(size/2);
yr = y - floor(size/2):y + floor(size/2);
psf = @(x, y, size, count, bg) count/(2 * pi * size^2) * exp(-((xr - x).^2 + (yr - y).^2)/(2 * size^2)) + bg;
nloglf = @(data, x, y, size, count, bg) @(data,x,y,size,count,bg)-1 * sum(data .* log(psf(x,y,size,count,bg)) - psf(x,y,size,count,bg), 'all');
params = [1 1 1 1 1];
final = mle(data, 'nloglf', nloglf, 'start', params);

回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by