Allow for constant log(dFC) across bins. i.e. all bins will contain (approximately) and equal number of datum points.

In other words binsize for the refence is adapted such that the number of points per bin is equal.
This commit is contained in:
R.J. Renken 2022-03-25 16:06:59 +01:00
parent 2274e88690
commit 3998755f40
1 changed files with 15 additions and 5 deletions

View File

@ -11,8 +11,11 @@ classdef CCREClass<CREClass
end
properties
DataRef %This parameter will contain the reference set.
nBinRef
nBinRef %number of "bins" to use for the reference distribution
CCRE %parameter containing the conditional Cumulative Residual Entropy
EquidistantBinFlag=true; % set to true to get equidistant bins, set to false to get equi-content bins,
% if set to false: each bin will contain (aproximately) an equal
% number of pixel values.
end
methods %constructor
@ -58,14 +61,21 @@ 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','probability');
[JointHist,E1,E2]=histcounts2(obj.Data(:),obj.DataRef(:),[obj.nBin,obj.nBinRef],'Normalization','probability');
if obj.EquidistantBinFlag
[pDataRef,E]=histcounts(obj.DataRef(:),obj.nBinRef,'Normalization','probability');
[JointHist,E1,E2]=histcounts2(obj.Data(:),obj.DataRef(:),[obj.nBin,obj.nBinRef],'Normalization','probability'); %obtain bin edges for Target
else
prc=linspace(0,100,obj.nBinRef+1); % define the edges of the bins as a precentile
Edges=prctile(obj.DataRef(:),prc);
[pDataRef,E]=histcounts(obj.DataRef(:),Edges,'Normalization','probability');
[JointHist,E1,E2]=histcounts2(obj.Data(:),obj.DataRef(:),[obj.nBin,obj.nBinRef],'Normalization','probability'); %obtain bin edges for Target
end
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
ind=E(k)<=obj.DataRef(:)&obj.DataRef(:)<E(k+1);
ind=E(k)<=obj.DataRef(:)&obj.DataRef(:)<E(k+1); %get an index to all points in Ref data inside the current bin
CRE_DataGivenDataRef=CREClass;
CRE_DataGivenDataRef.Data=obj.Data(ind);
CRE_DataGivenDataRef.nBin=E1;
CRE_DataGivenDataRef.nBin=E1; %force the same bin definition for all itterations. This value is ignored if UseHistProxy is set to false
CRE_DataGivenDataRef.Calc;
EVarEpsDataGivenRef=EVarEpsDataGivenRef+pDataRef(k)*CRE_DataGivenDataRef.CRE; % I really have to check this line on merit.
end