% This function evaluates a univariate Rosenblatt density estimator.
% Inputs:
% X: n X 1 vector of observations
% evl: p X 1 vector of points where the estimator is evaluated
% h: a scalar bandwidth
% K: a scalar that determines the kernel.
% 1 rectangular, 2 triangular, 3 Epanechnikov, 4 Biweight, 5 Gaussian
% output: fhat a pX1 vector containing the estimated density at evl

function fhat = urosenblatt(X,evl,h,K)
n=size(X,1);
a=(1/h)*gsubtract(X,evl');
if K==1
    k=0.5*(abs(a)<=1);
elseif K==2
    k=(1-abs(a)).*(abs(a)<=1);
elseif K==3
    k=0.75*(1-a.^2).*(abs(a)<=1);
elseif K==4
    k=((15/16)*(1-a.^2).^2).*(abs(a)<=1);
else 
    k=(1/sqrt(2*pi)).*exp(-0.5*a.^2);
end        
fhat =(1/(n*h))*sum(k)';
