]> Creatis software - CreaPhase.git/blob - octave_packages/econometrics-1.0.8/kernel_density_nodes.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / econometrics-1.0.8 / kernel_density_nodes.m
1 # Copyright (C) 2006, 2007  Michael Creel <michael.creel@uab.es>
2 # under the terms of the GNU General Public License.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; If not, see <http://www.gnu.org/licenses/>.
16
17 # kernel_density_nodes: for internal use by kernel_density - does calculations on nodes
18
19 function z = kernel_density_nodes(eval_points, data, do_cv, kernel, points_per_node, nslaves, debug)
20
21         if (nslaves > 0)
22                 global NEWORLD
23                 [info, myrank] = MPI_Comm_rank(NEWORLD);
24         else myrank = 0; # if not parallel then do all on master node
25         endif
26
27         if myrank == 0 # Do this if I'm master
28                 startblock = nslaves*points_per_node + 1;
29                 endblock = rows(eval_points);
30         else    # this is for the slaves
31                 startblock = myrank*points_per_node - points_per_node + 1;
32                 endblock = myrank*points_per_node;
33         endif
34
35         # the block of eval_points this node does
36         myeval = eval_points(startblock:endblock,:);
37         nn = rows(myeval);
38         n = rows(data);
39
40         W = __kernel_weights(data, myeval, kernel);
41         if (do_cv)
42                 W = W - diag(diag(W));
43                 z = sum(W,2) / (n-1);
44         else
45                 z = sum(W,2) / n;
46         endif
47
48         if debug
49                 printf("z on node %d: \n", myrank);
50                 z'
51         endif
52 endfunction
53
54