chainer.functions.gaussian_nll

chainer.functions.gaussian_nll(x, mean, ln_var, reduce='sum')[source]

Computes the negative log-likelihood of a Gaussian distribution.

Given two variable mean representing \(\mu\) and ln_var representing \(\log(\sigma^2)\), this function computes in elementwise manner the negative log-likelihood of \(x\) on a Gaussianx distribution \(N(\mu, S)\),

\[-\log N(x; \mu, \sigma^2) = \log\left(\sqrt{(2\pi)^D |S|}\right) + \frac{1}{2}(x - \mu)^\top S^{-1}(x - \mu),\]

where \(D\) is a dimension of \(x\) and \(S\) is a diagonal matrix where \(S_{ii} = \sigma_i^2\).

The output is a varialbe 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.

Parameters:
  • x (Variable or numpy.ndarray or cupy.ndarray) – Input variable.
  • mean (Variable or numpy.ndarray or cupy.ndarray) – A variable representing mean of a Gaussian distribution, \(\mu\).
  • ln_var (Variable or numpy.ndarray or cupy.ndarray) – A variable representing logarithm of variance of a Gaussian distribution, \(\log(\sigma^2)\).
  • reduce (str) – Reduction option. Its value must be either 'sum' or 'no'. Otherwise, ValueError is raised.
Returns:

A variable representing the negative log-likelihood. If reduce is 'no', the output varialbe 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.

Return type:

Variable