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