Skip to content

Commit 7349e4a

Browse files
committed
minor improvements
1 parent 7d7c3aa commit 7349e4a

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

chapter09/linRegEm.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
beta = 0.5;
1515
end
1616
[d,n] = size(X);
17-
17+
I = eye(d);
1818
xbar = mean(X,2);
1919
tbar = mean(t,2);
2020

@@ -39,12 +39,12 @@
3939
llh(iter) = 0.5*(d*log(alpha)+n*log(beta)-alpha*m2-beta*e2-logdetA-n*log(2*pi)); % 3.86
4040
if abs(llh(iter)-llh(iter-1)) < tol*abs(llh(iter-1)); break; end
4141

42-
V = inv(U);
43-
trS = dot(V(:),V(:)); % A=inv(S)
42+
invU = U'\I;
43+
trS = dot(invU(:),invU(:)); % A=inv(S)
4444
alpha = d/(m2+trS); % 9.63
4545

46-
UX = U'\X;
47-
trXSX = dot(UX(:),UX(:));
46+
invUX = U'\X;
47+
trXSX = dot(invUX(:),invUX(:));
4848
beta = n/(e2+trXSX); % 9.68 is wrong
4949
end
5050
w0 = tbar-dot(m,xbar);

chapter10/linRegVb.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
% model: trained model structure
99
% energy: variational lower bound
1010
% Written by Mo Chen (sth4nth@gmail.com).
11-
[m,n] = size(X);
1211
if nargin < 3
1312
a0 = 1e-4;
1413
b0 = 1e-4;
@@ -20,6 +19,7 @@
2019
c0 = prior.c;
2120
d0 = prior.d;
2221
end
22+
[m,n] = size(X);
2323
I = eye(m);
2424
xbar = mean(X,2);
2525
tbar = mean(t,2);

chapter10/rvmRegVb.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
% model: trained model structure
99
% energy: variational lower bound
1010
% Written by Mo Chen (sth4nth@gmail.com).
11-
[m,n] = size(X);
1211
if nargin < 3
1312
a0 = 1e-4;
1413
b0 = 1e-4;
@@ -20,6 +19,7 @@
2019
c0 = prior.c;
2120
d0 = prior.d;
2221
end
22+
[m,n] = size(X);
2323
idx = (1:m)';
2424
dg = sub2ind([m,m],idx,idx);
2525
I = eye(m);

chapter14/mixLinReg.m

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
if abs(llh(iter)-llh(iter-1)) < tol*abs(llh(iter)); break; end
4646
end
4747
llh = llh(2:iter);
48-
label = max(R,[],1);
4948
model.alpha = alpha; % mixing coefficient
5049
model.beta = beta; % mixture component precision
5150
model.W = W; % linear model coefficent

0 commit comments

Comments
 (0)