annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/som_estimate_gmm.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function [K,P] = som_estimate_gmm(sM, sD)
Daniel@0 2
Daniel@0 3 %SOM_ESTIMATE_GMM Estimate a gaussian mixture model based on map.
Daniel@0 4 %
Daniel@0 5 % [K,P] = som_estimate_gmm(sM, sD)
Daniel@0 6 %
Daniel@0 7 % Input and output arguments:
Daniel@0 8 % sM (struct) map struct
Daniel@0 9 % sD (struct) data struct
Daniel@0 10 % (matrix) size dlen x dim, the data to use when estimating
Daniel@0 11 % the gaussian kernels
Daniel@0 12 %
Daniel@0 13 % K (matrix) size munits x dim, kernel width parametes for
Daniel@0 14 % each map unit
Daniel@0 15 % P (vector) size 1 x munits, a priori probability of each map unit
Daniel@0 16 %
Daniel@0 17 % See also SOM_PROBABILITY_GMM.
Daniel@0 18
Daniel@0 19 % Reference: Alhoniemi, E., Himberg, J., Vesanto, J.,
Daniel@0 20 % "Probabilistic measures for responses of Self-Organizing Maps",
Daniel@0 21 % Proceedings of Computational Intelligence Methods and
Daniel@0 22 % Applications (CIMA), 1999, Rochester, N.Y., USA, pp. 286-289.
Daniel@0 23
Daniel@0 24 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Esa Alhoniemi
Daniel@0 25 % Copyright (c) by Esa Alhoniemi
Daniel@0 26 % http://www.cis.hut.fi/projects/somtoolbox/
Daniel@0 27
Daniel@0 28 % ecco 180298 juuso 050100 250400
Daniel@0 29
Daniel@0 30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniel@0 31
Daniel@0 32 [c, dim] = size(sM.codebook);
Daniel@0 33 M = sM.codebook;
Daniel@0 34
Daniel@0 35 if isstruct(sD), D = sD.data; else D = sD; end
Daniel@0 36 dlen = length(D(:,1));
Daniel@0 37
Daniel@0 38 %%%%%%%%%%%%%%%%%%%%%
Daniel@0 39 % compute hits & bmus
Daniel@0 40
Daniel@0 41 [bmus, qerrs] = som_bmus(sM, D);
Daniel@0 42 hits = zeros(1,c);
Daniel@0 43 for i = 1:c, hits(i) = sum(bmus == i); end
Daniel@0 44
Daniel@0 45 %%%%%%%%%%%%%%%%%%%%
Daniel@0 46 % a priori
Daniel@0 47
Daniel@0 48 % neighborhood kernel
Daniel@0 49 r = sM.trainhist(end).radius_fin; % neighborhood radius
Daniel@0 50 if isempty(r) | isnan(r), r=1; end
Daniel@0 51 Ud = som_unit_dists(sM);
Daniel@0 52 Ud = Ud.^2;
Daniel@0 53 r = r^2;
Daniel@0 54 if r==0, r=eps; end % to get rid of div-by-zero errors
Daniel@0 55 switch sM.neigh,
Daniel@0 56 case 'bubble', H = (Ud<=r);
Daniel@0 57 case 'gaussian', H = exp(-Ud/(2*r));
Daniel@0 58 case 'cutgauss', H = exp(-Ud/(2*r)) .* (Ud<=r);
Daniel@0 59 case 'ep', H = (1-Ud/r) .* (Ud<=r);
Daniel@0 60 end
Daniel@0 61
Daniel@0 62 % a priori prob. = hit histogram weighted by the neighborhood kernel
Daniel@0 63 P = hits*H;
Daniel@0 64 P = P/sum(P);
Daniel@0 65
Daniel@0 66 %%%%%%%%%%%%%%%%%%%%
Daniel@0 67 % kernel widths (& centers)
Daniel@0 68
Daniel@0 69 K = ones(c, dim) * NaN; % kernel widths
Daniel@0 70 for m = 1:c,
Daniel@0 71 w = H(bmus,m);
Daniel@0 72 w = w/sum(w);
Daniel@0 73 for i = 1:dim,
Daniel@0 74 d = (D(:,i) - M(m,i)).^2; % compute variance of ith
Daniel@0 75 K(m,i) = w'*d; % variable of centroid m
Daniel@0 76 end
Daniel@0 77 end
Daniel@0 78
Daniel@0 79 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%