Solved bug in usage histcount function used in the method: CCREClass.Calc. Now it calculates probability as it should.

Updated the test script
This commit is contained in:
Renken 2020-02-21 16:16:54 +01:00
parent 026a3f589f
commit 8ac21ada83
2 changed files with 18 additions and 7 deletions

View File

@ -58,7 +58,7 @@ classdef CCREClass<CREClass
if isempty(obj.DataRef);return;end %if no refdata given, return;
%calculate histogram for RefData
EVarEpsDataGivenRef=0; %clear previous calculations
[pDataRef,E]=histcounts(obj.DataRef(:),obj.nBinRef,'Normalization','pdf');
[pDataRef,E]=histcounts(obj.DataRef(:),obj.nBinRef,'Normalization','probability');
[JointHist,E1,E2]=histcounts2(obj.Data(:),obj.DataRef(:),[obj.nBin,obj.nBinRef],'Normalization','probability');
for k=1:numel(pDataRef) %loop over the bins in pDataRef NB: must be equal to the bins in JointHist for the Ref
if pDataRef(k)==0;continue;end% if no data at this line go to the next

View File

@ -22,14 +22,25 @@ S.Calc;
S
%% Test CCRE class
figure(1);clf;hold on
A=randn(10);
B=randn(10);
figure(2);clf;
figure(3);clf;hold on;
A=randn(100);
B=A;
B(:)=A(randperm(numel(A)))
for k=-1:0.1:1
CS=CCREClass;
CS.Data=(1-abs(k))*A+k*B;
CS.nBin=100;
CS.Data=1*(1-abs(k))*A+k*B;
CS.nBin=50;
CS.DataRef=B;
CS.nBinRef=50;
CS.nBinRef=500;
CS.Calc;
figure(1);
plot(k,CS.CCRE,'o')
end
plot(k,CS.CRE,'x');
figure(2);
scatter(CS.DataRef(:),CS.Data(:));
figure(3);
plot(k,CS.CCRE./CS.CRE,'d');
pause(0.01)
end
CS