Likelihood cross validation estimation
Afficher commentaires plus anciens
Hi,
I'm trying to use likelihood cross-validation method to select the bandwidth for the kernel density estimator in Matlab.
I've done something like below:
[~,~,bw] = ksdensity(DATA_I_HAVE);
%the default bw from ksdensity function
loglik = @(xtr,xte) sum(log(ksdensity(xtr,xte,'width',h)));
v = @(h,data,cens,freq) -sum(crossval(loglik,data,'leaveout',1));
h_hat = mle(DATA_I_HAVE,'nloglf',v,'start',bw)
Can I ask whether there is a way to put those two steps (the sum of log pdf and crossval) together? Alternatively, is there a better way to obtain the optimal bw using likelihood cross-validation method in Matlab?
Thanks very much!
Hi,
I've made some changes to the code, it works now, but takes quite long time, I really appreciate if you can give some suggestions for improvement!
[~,~,bw0] = ksdensity(DATA_I_HAVE);
h_hat = mle(DATA_I_HAVE,'nloglf',@custnloglf,'start',bw0);
function val = custnloglf(h,data,cens,freq)
val = -sum(crossval(@loglik,data,'leaveout',1));
function ll = loglik(xtr,xte)
ll = sum(log(ksdensity(xtr,xte,'width',h)));
end
end
Thanks!
Réponses (0)
Catégories
En savoir plus sur Kernel Distribution 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!