Topic: Probability and Statistics. Link: https://www.tensortonic.com/problems/bernoulli-pmf
Probability Mass Function:
$$ P (x = 1) = p,\quad P(x = 0) = 1 - p $$
Mean and Variance:
$$ \mu = p,\quad \sigma ^ 2 = p(1 - p) $$
Implement:
import numpy as np
def bernoulli_pmf_and_moments(x, p):
"""
Compute Bernoulli PMF and distribution moments.
"""
inp = np.asarray(x, dtype = int)
pmf = np.where(inp == 1, p, 1 - p)
mean = p
var = (p * (1 - p))
return pmf, mean, var
pass
The Bernoulli distribution is the simplest discrete probability distribution. It models a single experiment with exactly two possible outcomes: 1 or 0 (success of failure)
https://arxiv.org/abs/1708.02002
https://huytranvan2010.github.io/RetinaNet-Understanding/
Topic: Loss Function. Link: https://www.tensortonic.com/problems/binary-focal-loss
Binary focal loss addressed the class imbalance problem in binary classification by down-weighting the loss contribution from easy (well-classified) examples. This allows the model to focus training on hard, misclassified examples. It was introduced in the RetinaNet paper for Object Detection
Compute the probability assigned to the true class:
$$ p_t =\begin{cases}p & \text{if } y = 1 \\1 - p & \text{if } y = 0\end{cases} $$
Compute the focal loss for this sample
$$ \text{FL} = - \alpha \cdot (1 - p) ^ t \cdot ln(p_t) $$