src.model.deeplearn.loss.class_weighted_binary_crossentropy
Functions
Function to compute a weighted binary cross-entropy loss. |
- src.model.deeplearn.loss.class_weighted_binary_crossentropy.vl3d_class_weighted_binary_crossentropy(class_weight)
Function to compute a weighted binary cross-entropy loss.
Let \(\mathcal{L}(\pmb{y}, \pmb{\hat{y}}) \in \mathbb{R}^{m}\) be a binary crossentropy loss on \(m\) samples. Now, let \(\pmb{w} \in \mathbb{R}^2\) be a vector of class weights for binary classification, i.e., two classes. Thus, it is possible to define a vector \(\pmb{\omega} \in \mathbb{R}^{m}\) such that \(\omega_{i} = y_i w_2 + (1-y_i) w_1\), where any \(y_i\) must be either zero or one. For then, the class weighted binary crossentropy can be obtained simply by computing the following Hadamard Product (where \(\pmb{\hat{y}}\) is the vector of binary predictions):
\[\mathcal{L}(\pmb{y}, \pmb{\hat{y}}) \odot \pmb{\omega}\]- Parameters:
class_weight – The vector of class weights. The component i of this vector (\(\pmb{w}\)) is the weight for class i.
- Returns:
The weighted binary cross entropy loss.