% CDF of the sum of two independent random variables which are distributed
% according to Beta distributions.
%
% Note: When computing multiple values at once, 'betaconv' contains a more
% efficient implementation.
%
% Literature:
% K.H. Brodersen, C.S. Ong, K.E. Stephan, J.M. Buhmann (2010).
% The balanced accuracy and its posterior distribution. In: Proceedings
% of the 20th International Conference on Pattern Recognition.
% Kay H. Brodersen, ETH Zurich, Switzerland
% http://people.inf.ethz.ch/bkay/
% $Id: betasumcdf.m 8246 2010-10-22 13:28:23Z bkay $
% -------------------------------------------------------------------------
function y = betasumcdf(x, alpha1, beta1, alpha2, beta2)
if ~(ndims(x)==2 && (size(x,1)==1 || size(x,2)==1))
error('only implemented for onedimensional input');
end
% Compute the PDF first (since we want the entire pdf rather than just
% one value from it, using betaconv is computationally more efficient
% than using betasumpdf)
res = 0.001;
c = betaconv(res, alpha1, beta1, alpha2, beta2);
% Sum the PDF up to point x
for i=1:length(x)
idx = round(x(i)/res);
if idx < 1
y(i) = 0;
elseif idx > length(c)
y(i) = 1;
else
y(i) = trapz(c(1:idx)) * res;
end
end
end