-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFindLocal.m
53 lines (44 loc) · 1.48 KB
/
FindLocal.m
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
%==========================================================================
%
% Function to find local minimum of trained kernel radius function
%
% Return Values:
% N_locals: local min corresponding to each sample
% local: unique local mins
%
%
%==========================================================================
% January 13, 2009
% Implemented by Daewon Lee
% WWW: http://sites.google.com/site/daewonlee/
%==========================================================================
function [N_locals,local,local_val,match_local]=FindLocal(X,model)
[N dim]=size(X);
N_locals=[];
local_val=[];
for i=1:N
x0=X(i,:);
options = optimset('Display','off','LargeScale','on','GradObj','on');
if length(x0)<=2
[temp val]=fminsearch(@my_R,x0,[],model); % Nelder-Mead
else
[temp val]=fminunc(@my_R,x0,options,model); % trust region method
end
N_locals=[N_locals; temp];
local_val=[local_val;val];
end
[local,I,match_local]=unique(round((10*N_locals)),'rows');
local=N_locals(I,:);
% for i=1:length(I)
% tmp=find(match_local==i);
% if length(tmp)<=1
% one_ind=I(match_local(tmp(1)));
% [dummy,ind]=sort(dist2(local,N_locals(one_ind,:)));
% N_locals(one_ind,:)=repmat(N_locals(ind(2),:),length(tmp),1);
% end
%
% end
% [local,I,match_local]=unique(round((10*N_locals)),'rows');
% local=N_locals(I,:);
%local=N_locals(I,:);
local_val=local_val(I,:);