I have a vector of 10,000 observations and I need to estimate the pdf at each point of the vector. The code I have is the following (Matlab):
n = 1000; %Sample size
Y = normrnd(0,1,n,1); %Data
h = 1.06*std(Y)*n^(-1/5); %Bandwith
pair = (Y - Y')/h; %Argument of Kernel
pair_kernel = normpdf(pair); %calculate kernel on all the matrix
f_hat = mean(pair_kernel,2)/h; %Kernel estimate of pdf
The running time increases considerably when I go from n=1000 to n=10000. This is an issue because I have to do this many times as it is a Monte Carlo study. I wonder if there is a more efficient way to deal with the large matrices.