# 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', loss values are summed up.

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: x (Variable or numpy.ndarray or cupy.ndarray) – Input variable. y (Variable or numpy.ndarray or cupy.ndarray) – A variable representing the parameter of Bernoulli distribution. reduce (str) – Reduction option. Its value must be either 'sum' or 'no'. Otherwise, ValueError is raised. 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', the output variable holds a scalar value. Variable