forked from PRML/PRMLT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refined doc for common and other functions
- Loading branch information
Showing
15 changed files
with
19 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function [Q, R] = gsog(X) | ||
% Gram-Schmidt orthogonalization | ||
% Written by Mo Chen ([email protected]). | ||
[d,n] = size(X); | ||
m = min(d,n); | ||
R = eye(m,n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function [Q, R] = gson(X) | ||
% Gram-Schmidt orthonormalization which produces the same result as [Q,R]=qr(X,0) | ||
% Written by Mo Chen ([email protected]). | ||
[d,n] = size(X); | ||
m = min(d,n); | ||
R = zeros(m,n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
function W = invpd(M) | ||
% Compute A\B where A is a positive definite matrix | ||
% A: a positive difinie matrix | ||
% Input: | ||
% M: a positive difinie matrix | ||
% Written by Michael Chen ([email protected]). | ||
[U,p] = chol(M); | ||
if p > 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
function s = logsumexp(X, dim) | ||
% Compute log(sum(exp(X),dim)) while avoiding numerical underflow. | ||
% By default dim = 1 (columns). | ||
% Written by Michael Chen ([email protected]). | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 1, | ||
% Determine which dimension sum will use | ||
dim = find(size(X)~=1,1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function [Q, R] = mgsog(X) | ||
% Modified Gram-Schmidt orthogonalization | ||
% Written by Mo Chen ([email protected]). | ||
[d,n] = size(X); | ||
m = min(d,n); | ||
R = eye(m,n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
function [Q, R] = mgson(X) | ||
% Modified Gram-Schmidt orthonormalization (numerical stable version of Gram-Schmidt algorithm) | ||
% which produces the same result as [Q,R]=qr(X,0) | ||
% Written by Mo Chen ([email protected]). | ||
[d,n] = size(X); | ||
m = min(d,n); | ||
R = zeros(m,n); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
function V = solvpd(A,B) | ||
% Compute A\B where A is a positive definite matrix | ||
% A: a positive difinie matrix | ||
% Written by Michael Chen ([email protected]). | ||
% Written by Mo Chen ([email protected]). | ||
[U,p] = chol(A); | ||
if p > 0 | ||
error('ERROR: the matrix is not positive definite.'); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
function [Y, s] = standardize(X) | ||
% Unitize the vectors to be unit length | ||
% By default dim = 1 (columns). | ||
% Written by Michael Chen ([email protected]). | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 1, | ||
% Determine which dimension sum will use | ||
dim = find(size(X)~=1,1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
% Compute eigenvalues and eigenvectors of symmetric matrix | ||
% m == 's' smallest (default) | ||
% m == 'l' largest | ||
% Written by Michael Chen ([email protected]). | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 2 | ||
m = 's'; | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function [U, D] = ud(X) | ||
% UD factorization U'*D*U=X'*X; | ||
% Written by Mo Chen ([email protected]). | ||
[~,R] = qr(X,0); | ||
d = diag(R); | ||
D = d.^2; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
function [Y, s] = unitize(X, dim) | ||
% Unitize the vectors to be unit length | ||
% By default dim = 1 (columns). | ||
% Written by Michael Chen ([email protected]). | ||
% Written by Mo Chen ([email protected]). | ||
if nargin == 1, | ||
% Determine which dimension sum will use | ||
dim = find(size(X)~=1,1); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function r = loggmpdf(X, model) | ||
|
||
% Compute log pdf of a Gaussian mixture model. | ||
% Written by Mo Chen ([email protected]). | ||
mu = model.mu; | ||
Sigma = model.Sigma; | ||
w = model.weight; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
function plotgm(X, model) | ||
% Written by Michael Chen ([email protected]). | ||
% Plot 2d Gaussian mixture model. | ||
% Written by Mo Chen ([email protected]). | ||
level = 64; | ||
n = 256; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
function plotkde(X, sigma2) | ||
% Written by Michael Chen ([email protected]). | ||
|
||
% Plot 2d kernel density. | ||
% Written by Mo Chen ([email protected]). | ||
if nargin < 2 | ||
sigma2 = 1e-1; | ||
end | ||
|