找回密码
 注册
关于网站域名变更的通知
查看: 527|回复: 3
打印 上一主题 下一主题

高斯混合模型里面的参数可以用到混核主元分析里面吗?

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2020-12-24 11:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
高斯混合模型里面的参数可以用到混核主元分析里面吗?有混合概率主元分析的EM算法的程序吗
! V' x( {+ }& tfunction ppca_mixture  , L1 P. T& E1 s8 X8 L
filename = 'virus3.dat';) }$ o$ y8 f6 N) R9 t  ]
    T = importdata(filename);
3 @) m8 x0 m! g0 H    [N, d] = size(T);
7 M1 Q& J1 w/ V# V/ z0 l    M = 3;  % number of ppca analysers considered 考虑的ppca分析仪数量
. {7 I# T1 `( S    q = 2;  % dimension of ppcas  ppca的维数. R  S- V- N& L; `* ?" p
    % init% {9 Z- M& n" y6 u
    % initializing the posteriors (p(i|t_n), indexed by (n, i). R in text)
1 b, r$ d- `; g% v  A    %初始化后验(p(i|t_n),在文本中由(n, i). R索引     - ?5 H( Z( g* }' B; X' ~
    classes = [3, 3, 3, 3, 2, 2, 3, 1, 3, 3, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2];
5 m. a9 [. G+ Q3 x3 c1 ~+ I0 O4 C3 c    for n=1:N
9 B7 N$ |, s8 j5 k. T" J        for i=1:M
" e! k" D+ S6 d! C            if(i==classes(n))+ H2 @; P6 D/ a. m& E  t" ~
                posteriors(n, i) = 1;5 w& d+ F2 J% Z& i3 n+ C
            else& `: i9 ?( H7 g6 V
                posteriors(n, i) = 0;/ O8 m0 P8 w8 ~% @# p" c
            end2 Q+ h( ~: Y( ~# j+ g( }+ A
        end
# a& c* N8 q5 T( d7 x) s    end, |. D( j4 L/ V3 b
    % precision for convergence checking 收敛检验精度
; h  N" B) I2 s    epsilon = 0.01;
$ y) _/ b7 V6 r$ }2 u) g$ z    entered = false;
$ M7 G* Y1 ~7 o' Y7 p, _- A
* d0 z4 I( U4 B& ^$ `$ Q( W4 ^' ^$ `    % loop
; O. Z, J+ c" T! {    while(true)
+ W9 O; n* I) H( j" I. b        % updating priors (p(i), pi in text) and mean vectors (mu in text)
6 v; |. w2 T: p8 n6 D        % 更新先验(p(i),文本中的pi)和平均向量(文本中的mu)$ f0 V* E7 U/ F' ~
        new_priors = 1/N * sum(posteriors);
' b2 O3 F, R4 B1 d6 o, C& v        new_mus = zeros(M, d);( V8 m2 y' X. h* h
        for i=1:M
( i6 H! X( b6 Y# s  M) S! n: o! b            for n=1:N
8 T5 T, |2 f4 V$ Z- O% c7 {                new_mus(i, = new_mus(i, + posteriors(n, i) * T(n, ;8 I: r0 c8 x" {" ^
            end" L9 O6 K9 x7 C/ z% Y( w: G
            new_mus(i, :) = new_mus(i, :) / sum(posteriors(:, i));$ ~: O- G( s$ Z$ j: g
        end+ b" z: S6 @( q
0 _( i; p5 K7 M! ?
        % computing covariance matrices (S in text)计算协方差矩阵(文本中的S)
  y, |0 N, ]. |- H$ I        covariances = cell(M);
$ i) e- y! |# B* |" x0 o6 n        for i=1:M
% F$ m  {7 _5 s! O1 A            covariances{i} = zeros(d, d);% D2 K3 j9 O5 h& q
            for n=1:N2 M  Z7 H5 {5 f- t, _% E6 t4 o; ]
                covariances{i} = covariances{i} + posteriors(n, i)*(T(n, :)' - new_mus(i, :)')*(T(n, :)' - new_mus(i, :)')';
  U; m$ @) ?5 H2 {4 O% A            end
+ b' `( J0 C: c* `$ J! }9 b            covariances{i} = covariances{i} / (new_priors(i) * N);
5 o. I4 `1 |# g4 u, N, K# Q% `        end* D7 L0 y& a( P# E5 X! B5 g6 |
6 u/ C1 d8 e! o' D* K! p" ^

. h! g' O: }# J7 ]! P; D, i! J        % applying ppca using covariance matrices 使用协方差矩阵应用ppca
! d: O5 t% p" N8 }        % (Ws are weight matrices; sigmas are variances) (Ws为权重矩阵;(差异)* K% v; |  D- i* W+ z8 W' |* `3 p
        new_Ws = cell(M);
" B, |4 |: H% j$ w$ I* q        for i=1:M  \4 v' i% ?& b: X
            [new_Ws{i}, new_sigmas{i}] = ppca_from_covariance(covariances{i}, q);2 C: m- {7 b; m$ ?5 \5 q
        end
6 U* i& f; q" ]1 O: d4 D
9 N5 V) U* i0 `3 E  o        % convergence check 收敛性检查
9 r; B# g2 L9 H$ a9 E        if(entered && max(abs(new_priors - priors)) < epsilon && max(max(abs(new_mus - mus))) < epsilon && max(max(max(abs(cell2mat(new_Ws) - cell2mat(Ws))))) < epsilon && max(abs(new_sigmas - sigmas)) < epsilon)4 H9 A$ x9 w# g' t) l
            break;
. P. B9 N( q% J# {$ B        end1 j( x7 O, W% i% c& ]' y

# R" w/ k( l- b& Q        % replacing old parameter values 替换旧的参数值
8 c" p4 _0 f/ r        priors = new_priors;* s* U# ~! ?0 G2 U0 U) X
        mus = new_mus;
# H5 T; L' O( |: ~: ^  _% I        Ws = new_Ws;& l: p$ \. w! S: w+ t0 \; K
        sigmas = new_sigmas;6 r5 z8 ~+ R0 G0 H" m) X( Z
# U8 H7 E' k4 ]+ ]  p
        % computing the likelihoods (p(t_n|i)) 计算概率(p(t_n|i))
3 U& |6 m# I( J0 w        for i=1:M. z5 H! U  X; K1 S8 ~% M
            C = sigmas{i}^2 * eye(d) + Ws{i}*Ws{i}';$ n! h( o% N: ^
            detC = det(C);
7 o7 V, z2 V1 [2 B* N* ?- l            invC = inv(C);7 T+ l' E4 ^9 h1 Z6 R7 n3 F) o
            for n=1:N8 b" }  R) X: a/ F1 [7 z
                likelihoods(n, i) = (2*pi)^(-d/2)*detC^(-1/2)*exp(-1/2*(T(n, :)' - mus(i, :)')'*invC*(T(n, :)' - mus(i, :)'));: t7 U4 m1 u1 C
            end8 |1 i% d, `8 i& F: @8 Q8 N
        end/ c  c1 K, q; }: A4 r
        % computing the joint probabilities (p(t_n, i)) 计算联合概率(p(t_n, i))2 o0 n* D; c. n3 @% H( x- l
        for i=1:M7 o, j' D9 M7 G3 J4 t! K3 q" X
            joint(:, i) = likelihoods(:, i) * priors(i);
& l+ T6 K$ M& i3 x        end
& B8 P: z' ~" M& i$ M2 {        % computing the data priors (p(t_n)) 计算数据先验(p(t_n))
6 m+ A$ O  g# P0 }9 \        data_priors = sum(joint');
. [( P  J7 m- g4 G3 l, `; x% A        % computing and displaying the likelihood of the data set 计算和显示数据集的可能性
. i  M" o, O+ ^; n        disp(sum(log(data_priors)));+ B! Z( j2 I8 d6 ^5 j" S
        % computing the posteriors (p(i|t_n), indexed by (n, i). R in text)
1 `. o1 h0 q7 H& G, z        % 计算后验(p(i|t_n),用(n, i)索引。R在文本中)% `4 d( P, j9 Q+ P3 }3 P! @9 [
        for n=1:N
+ {7 Y/ C8 h8 p% ?6 ?( S            posteriors(n, :) = joint(n, :) / data_priors(n);
9 l4 Z/ C! C+ Z& U# U6 K: p; }/ V! c        end  }+ a1 m7 D# h' z

3 Z2 A' I) _# |2 ]3 L5 x* q- g        % we went through the loop at least once 我们至少做了一次循环
  N, f. T6 ~4 U' ]  T) B        entered = true;3 _" a, u' z. ^+ T
    end, Z% _; j+ r8 i9 n8 B
2 g/ R) t* O9 _7 c7 e

3 w8 b* \. a) z" p2 k1 M7 o/ e    % computing the latent variables 计算潜变量
3 V5 d: A9 V& Z( ^3 ^) f& P" D    latent = cell(M);9 B( H& f- ]- N7 [
    for i=1:M
1 M' ?. x  E7 V* P7 m" ~        latent{i} = ppca_latent(T, Ws{i}, sigmas(i));. P% s& ~+ s% G" }% r# w' `
    end, G! j" q  G3 C, U! h
    % selecting likely points for each ppca analyser 为每个ppca分析器选择可能的点
% H6 i$ D: W4 |) p    for n=1:N
0 `! K% k6 Z4 k        [~, i] = sort(posteriors(n, :), 'descend');
, o% B  t& A* K& B2 u, v        points_to_classes(n) = i(1);
- s# L2 \. l, _* D, ^    end
, w8 M( F9 K6 n+ ~( _    classes_to_points = cell(M);$ X: c3 P' P6 H: \% N; ?
    classes_to_point_numbers = cell(M);$ y) A$ p' I6 u
    for n=1:N
( v8 s( ]- s6 f. ~7 k% y        classes_to_points{points_to_classes(n)}(:, end+1) = latent{points_to_classes(n)}(:, n);
' N% o4 U9 q1 D. R, O9 Q/ M        classes_to_point_numbers{points_to_classes(n)}(end+1) = n;) d6 T. X/ N$ b( A3 s7 |- T) m
    end
+ Y% c& H) a0 u3 {
0 L* a( v/ I0 u! ?    % display the results of the automatic classification 显示自动分类结果
/ b4 W( t/ S& @2 Z3 }, u* J# X4 D    for i=1:M, A1 w! e9 t: ?8 W2 H
        disp(classes_to_point_numbers{i});; ^; l7 _+ t8 ^, n
    end% F" v  a! j! H) @

' ?# E) J, B. l, G% t5 d    ppca_plot2d(classes_to_points{1});
, X! N( h: _& z) j2 Rend7 U$ |; o& o4 D* B

该用户从未签到

2#
发表于 2020-12-24 13:13 | 只看该作者
帮你顶一下
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-11-24 02:46 , Processed in 0.156250 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表