99 lines
4.2 KiB
Matlab
99 lines
4.2 KiB
Matlab
classdef CCREClass<CREClass
|
|
%CCRECLASS calculate the Conditional Cummulative Residual Entropy
|
|
% This class uses the CREClass options
|
|
%
|
|
|
|
properties
|
|
%the data field inherited from the CREClass will contain the data
|
|
%to calculate the CCRE on.
|
|
%the nBin field inherited from the CREClass will contain the number
|
|
%of bins if UseHistProxy is set.
|
|
end
|
|
properties
|
|
DataRef %This parameter will contain the reference set.
|
|
nBinRef %number of "bins" to use for the reference distribution
|
|
EqualSizeBinFlagRef=false; %set to true to get equally spaced bins, default : false, put an equal number of points per bin.
|
|
EdgesRef; %edges for the bins of the reference function. %todo, turn into dep. variable!
|
|
end
|
|
properties(SetAccess=private) %make read only
|
|
CCRE %parameter containing the conditional Cumulative Residual Entropy
|
|
end
|
|
properties(Constant)
|
|
UseHistProxyFlagRef=true; % this value is there to remind the user that we will have to bin the reference image. The actual value is not used in the code
|
|
end
|
|
|
|
methods %constructor
|
|
function obj = CCREClass()
|
|
%CCRECLASS Construct an instance of this class
|
|
% Detailed explanation goes here
|
|
obj@CREClass;
|
|
end
|
|
end
|
|
methods %set and get functions
|
|
function set.DataRef(obj,val)
|
|
if isnumeric(val)
|
|
obj.DataRef=val;
|
|
else
|
|
error('please enter numeric array/matrix as reference');
|
|
end
|
|
end
|
|
function set.nBinRef(obj,val)
|
|
nBinFromCRE=obj.nBin; %park the current value of nBin
|
|
obj.nBin=val; %use the check system from CREClass
|
|
obj.nBinRef=obj.nBin;
|
|
obj.nBin=nBinFromCRE; %restore the current value of nBin
|
|
end
|
|
end
|
|
methods %user callable functions
|
|
function CalcEdgesRef(obj)
|
|
% copy the info for "ref" to a CRE object
|
|
Stmp=CREClass('ref',obj.DataRef...
|
|
,'nbin',obj.nBinRef...
|
|
,'EqualSizeBinFlag',obj.EqualSizeBinFlagRef...
|
|
,'UseHistProxyFlag',obj.UseHistProxyFlagRef...
|
|
);
|
|
Stmp.CalcEdges;
|
|
obj.EdgesRef=Stmp.Edges;
|
|
end
|
|
%% CCRE A|B
|
|
%
|
|
% $$CCRE = \varepsilon (A) - E[\varepsilon(A|B)]$$
|
|
%
|
|
% $$\varepsilon(A) = -\sum_{\lambda}F_c^A(\lambda)logF_c(A^(\lambda)$$
|
|
% $$F_c^A(\lambda)=\int_{\lambda}^{\infty}p^A(l)dl$$
|
|
%
|
|
% $$E[\varepsilon(A|B)]= \sigma_{\kappa} p^B(\kappa)*\varepsilon(A|B)$$
|
|
%
|
|
% $$\varepsilon(A|B) = \sigma_{\lambda}F_c^{A|B}(\lambda)log
|
|
% F_c^{A|B}(\lambda)$$
|
|
%
|
|
% $$F_c^{A|B}(\lambda) = \int_{\lambda}^{\infty}p^{A,B}(l,k)/p^B(\kappa)dl$$
|
|
%
|
|
% see equation 7 in wan and Vemuri
|
|
function Calc(obj)
|
|
Calc@CREClass(obj); %calculate the CRE for the data.
|
|
if isempty(obj.DataRef);return;end %if no refdata given, return;
|
|
%calculate histogram for RefData
|
|
EVarEpsDataGivenRef=0; %clear previous calculations
|
|
%get the edge definition.
|
|
% a bit of a workaround, I don't plan to reprogram the function
|
|
if isempty(obj.EdgesRef)
|
|
obj.CalcEdgesRef;
|
|
end
|
|
[pDataRef,E]=histcounts(obj.DataRef(:),obj.EdgesRef,'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
|
|
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('data',obj.Data(ind)...
|
|
,'nbin',obj.Edges...
|
|
);
|
|
CRE_DataGivenDataRef.Calc;
|
|
EVarEpsDataGivenRef=EVarEpsDataGivenRef+pDataRef(k)*CRE_DataGivenDataRef.CRE; % I really have to check this line on merit.
|
|
end
|
|
obj.CCRE=obj.CRE-EVarEpsDataGivenRef;
|
|
|
|
end
|
|
end
|
|
end
|
|
|