Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to standardize data before obtaining shrinkage gamma #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions classification/utils/clsutil_shrinkage.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
% 'C' (common covariance)
% 'D' (diagonal, unequal variance)
% 'Gamma': DOUBLE - Shrinkage parameter. May be used to set the shrinkage parameter explicitly.
% 'Standardize': BOOL (default 0) - If set, standardizes dimensions before calculating optimal
% Shrinkage gamma. The obtained covariance matrix is scaled back into the
% original feature range.
% 'Verbose': BOOL (default 0) - If set, verbose mode is activated
%
%Returns:
Expand Down Expand Up @@ -44,9 +47,10 @@
% opt-type checking (Michael Tangermann)


props= {'Target' 'B' 'CHAR(A B C D)'
'Gamma' 'auto' 'CHAR(auto)|!DOUBLE'
'Verbose' 0 'BOOL'};
props= {'Target' 'B' 'CHAR(A B C D)'
'Gamma' 'auto' 'CHAR(auto)|!DOUBLE'
'Standardize' 0 'BOOL'
'Verbose' 0 'BOOL'};

if nargin==0,
Cstar= props;
Expand All @@ -66,6 +70,9 @@

%%% Empirical covariance
[p, n] = size(X);
if opt.Standardize
[X, ~, z_sigma] = zscore(X, 0, 2);
end
Xn = X - repmat(mean(X,2), [1 n]);
S = Xn*Xn';
Xn2 = Xn.^2;
Expand Down Expand Up @@ -112,3 +119,6 @@

%%% Estimate covariance matrix
Cstar = (gamma*T + (1-gamma)*S ) / (n-1);
if opt.Standardize
Cstar = (z_sigma * z_sigma') .* Cstar;
end