X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Feconometrics-1.0.8%2Fkernel_regression_nodes.m;fp=octave_packages%2Feconometrics-1.0.8%2Fkernel_regression_nodes.m;h=35bf3a5f6a7af9f7943f3f6bcb9d2af4bafca7a6;hp=0000000000000000000000000000000000000000;hb=c880e8788dfc484bf23ce13fa2787f2c6bca4863;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/econometrics-1.0.8/kernel_regression_nodes.m b/octave_packages/econometrics-1.0.8/kernel_regression_nodes.m new file mode 100644 index 0000000..35bf3a5 --- /dev/null +++ b/octave_packages/econometrics-1.0.8/kernel_regression_nodes.m @@ -0,0 +1,62 @@ +# Copyright (C) 2006, 2007 Michael Creel +# under the terms of the GNU General Public License. +# +# 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 2 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 . + +# kernel_regression_nodes: for internal use by kernel_regression - does calculations on nodes + +function z = kernel_regression_nodes(eval_points, data, do_cv, kernel, points_per_node, nslaves, debug) + + if (nslaves > 0) + global NEWORLD + [info, myrank] = MPI_Comm_rank(NEWORLD); + else myrank = 0; # if not parallel then do all on master node + endif + + if myrank == 0 # Do this if I'm master + startblock = nslaves*points_per_node + 1; + endblock = rows(eval_points); + else # this is for the slaves + startblock = myrank*points_per_node - points_per_node + 1; + endblock = myrank*points_per_node; + endif + + # the block of eval_points this node does + myeval = eval_points(startblock:endblock,:); + nn = rows(myeval); + n = rows(data); + + y = data(:,1); + data = data(:,2:columns(data)); + W = __kernel_weights(data, myeval, kernel); + + # drop own weight for CV + if (do_cv) W = W - diag(diag(W)); endif + + den = sum(W,2); + if !all(den) + warning("kernel_regression: some evaluation points have no neighbors - increase the bandwidth"); + den = den + eps; # avoid divide by zero + endif + + W = W ./ (repmat(den,1,n)); + z = W*y; + + if debug + printf("z on node %d: \n", myrank); + z' + endif +endfunction + +