/* This file contains some kernel functions. All functions take an
n x k matrix u as their argument and return an n x k matrix with the
function evaluated in each point of x and an n x k matrix d with the
derivative of the function in each point of x.
    k_bw:     biweight kernel function
    k_epan:   Epanechnikov kernel
    k_gauss:  Gaussian kernel
    k_triang: triangular kernel
    k_rect:   rectangular kernel

usage:
    {f,d}=k_bw(u);
*/

proc (2)=k_bw(u);
 local select;
 select = abs(u).<=1;
 retp( 15/16*((1-u.^2).^2).*select, -15/4*u.*(1-u.^2).*select);
endp;

proc (2)=k_gauss(u);
    retp( pdfn(u), -u.*pdfn(u) );
endp;

proc (2)=k_epan(u);
    local c, s;
    s = abs(u).<sqrt(5);
    c = 0.75/sqrt(5);
    retp( c*(1-0.2*u.^2).*s, -0.4*c*u.*s );
endp;

proc (2)=k_rect(u);
    retp( 0.5*(abs(u).<1), 0*u );
endp;

proc (2)=k_trian(u);
    local s, a;
    a = abs(u);
    s = a.<1;
    retp( (1-a).*s, (-(u.>=0) + (u.<=0)).*s );
endp;



