4 Star 11 Fork 2

叶夜笙歌 / FastICA

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
whitenv.m 2.78 KB
一键复制 编辑 原始数据 按行查看 历史
叶夜笙歌 提交于 2014-03-30 17:35 . FastICA盲源分离算法DEMO
function [newVectors, whiteningMatrix, dewhiteningMatrix] = whitenv ...
(vectors, E, D, s_verbose);
%WHITENV - Whitenv vectors.
%
% [newVectors, whiteningMatrix, dewhiteningMatrix] = ...
% whitenv(vectors, E, D, verbose);
%
% Whitens the data (row vectors) and reduces dimension. Returns
% the whitened vectors (row vectors), whitening and dewhitening matrices.
%
% ARGUMENTS
%
% vectors Data in row vectors.
% E Eigenvector matrix from function 'pcamat'
% D Diagonal eigenvalue matrix from function 'pcamat'
% verbose Optional. Default is 'on'
%
% EXAMPLE
% [E, D] = pcamat(vectors);
% [nv, wm, dwm] = whitenv(vectors, E, D);
%
%
% This function is needed by FASTICA and FASTICAG
%
% See also PCAMAT
% @(#)$Id: whitenv.m,v 1.3 2003/10/12 09:04:43 jarmo Exp $
% ========================================================
% Default value for 'verbose'
if nargin < 4, s_verbose = 'on'; end
% Check the optional parameter verbose;
switch lower(s_verbose)
case 'on'
b_verbose = 1;
case 'off'
b_verbose = 0;
otherwise
error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose));
end
% ========================================================
% In some cases, rounding errors in Matlab cause negative
% eigenvalues (elements in the diagonal of D). Since it
% is difficult to know when this happens, it is difficult
% to correct it automatically. Therefore an error is
% signalled and the correction is left to the user.
if any (diag (D) < 0),
error (sprintf (['[ %d ] negative eigenvalues computed from the' ...
' covariance matrix.\nThese are due to rounding' ...
' errors in Matlab (the correct eigenvalues are\n' ...
'probably very small).\nTo correct the situation,' ...
' please reduce the number of dimensions in the' ...
' data\nby using the ''lastEig'' argument in' ...
' function FASTICA, or ''Reduce dim.'' button\nin' ...
' the graphical user interface.'], ...
sum (diag (D) < 0)));
end
% ========================================================
% Calculate the whitening and dewhitening matrices (these handle
% dimensionality simultaneously).
whiteningMatrix = inv (sqrt (D)) * E';
dewhiteningMatrix = E * sqrt (D);
% Project to the eigenvectors of the covariance matrix.
% Whiten the samples and reduce dimension simultaneously.
if b_verbose, fprintf ('Whitening...\n'); end
newVectors = whiteningMatrix * vectors;
% ========================================================
% Just some security...
if ~isreal(newVectors)
error ('Whitened vectors have imaginary values.');
end
% Print some information to user
if b_verbose
fprintf ('Check: covariance differs from identity by [ %g ].\n', ...
max (max (abs (cov (newVectors', 1) - eye (size (newVectors, 1))))));
end
Matlab
1
https://gitee.com/a_bad_geek/FastICA.git
git@gitee.com:a_bad_geek/FastICA.git
a_bad_geek
FastICA
FastICA
master

搜索帮助