function X = internal_bincrossentropy(X, T, observationDim)
% This function is undocumented and will change in a future release.

% internal_bincrossentropy    Return the binary cross-entropy between
% estimates X and true responses T averaged by the number of observations
%
% Syntax:
%   Y = internal_bincrossentropy(X, T, observationDim);
%
% Inputs (image):
%   X              Predictions made by network
%   T              Targets (actual values)
%   observationDim Index of the observations dimension

%   Copyright 2019-2020 The MathWorks, Inc.

N = size(X, observationDim);
OneMinusX = nnet.internal.cnn.util.boundAwayFromZero(1-X);
X = nnet.internal.cnn.util.boundAwayFromZero(X);
X = -sum(T.*log(X),'all')/N - sum((1 - T).* log(OneMinusX), 'all')/N;

end
