chainer.functions.bernoulli_nll

chainer.functions.bernoulli_nll(x, y, reduce='sum')[source]

Computes the negative log-likelihood of a Bernoulli distribution.

This function calculates the negative log-likelihood of a Bernoulli distribution.

\[-\log B(x; p) = -\sum_i \{x_i \log(p_i) + (1 - x_i)\log(1 - p_i)\},\]

where \(p = \sigma(y)\), \(\sigma(\cdot)\) is a sigmoid function, and \(B(x; p)\) is a Bernoulli distribution.

The output is a variable whose value depends on the value of the option reduce. If it is 'no', it holds the elementwise loss values. If it is 'sum' or 'mean', loss values are summed up or averaged respectively.

Note

As this function uses a sigmoid function, you can pass a result of fully-connected layer (that means Linear) to this function directly.

Parameters
Returns

A variable representing the negative log-likelihood. If reduce is 'no', the output variable holds array whose shape is same as one of (hence both of) input variables. If it is 'sum' or 'mean', the output variable holds a scalar value.

Return type

Variable