Error: "The PDF function returned NaN or infinite values" or "The PDF function returned negative or zero values."
Afficher commentaires plus anciens
Hello all,
I'm trying to make a mixed probability function within the interval [0,1]. All my data is in the interval [0,1]. For my data I thought to do it with 2 possible manners: 1) with a LogNormal and a Normal distributions 2) Using 2 Beta distributions and a uniform one.
In the first case I got as error: "The PDF function returned negative or zero values."
Instead in the second case: "The PDF function returned NaN or infinite values."
I try go through the mle's codes, but it seems impossible for me to understand the mistake.
Below is the code of the second solution (2 Beta distributions and a uniform):
function f=BIMpdf(data,x)
pdf_mix= @(x,p,q,a1,a2,b1,b2) ...
p*betapdf(x,a1,b1) + (1-p-q)*betapdf(x,a1,b2) + q;
qStart= 0.001;
pStart = .7;
data1= data(data<=0.3);
data2= data(data>0.8);
m= [mean(data1) mean(data2)];
s = [var(data1) var(data2)];
for k=1:2
aStart(1,k)= m(k)*(1-m(k)-s(k))/s(k);
bStart(1,k) =(1-m(k)-s(k))*(1-m(k))/s(k);
end
start = [pStart qStart aStart bStart]
% p q a1 a2 b1 b2
lb = [0 0 0 0 0 0];
ub = [1 1 Inf Inf Inf Inf];
options = statset('MaxIter',600, 'MaxFunEvals',1000);
[paramEsts, pci] = mle(data', 'pdf',pdf_mix, 'start',start, 'lower',lb, 'upper',ub);
f= pdf_mix(x,paramEsts(1),paramEsts(2),paramEsts(3),paramEsts(4),paramEsts(5),parEsts(6));
end
Thanks a lot for your help guys!
Réponses (0)
Catégories
En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!