Group: | Binning, Grids and Sequences |
See also: | bindata denest grid |
Function: | conv | |
Description: | conv performs the convolution of a step kernel function and a function over a p-dimensional equidistant grid. |
Usage: | {xc, yc, fill} = conv (xb, yb, wx, wy {,sym}) | |
Input: | ||
xb | m x p x d1 x ... x dn array of integers | |
yb | m x l x d1 x ... x dn array of non-negative integers | |
wx | r x p x d1 x ... x dn array of non-negative integers | |
wy | r x 1x d1 x ... x dn array | |
sym | scalar | |
Output: | ||
xc | k x p x d1 x ... x dn array (k >= m) | |
yc | k x l x d1 x ... x dn array | |
fill | k x 1 x d1 x ... x dn array of zeros or ones |
For p has to hold: p <= 15.
IDEA:
conv is a computational command to improve the speed with which the kernel estimates are carried out.
In a first step you need to bin your data, e.g. with bindata.
In a second step you descreticize the kernel that you have chosen.
Both grids must have the same size.
conv performs the convolution of given values of a symmetric p-dimensional (step) function K(x), with the columns of a matrix yb with values given over a p-dimensional grid, as produced when binning your data.
INPUTS:
xb, a m x p matrix of integers with the indices of the bins in the grid (e.g., like xb as returned by bindata) and
yb, a m x 1 matrix (e.g., yb as returned by bindata),which gives you the number of your data points in each of the bins.
wy is the evaluation of K(x) at the points
wx.*d'. Here d, a p x 1 vector, is the binwidth in each coordinate direction (e.g. as used in the bindata command)
sym specifies the symmetry of the Kernel you use:
You can specify via the parameter sym the symmetry of K(x). This is given by
sym = s_1*2^0 + s_2*2^1 + ...+ s_p*2^(p-1)
where s_j = 0 indicates that K(x) is an even function with respect to the j-th coordinate, respectively s_j = 1 that it is an odd function.
The default value is sym = (0,...,0).
COMPUTATION:
The convolution is calculated for each bin (b_1...b_j...b_p) of the full grid xc (given by the bins in xb plus the empty bins) and the result is stored in the matrix yc.
The calculation of yc_i involve the values of yb that belong to the bins in a neighbourhood of xc_i, defined by the matrix wx.
The matrix wx is a matrix of (non-negative) integers where wx_l = (k_1...k_j...k_p) indicates that the values of yb belonging to the bins (b_1+/-k_1...b_j+/-k_j... b_p+/-k_p) should be multiplied by the value wy_i (or -wy_i depending on the symmetry considered for K(x)). The sum of all these products give the result yc_i.
The output vector fill is defined according to, fill_i = 1 if xc_i is in xb and fill_i = 0 otherwise.
x = normal(100) {xb,yb} = bindata(x, 0.4,0) wx = #(0,1) wy = #(1.25,0.75) {xc, yc, fill} = conv(xb, yb, wx, wy) cc=createdisplay(1,1) show(cc,1,1,xc ~ yc)
Display of a one-dimensional kernel estimate of the normal distribution.
randomize(0) x = normal(100,2) {xb,yb} = bindata(x, #(0.25,0.5),#(0,0)) library("kernel") x = #(0,0) h = #(0.25,0.25) n = #(5,5) wx= grid(x,#(1,1),n) wy = qua(wx.*h') {xc, yc, fill} = conv(xb, yb, wx, wy) cc=createdisplay(1,1) show(cc,1,1,xc ~ yc)
Display of a two-dimensional kernel estimate of the two-dimensional normal distribution.