forked from ilarinieminen/SOM-Toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsom_fillnans.m
56 lines (45 loc) · 1.29 KB
/
som_fillnans.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
54
function sD = som_fillnans(sD,sM,bmus)
% SOM_FILLNANS Replaces NaNs in the data matrix with values from
% SOM prototypes.
%
% sD = som_fillnans(sD,sM, [bmus])
%
% sD (struct) data struct
% (matrix) size dlen x dim
% sM (struct) data struct, with .data of size dlen x dim
% (matrix) size dlen x dim, a matrix from which
% the values are taken from directly
% (struct) map struct: replacement values are taken from
% sM.codebook(bmus,:)
% [bmus] (vector) BMU for each data vector (calculated if not specified)
%
% See also SOM_MAKE.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if isstruct(sD),
[dlen dim] = size(sD.data);
nans = find(isnan(sD.data));
else
[dlen dim] = size(sD);
nans = find(isnan(sD));
end
if nargin<3,
bmus = som_bmus(sM,sD);
end
if isstruct(sM) && strcmp(sM.type,'som_map'),
sM = sM.codebook(bmus,:);
elseif isstruct(sM),
sM = sM.data(bmus,:);
else
sM = sM(bmus,:);
end
me = mean(sM);
if any(size(sM) ~= [dlen dim]),
error('Invalid input arguments.')
end
if isstruct(sD),
sD.data(nans) = sM(nans);
else
sD(nans) = sM(nans);
end
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%