help-octave
[Top][All Lists]

## speed up a computation?

 From: Michael Creel Subject: speed up a computation? Date: Wed, 7 Nov 2007 12:03:53 +0100

```For use by kernel density and regression functions, I have written two
kernel functions, a Gaussian product kernel, and a radial symmetric
Epanechnikov kernel. The two functions are

# product normal kernel
# input: PxK matrix - P data points, each of which is in R^K
# output: Px1 vector, input matrix passed though the kernel
# other multivariate kernel functions should follow this convention

function z = __kernel_normal(z)

z = normal_pdf(z);
z = prod(z,2);

endfunction

# multivariate spherical Epanechnikov kernel
# input: PxK matrix - P data points, each of which is in R^K
# output: Px1 vector, input matrix passed though the kernel
# other multivariate kernel functions should follow this convention

function z = __kernel_epanechnikov(z)

K = columns(z);

# Volume of d-dimensional unit sphere
c = pi ^ (K/2) / gamma(K/2 + 1);

# compute kernel
z  =  sumsq(z, 2);
z = ((1/2) / c * (K + 2) * (1 - z)) .* (z < 1);

endfunction

When the input matrix z is large, the Epanechnikov kernel is
considerably faster to compute. However, the Gaussian kernel is more
stable in the applications I'm working on, since it is always nice and
smooth. So I'm wondering if I can speed up the Gaussian kernel
computations.
Thanks, M.

--
There are 10 kinds of people - those who understand binary and those who don't.

```