All problems
Focal Loss Gamma Reduction
Problem
Compute how much focal loss reduces the mean cross-entropy. Use mean CE minus mean focal loss with focusing parameter gamma and alpha 1, where p_t is p for y = 1 and 1 - p otherwise, with probabilities clipped to [1e-15, 1 - 1e-15]. Return 0.0 for empty input.
Hint
A larger gamma focuses more of the loss on hard, misclassified examples.
Test cases
case 1
in: [[1,0],[0.9,0.9],2]
expected: 0.2708990390850584
case 2
in: [[1,1],[0.6,0.6],0]
expected: 0
case 3
in: [[0,1],[0.3,0.3],1]
expected: 0.3054321510274468
case 4
in: [[],[],2]
expected: 0
Starter codePython
import math
def focal_gamma_reduction(y_true, probs, gamma):
# Your code here
pass4 test cases · run your code against them in the editor