CRE_RB_and_CCRE/TestCREClass.m

89 lines
2.2 KiB
Matlab

%% Test CCRE and CRE class
% show some default behaviour
% and test the error handling.
%% set some constants
A=randn(100);
%% create instance of CRE class
S1=CREClass;
%% Calculate by setting labda equal to each of the (unique) values in the data.
S1.UseHistProxyFlag=false;
S1.EqualSizeBinFlag=false;
S1.Data=A;% set gaussian data
S1.Calc;
disp(S1)
%% use histogram aproximation with unequal bin sizes in the histogram
S2=CREClass;
S2.UseHistProxyFlag=true;
S2.EqualSizeBinFlag=false;
S2.Data=A;% set gaussian data
S2.nBin=numel(A); % set nbin to npoints; This is fine as we use the cummulative distribution and the formulas as defined in Zografos
S2.Calc
disp(S2)
%% use histogram aproximation with equal bin sizes in the histogram
S3=CREClass;
S3.UseHistProxyFlag=true;
S3.EqualSizeBinFlag=false;
S3.Data=A;% set gaussian data
S3.nBin=numel(A); % set nbin to npoints; This is fine as we use the cummulative distribution and the formulas as defined in Zografos
S3.Calc
disp(S3)
%% Check recalculation of edges
S4=CREClass;
S4.UseHistProxyFlag=true;
S4.EqualSizeBinFlag=true;
S4.Data=A;% set gaussian data
S4.nBin=numel(A); % set nbin to npoints; This is fine as we use the cummulative distribution and the formulas as defined in Zografos
S4.Calc
disp(S4)
S4.nBin=numel(A)/10;
S4.CalcEdges ; % force a recalculation of the edges
S4.Calc;
disp(S4)
%% Show effect of scaling or ofsett the data
% Scale
S.Data=100*A;
S.UseHistProxyFlag=true;
S.Calc;
disp(S);
% Offset
S.Data=A+10;
S.UseHistProxyFlag=true;
S.Calc;
disp(S);
%%
%% Test CCRE class
figure(1);clf;hold on
figure(2);clf;
figure(3);clf;hold on;
A=randn(100);
B=A;
B(:)=A(randperm(numel(A)));
w=-1:0.1:1;
out(numel(w),1)=struct('w',[],'CRE',[],'CCRE',[],'R',[]);
for k=1:numel(w)
out(k).w=w(k);
CS=CCREClass;
CS.EqualSizeBinFlag=false;
CS.Data=1*(1-abs(w(k)))*A+w(k)*B;
CS.nBin=50;
CS.DataRef=B;
CS.nBinRef=500;
CS.Calc;
out(k).CRE=CS.CRE;
out(k).CCRE=CS.CCRE;
out(k).R=CS.CCRE./CS.CRE;
figure(2);
title(sprintf('w: %d',w(k)));
scatter(CS.DataRef(:),CS.Data(:));
snapnow
end
disp(CS);
figure(1);
clf;hold on;
plot([out(:).w],[out(:).CCRE],'o');
plot([out(:).w],[out(:).CRE],'x');
figure(3);clf
plot([out(:).w],[out(:).R],'d');