src.model.deeplearn.loss.class_weighted_categorical_crossentropy

Functions

vl3d_class_weighted_categorical_crossentropy(...)

Function to compute a weighted categorical cross-entropy loss.

src.model.deeplearn.loss.class_weighted_categorical_crossentropy.vl3d_class_weighted_categorical_crossentropy(class_weight)

Function to compute a weighted categorical cross-entropy loss.

Let \(\mathcal{L}(\pmb{y}, \pmb{\hat{y}}) \in \mathbb{R}^{m}\) be a categorical crossentropy loss on \(m\) samples. Now, let \(\pmb{w} \in \mathbb{R}^n\) be a vector of class weights for multiclass classification, i.e., potentially many classes. Thus, it is possible to define a vector \(\pmb{\omega} \in \mathbb{R}^{m}\) such that \(\omega_i = \langle{\pmb{w}, \pmb{y}}\rangle\), where any \(y_j\) must be either zero or one for \(j=1,\ldots,n\). For then, the class weighted categorical crossentropy can be obtained simply by computing the following Hadamard Product (where \(\pmb{\hat{y}}\) is the vector of one-hot-encoded multiclass 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 categorical cross entropy loss