IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
assert_standardized.m
Go to the documentation of this file.
1 %>@ingroup misc assert
2 %>@file
3 %>@brief Checks whether the columns of X have mean zero and variance 1 up to a certain tolerance.
4 %>
5 %> For instance, if tolerance is 0.02, -0.02 <= mean <= 0.02, and 0.98 <= variance <= 1.02 will be accepted.
6 %
7 %> @param X Input matrix
8 %> @param tolerance =0.001 Tolerance
9 %> @return Nothing. If fails, wil generate an error.
10 function assert_standardized(X, tolerance)
11 if nargin < 2 || isempty(tolerance)
12  tolerance = 0.001;
13 end;
14 vv = var(X, 1);
15 [v, i] = max(abs(vv-1)); % Maximum absolute deviation around 1
16 if v > tolerance
17  irerror(sprintf('Invalid variable variance! Expecting: 1; found: %g', vv(i)));
18 end;
19 
20 mm = max(abs(mean(X)));
21 
22 if mm > tolerance
23  irerror(sprintf('Invalid variable mean! Expecting: 0; found: %g', mm));
24 end;
function irerror(in s)
function assert_standardized(in X, in tolerance)