pdf of Poisson binomial distribution in Matlab

조회 수: 9 (최근 30일)
valentino dardanoni
valentino dardanoni 2023년 12월 9일
댓글: Paul 2024년 12월 22일
Is there a Matlab implementation for the calculation of the pdf for the Poisson-binomial distribution?
  댓글 수: 3
valentino dardanoni
valentino dardanoni 2023년 12월 9일
Thank you Torsten, I guess I could start with a small example with small n, say n=5
Torsten
Torsten 2023년 12월 9일
편집: Torsten 2023년 12월 9일

댓글을 달려면 로그인하십시오.

채택된 답변

Gyan Vaibhav
Gyan Vaibhav 2023년 12월 18일
편집: Gyan Vaibhav 2023년 12월 18일
Hi Valentino,
I understand that you are trying to find the PDF of a given Binomial-Poisson distribution.
While MATLAB doesn't offer a built-in function specifically for this purpose, you can certainly craft a custom function to accomplish the task.
The code snippet provided below is designed to calculate the PDF for a Poisson-Binomial distribution. This function requires two input arguments:
  1. successProbs: A vector containing the individual success probabilities for each trial.
  2. k: The specific number of successful trials for which you wish to compute the PDF.
function pdf = poisson_binomial_pdf(successProbs, k)
% successProbs is a vector containing the success probabilities for each trial
% k is the number of successful trials for which you want to calculate the PDF
n = length(successProbs); % Number of trials
% The FFT-based method for Poisson-binomial PDF calculation
M = 2^nextpow2(2*n); % Find the next power of 2 for zero-padding
omega = exp(-2i * pi / M);
A = ones(1, M);
for j = 1:n
A = A .* (1 - successProbs(j) + successProbs(j) * omega.^(0:M-1));
end
pdfVals = ifft(A);
pdf = real(pdfVals(1:n+1)); % Only the first (n+1) values are needed
% Return the PDF value for k successes
if k >= 0 && k <= n
pdf = pdf(k+1);
else
pdf = 0;
end
end
You can use this function as follows:
% Example success probabilities for 5 trials
successProbs = [0.04, 0.07, 0.07];
% Calculate the PDF for 3 successes
k = 3;
pdfValue = poisson_binomial_pdf(successProbs, k);
This approach gives us the PDF of a Binomial-Poisson Distribution.
Hope this helps.
Thanks
Gyan
  댓글 수: 7
John D'Errico
John D'Errico 2024년 12월 22일
편집: John D'Errico 2024년 12월 22일
Yeah, I did not look carefully at the original code. Pulling omega out helps a lot. Given that I have one case where n may be as large as 7 million, the difference would be significant.
Paul
Paul 2024년 12월 22일
I didn't test each change individually, but I imagine elminating the loop over k (outside the function) is quite signficant as well.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by