%define sample size sampleSize = 20; % define window widths h = [5]'; % define discrete values of x xs = [-sampleSize:1:sampleSize]'; % define mu and sigma mu = 0; sigma = 5; % calculate actual pdf values targetValues1 = zeros(size(xs,1),1); for i=1:size(xs,1) targetValues1(i) = normpdf(xs(i),mu,sigma); end % start finding p-hat(x) values for each bandwidth probValues = zeros(size(xs,1),size(h,1)); % UNIFORM KERNEL for i = 1:size(xs,1) myX = xs(i); myProbability = 0; if (abs(myX)/h) > 1 myProbability = 0; else for j = 1:sampleSize u = (myX - allPoints(j))/h; myProbability = myProbability + (0.5); end myProbability = myProbability / (size(xs,1) * h); % below line is matlab version of the above 5 lines % probValue = ksdensity(trainEffort, effToEstimate,'width',h,'kernel','box'); end probValues(i) = myProbability; end % uniform weights uniformWeighingProbs = ones(size(xs,1),size(h,1)) * (1/(2*sampleSize)); % now draw the figure figure; hold on; axis([-sampleSize sampleSize 0 (max(probValues)+0.05)]); set(gca,'FontSize', 22,'FontName','Times New Roman'); h1 = semilogy(xs,probValues(:,1)); h2 = semilogy(xs,uniformWeighingProbs); h3 = semilogy(xs,targetValues1); markerSize = 6; set(h1, 'LineStyle', '--', 'LineWidth', 1.0, 'Color', 'Black'); set(h1, 'Marker', 'o', 'MarkerFaceColor', [0.5 0.5 0.5], 'MarkerEdgeColor', [0 0 0], 'MarkerSize', markerSize); set(h2, 'LineStyle', '-', 'LineWidth', 1.0, 'Color',' Black'); set(h2, 'Marker', 's', 'MarkerFaceColor', [1 1 1], 'MarkerEdgeColor', [0 0 0], 'MarkerSize', markerSize); set(h3, 'LineStyle', '-', 'LineWidth', 1.0, 'Color',' Black'); set(h3,'LineWidth', 1.5, 'MarkerFaceColor', [1 1 1], 'MarkerEdgeColor', [0 0 0], 'MarkerSize', markerSize); % title('Uniform vs. Non-Uniform Weighting'); xlabel('Instances IDs'); ylabel('Actual Probability Values in Log Scale'); legend('Uniform Kernel','ABE0','Actual Probability Values');