[2cc862]: src / __kernel_weights.cc Maximize Restore History

Download this file

__kernel_weights.cc    61 lines (52 with data), 1.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (C) 2007 Michael Creel <michael.creel@uab.es>
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see <http://www.gnu.org/licenses/>.
// __kernel_weights: for internal use by kernel density and regression functions
// This function was originally written as .m file and eventually rewritten in
// C++ for performance. the .m file was removed from the package on revision
// 10407 by carandraug
#include <oct.h>
#include <octave/parse.h>
DEFUN_DLD(__kernel_weights, args, ,"__kernel_weights: for internal use by kernel_regression and kernel_density functions")
{
Matrix data (args(0).matrix_value());
Matrix evalpoints (args(1).matrix_value());
std::string kernel (args(2).string_value());
int n, nn, i, j, k, kk, dim;
n = data.rows();
dim = data.columns();
nn = evalpoints.rows();
Matrix W(nn, n);
Matrix zz(n,dim);
Matrix zzz;
octave_value kernelargs;
octave_value_list f_return;
for (i = 0; i < nn; i++) {
for (j = 0; j < n; j++) {
// note to self: zz.insert(data.row(j) - evalpoints.row(i), j, 0) is slower
for (k = 0; k < dim; k++) {
zz(j,k) = data(j,k) - evalpoints(i,k);
}
}
kernelargs = zz;
f_return = feval(kernel, kernelargs);
zzz = f_return(0).matrix_value();
// note to self: W.insert(zzz.transpose(),i,0) is slower
for (j = 0; j < n; j++) {
W(i,j) = zzz(j,0);
}
}
f_return(0) = W;
return f_return;
}