From 7349e4a2548d5a22bd6f472cb76a7a8434167fc5 Mon Sep 17 00:00:00 2001 From: Mo Chen Date: Mon, 12 Mar 2018 03:11:38 +0800 Subject: [PATCH] minor improvements --- chapter09/linRegEm.m | 10 +++++----- chapter10/linRegVb.m | 2 +- chapter10/rvmRegVb.m | 2 +- chapter14/mixLinReg.m | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/chapter09/linRegEm.m b/chapter09/linRegEm.m index 00280fe..5534bfa 100644 --- a/chapter09/linRegEm.m +++ b/chapter09/linRegEm.m @@ -14,7 +14,7 @@ beta = 0.5; end [d,n] = size(X); - +I = eye(d); xbar = mean(X,2); tbar = mean(t,2); @@ -39,12 +39,12 @@ llh(iter) = 0.5*(d*log(alpha)+n*log(beta)-alpha*m2-beta*e2-logdetA-n*log(2*pi)); % 3.86 if abs(llh(iter)-llh(iter-1)) < tol*abs(llh(iter-1)); break; end - V = inv(U); - trS = dot(V(:),V(:)); % A=inv(S) + invU = U'\I; + trS = dot(invU(:),invU(:)); % A=inv(S) alpha = d/(m2+trS); % 9.63 - UX = U'\X; - trXSX = dot(UX(:),UX(:)); + invUX = U'\X; + trXSX = dot(invUX(:),invUX(:)); beta = n/(e2+trXSX); % 9.68 is wrong end w0 = tbar-dot(m,xbar); diff --git a/chapter10/linRegVb.m b/chapter10/linRegVb.m index 49ba81e..809c3fa 100644 --- a/chapter10/linRegVb.m +++ b/chapter10/linRegVb.m @@ -8,7 +8,6 @@ % model: trained model structure % energy: variational lower bound % Written by Mo Chen (sth4nth@gmail.com). -[m,n] = size(X); if nargin < 3 a0 = 1e-4; b0 = 1e-4; @@ -20,6 +19,7 @@ c0 = prior.c; d0 = prior.d; end +[m,n] = size(X); I = eye(m); xbar = mean(X,2); tbar = mean(t,2); diff --git a/chapter10/rvmRegVb.m b/chapter10/rvmRegVb.m index 2ced2d7..91d073b 100644 --- a/chapter10/rvmRegVb.m +++ b/chapter10/rvmRegVb.m @@ -8,7 +8,6 @@ % model: trained model structure % energy: variational lower bound % Written by Mo Chen (sth4nth@gmail.com). -[m,n] = size(X); if nargin < 3 a0 = 1e-4; b0 = 1e-4; @@ -20,6 +19,7 @@ c0 = prior.c; d0 = prior.d; end +[m,n] = size(X); idx = (1:m)'; dg = sub2ind([m,m],idx,idx); I = eye(m); diff --git a/chapter14/mixLinReg.m b/chapter14/mixLinReg.m index aa530f5..7bf90cb 100644 --- a/chapter14/mixLinReg.m +++ b/chapter14/mixLinReg.m @@ -45,7 +45,6 @@ if abs(llh(iter)-llh(iter-1)) < tol*abs(llh(iter)); break; end end llh = llh(2:iter); -label = max(R,[],1); model.alpha = alpha; % mixing coefficient model.beta = beta; % mixture component precision model.W = W; % linear model coefficent