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

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

[复制链接]

该用户从未签到

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

EDA365欢迎您登录!

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

x
高斯混合模型里面的参数可以用到混核主元分析里面吗?有混合概率主元分析的EM算法的程序吗
. r, p2 X4 v3 ifunction ppca_mixture  ! U* d6 g. v1 ^* E$ v$ z4 a
filename = 'virus3.dat';
  B- j* D) K$ y3 i% c    T = importdata(filename);, ^& Z9 U$ ?) X+ @" Y* T
    [N, d] = size(T);
% G' u- H) y3 C- s    M = 3;  % number of ppca analysers considered 考虑的ppca分析仪数量5 {+ ]! `5 U" R3 P5 I. `5 ~
    q = 2;  % dimension of ppcas  ppca的维数0 Y' c  c- `5 X( }. n, ]; K
    % init
( y" t, V1 T) W7 C8 Y/ C    % initializing the posteriors (p(i|t_n), indexed by (n, i). R in text)) t, n& _& o5 q! j
    %初始化后验(p(i|t_n),在文本中由(n, i). R索引     
* n. I& f( x" 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];
& L9 d3 {/ ^; i, x. k0 W2 p. [    for n=1:N
; G  m: s1 ?$ m- @        for i=1:M% M1 o, e: T$ ?9 r1 e, W$ [- J1 m+ c
            if(i==classes(n))  X' v1 V0 |! ?
                posteriors(n, i) = 1;+ L' ]7 i& e% i2 a
            else& S5 ?# C$ R( z# x% j/ m) q
                posteriors(n, i) = 0;+ G9 |6 o4 V, B
            end
% e: B& E" n  P! i        end
% y9 x% l( X. o$ X    end' d$ B+ s2 g2 C; k5 u" |" T& ?
    % precision for convergence checking 收敛检验精度! p: j4 A* o1 P5 z3 {3 ], ^5 d
    epsilon = 0.01;- e3 E/ E6 A- U% T5 f, w# F
    entered = false;+ Y2 \8 O0 x4 ?. c+ y

' E) A/ P1 u& g, m- k/ O    % loop4 J' ~8 Y  N! ~/ C
    while(true)# Z3 J" b) J% r- X& f
        % updating priors (p(i), pi in text) and mean vectors (mu in text)1 `9 o1 a: y, I& u& G
        % 更新先验(p(i),文本中的pi)和平均向量(文本中的mu)
4 m  }/ O; X; _2 K/ A        new_priors = 1/N * sum(posteriors);, x8 i( E% G) c  }: I6 {
        new_mus = zeros(M, d);
1 C9 P; l2 j- b: I' b5 A  O        for i=1:M$ H0 C! x( I; b% a$ W7 \7 q5 l2 E
            for n=1:N$ g1 e$ ?5 w. B! f4 F
                new_mus(i, = new_mus(i, + posteriors(n, i) * T(n, ;% K, `. e2 ]7 |8 K6 M; P! o& K
            end
1 r- E3 X8 I$ l            new_mus(i, :) = new_mus(i, :) / sum(posteriors(:, i));. E/ B+ g/ [0 H  [8 E, c5 w; N1 w
        end& w$ z) L9 H. K; _5 ]3 U
$ s6 `  t! ]# a4 C" a. \
        % computing covariance matrices (S in text)计算协方差矩阵(文本中的S)
3 q; n' O3 K9 v        covariances = cell(M);6 ]8 z7 o! h9 F9 E7 M% ]
        for i=1:M
* U3 X( ?) Q/ d            covariances{i} = zeros(d, d);: u0 ~0 b/ {6 J3 c: W& @
            for n=1:N* A3 ^0 z, _# E, a2 M
                covariances{i} = covariances{i} + posteriors(n, i)*(T(n, :)' - new_mus(i, :)')*(T(n, :)' - new_mus(i, :)')';5 a/ ?+ H, A7 t8 z: S" |8 }, O. W- O
            end
, `/ U9 Y  t. S2 a' F+ m            covariances{i} = covariances{i} / (new_priors(i) * N);! X+ m0 Z4 m, A4 g- u4 ~
        end
8 o: H, P3 h9 R) Y% ~  \" ?0 j8 S6 G& `# t+ j0 z- R

! @: s# V4 K% G1 M- u4 x        % applying ppca using covariance matrices 使用协方差矩阵应用ppca/ o6 P# S. U) t5 K! V" @
        % (Ws are weight matrices; sigmas are variances) (Ws为权重矩阵;(差异)
0 p9 e6 C9 ^- P  C+ Y        new_Ws = cell(M);* h  P( d4 Q+ U' @7 z8 x
        for i=1:M
" c2 l4 k: a* P& m            [new_Ws{i}, new_sigmas{i}] = ppca_from_covariance(covariances{i}, q);
5 a% K& d7 F, c! l# r( Q        end! L1 [# W% @6 l4 ]1 n

& Y/ ?& t4 Y3 b2 @3 B* j        % convergence check 收敛性检查
& b# s3 `) {3 }! p( y3 B. \- X0 I        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)
$ ]. u) F; ^! e2 F            break;' {( o& s. W0 i2 F
        end+ m' t  K* H+ J% K5 p9 w& T) g
- x' w8 T0 v' o4 J6 I
        % replacing old parameter values 替换旧的参数值8 E0 }3 }6 p3 @# V8 Q* b
        priors = new_priors;
8 U6 a: d$ z( |  t8 Q6 |        mus = new_mus;+ r- |2 |6 _! {' S) _1 j" f6 R
        Ws = new_Ws;
: h/ d* Q  i3 {; I7 K        sigmas = new_sigmas;
6 S2 L' N7 q5 B7 L3 r; k/ F/ W$ X- |/ T
        % computing the likelihoods (p(t_n|i)) 计算概率(p(t_n|i))
  A6 [+ O/ W, M) l3 U' l        for i=1:M
. _, K" l: j$ ?+ j8 I; A/ K8 w            C = sigmas{i}^2 * eye(d) + Ws{i}*Ws{i}';
6 f& d% Z$ x2 N3 S$ J" U            detC = det(C);2 Q2 a* }" P1 @& U- U' ?2 Q  R
            invC = inv(C);1 p* D8 k# N2 \5 D5 h. P
            for n=1:N
. p- i1 p1 J- I; [' B                likelihoods(n, i) = (2*pi)^(-d/2)*detC^(-1/2)*exp(-1/2*(T(n, :)' - mus(i, :)')'*invC*(T(n, :)' - mus(i, :)'));- z  X" ~+ o" B! Y" E+ y
            end, L; H7 H2 f* u+ r- W
        end; H* a* j- m% _: Q( G
        % computing the joint probabilities (p(t_n, i)) 计算联合概率(p(t_n, i))( \7 c+ F. C7 l- F
        for i=1:M- i7 D5 h" k" M+ y! X  h3 |
            joint(:, i) = likelihoods(:, i) * priors(i);. [  _# ]: _+ J' Q
        end
2 s& w. o$ @! ]( g( m6 G8 M3 m: ^) F        % computing the data priors (p(t_n)) 计算数据先验(p(t_n))
+ \! k' x& r" ?2 _        data_priors = sum(joint');
- i8 L0 C# `- ]2 Y# U0 p+ s        % computing and displaying the likelihood of the data set 计算和显示数据集的可能性
$ r% ]9 a* M: q        disp(sum(log(data_priors)));
0 {; L1 _$ Z1 d        % computing the posteriors (p(i|t_n), indexed by (n, i). R in text)" R7 Y5 T/ y3 i3 ^
        % 计算后验(p(i|t_n),用(n, i)索引。R在文本中)+ l, @* R5 p( J' c' ^- u
        for n=1:N
8 X! |% v! h* P/ V6 f; s            posteriors(n, :) = joint(n, :) / data_priors(n);
: g' B2 w! [$ u" ~- g6 s        end
& V: I" f8 S/ q. _9 E7 p+ M0 F
4 O% w) b2 D, G( S6 N# a        % we went through the loop at least once 我们至少做了一次循环$ I  i! V* L1 R% u
        entered = true;# [& s% u0 g8 Q) X! J8 ?/ p1 l
    end
" w' f" K3 F1 B$ a: K/ V" F: u: `3 {+ o( m8 X* _8 j# w
& j# F2 R4 S3 w) e6 L; c
    % computing the latent variables 计算潜变量! B2 n& M5 U! Q8 T: c5 o4 h; g
    latent = cell(M);
0 K. G8 s6 ?9 E6 e2 |    for i=1:M* V$ z$ H& ?: h- K( t
        latent{i} = ppca_latent(T, Ws{i}, sigmas(i));
* F! E4 Y) ^+ L2 Y% o" C- A2 i    end
# r+ o4 w* o% t    % selecting likely points for each ppca analyser 为每个ppca分析器选择可能的点
: ^; d8 f8 D" w' |) V9 ]& _7 q    for n=1:N( o9 V" d8 n4 Y) i2 m
        [~, i] = sort(posteriors(n, :), 'descend');' @) W0 J5 e+ R6 F/ n( K$ p
        points_to_classes(n) = i(1);# I& F3 `% x7 V8 u+ e3 L
    end
/ ?7 g/ M6 k0 j/ Y    classes_to_points = cell(M);
# g7 [2 I* S6 t- h    classes_to_point_numbers = cell(M);. J% n' [$ B5 U- w$ D. V( f/ m3 s
    for n=1:N$ l2 w6 i5 r; S. S& B: B# W4 S
        classes_to_points{points_to_classes(n)}(:, end+1) = latent{points_to_classes(n)}(:, n);
4 j, i  o6 s# e        classes_to_point_numbers{points_to_classes(n)}(end+1) = n;( c  f5 u& z* [# j7 U! j5 f6 A5 ~
    end3 h0 q% W  v- E8 c

/ M/ q  d( b) \1 C! n7 w4 q7 i2 l! l+ k    % display the results of the automatic classification 显示自动分类结果
0 T' o! X) M4 t. K- z! Y9 x1 t    for i=1:M
* b5 F9 N* x) ?        disp(classes_to_point_numbers{i});* w6 I% P. H4 R1 r& }( E4 b  L
    end
1 j* {2 k8 a( S* Y6 M8 p
. @6 v3 g3 E; k/ M8 b7 \    ppca_plot2d(classes_to_points{1});# N9 I& @6 P" m- s& ~
end' i& _! G. n' a$ B2 `0 L

该用户从未签到

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

本版积分规则

关闭

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

EDA365公众号

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

GMT+8, 2025-10-6 15:07 , Processed in 0.156250 second(s), 23 queries , Gzip On.

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

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

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