mlnext.score.bern_log_likelihood

mlnext.score.bern_log_likelihood(x: ndarray, mean: ndarray) ndarray[source]

Calculates the log likelihood of x being produced by a bernoulli distribution parameterized by mean.

\[LL(x|\text{mean}) = x \cdot \log(\text{mean}) + (1 - x) \cdot \log(\text{mean})\]
Parameters:
  • x (np.ndarray) – Samples.

  • mean (np.ndarray) – Mean of the bernoulli distribution.

Returns:

Returns the negative log likelihood.

Return type:

np.ndarray

Example

>>> import numpy as np
>>> from mlnext import bern_log_likelihood
>>> bern_log_likelihood(
>>>     np.array([1, 0, 1]),
>>>     mean=np.array([0.2, 0.1, 0.8]),
>>> )
array([1.60943791, 0.10536052, 0.22314355])