rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
scm_get_neighbours.m
Go to the documentation of this file.
1 function [P_M, ind] = scm_get_neighbours(M, mu, C)
2 %[P_M, ind] = scm_get_neighbours(M, mu, C)
3 %
4 % function which computes the set P_M(mu,C) with M\in\mathbb{N}, mu the
5 % parameter and C a set of parameters (the parameters in C have the same
6 % size as mu. The set P_M(mu,C) is defined as
7 % P_M(mu,C) = {the M closest neigbours of mu in C, measured in |.|, if 1 <= M < C,
8 % C, if M >= |C|,
9 % [], if M = 0.
10 %
11 % The second output ind contains the indices of the M closest neighbours of
12 % mu in C.
13 
14 % Dominik Garmatter 23.03 2012
15 
16 P_M = [];
17 ind = [];
18 
19 if M ~= 0 && isequal(C,[]) ~= 1
20  mu = mu(:); % we assume that every row of C contains a parameter
21  % realises P_M(mu,C)
22  c = size(C,2);
23  A = mu(:)*ones(1,c);
24  if size(C,1) > 1
25  [~,I] = sort(sqrt(sum((A-C).^2)));
26  elseif size(C,1) == 1
27  [~,I] = sort(abs(A-C));
28  end
29  ind = I(1:min(c,M));
30  P_M = C(:, ind);
31 end
function [ P_M , ind ] = scm_get_neighbours(M, mu, C)
[P_M, ind] = scm_get_neighbours(M, mu, C)