“…The statistics toolbox is required for this script. %% Loop over PDFs for j = 1:size(X,1) %% Optimal kernel density estimate w/ knowledge of PDF opt = optimalkernelbandwidth(x,f(j,:),n(aa),kernelflag); if kernelflag > 0 pd_opt = fitdist(X(j,:)',kernelargstr,'BandWidth',opt.h); elseif kernelflag < 0 pd_opt = fitdist(X(j,:)','Kernel','Kernel',kernelargstr,... 'BandWidth',opt.h); end kde_opt = pdf(pd_opt,x); %% Numerically ISE minimizing bandwidth temp = vbise(x,f(j,:),X(j,:),kernelflag); ind = find(temp.ISE==min(temp.ISE),1,'first'); h_opt = temp.h(ind); if kernelflag > 0 pd_numopt = fitdist(X(j,:)',kernelargstr,'BandWidth',h_opt); elseif kernelflag < 0 pd_numopt = fitdist(X(j,:)','Kernel','Kernel',... kernelargstr,'BandWidth',h_opt); end kde_numopt = pdf(pd_numopt,x); %% Cross-validation KDE cv = cv1d(X(j,:)',kernelflag); if kernelflag > 0 % % For MATLAB estimator % pd = fitdist(X(j,:)',kernelargstr); pd = fitdist(X(j,:)',kernelargstr,'BandWidth',cv.h); elseif kernelflag < 0 % % For MATLAB estimator % pd = fitdist(X(j,:)','Kernel','Kernel',kernelargstr); pd = fitdist(X(j,:)','Kernel','Kernel',kernelargstr,'BandWidth',cv.h); end kde = pdf(pd,x); h_hat = pd.BandWidth; pre_c1_CV(ii,j,aa) = h_hat-h_opt; pre_c23_CV(ii,j,aa) = ise(x,f(j,:),X(j,:),h_hat,kernelflag); pre_c45_CV(ii,j,aa) = ... pre_c23_CV(ii,j,aa)-ise(x,f(j,:),X(j,:),h_opt,kernelflag); %% Topological KDE tde = tde1d(X(j,:),kernelflag); f_tde = tde.y/(sum(tde.y)*mean(diff(tde.x))); h_hat = tde.h; pre_c1_top(ii,j,aa) = h_hat-h_opt; pre_c23_top(ii,j,aa) = ise(x,f(j,:),X(j,:),h_hat,kernelflag); pre_c45_top(ii,j,aa) = ... pre_c23_top(ii,j,aa)-ise(x,f(j,:),X(j,:),h_opt,kernelflag); %% Unimodal category and number of local maxima ucat_CV(ii,j,aa) = nnz(sum(unidec(kde,0),2)>sqrt(eps)); lmax_CV(ii,j,aa) = nnz(diff(sign(diff([0,kde,0])))<0); ucat_top(ii,j,aa) = tde.mfuc; lmax_top(ii,j,aa) = nnz(diff(sign(diff([0,f_tde,0])))<0); end end end %% c1 for j = 1:6 % Normalized histogram lo = min([min(min(pre_c1_top(:,j,:))),min(min(pre_c1_CV(:,j,:)))]); hi = max([max(max(pre_c1_top(:,j,:))),max(max(pre_c1_CV(:,j,:)))]); L = linspace(lo,hi,50); for k = 1:5 % n = [25,50,100,200,500] A(:,k) = histc(squeeze(pre_c1_top(:,j,k)),L,1); B(:,k) = histc(squeeze(pre_c1_CV(:,j,k)),L,1); end eval(normmacro); % Plot subplot(3,6,j); eval(plotmacro); title(['$f_',num2str(j),'$'],'Interpreter','latex'); end subplot(3,6,1); ylabel('$\hat h -h_{opt}$','Interpreter','latex'); %% c2, c3 for j = 1:6 % Normalized histogram lo = 0; hi = max([max(max(pre_c23_top(:,j,:))),max(max(pre_c23_CV(:,j,:)))]); L = linspace(lo,hi,50); for k = 1:5 % n = [25,50,100,200,500] A(:,k) = histc(squeeze(pre_c23_top(:,j,k)),L,1); B(:,k) = histc(squeeze(pre_c23_CV(:,j,k)),L,1); end eval(normmacro); % Plot subplot (3,6,j+6); eval(plotmacro); end subplot (3,6,7); ylabel('ISE$(\hat h)$','Interpreter','latex'); %% c4, c5 for j = 1:6 % Form histograms (note logspace). NB.…”