Skip to main content
. 2024 Feb 7;24(4):1092. doi: 10.3390/s24041092
Algorithm 9 Adaptive Weighted Softmax Loss with Focal Modification
  • Require:  y,y^,gamma=2

  • Compute y^ using the softmax transformation

  • Initialize grad and hess as zero matrices of the same shape as y^

  • Compute adaptive weights using y and y^

  • for i=0 to len(y)1 do

  •     for j=0 to columns(y^)1 do

  •         weight weight for the pair (min(y[i],j),max(y[i],j))

  •         proby^[i,j]

  •         focal_mod(1prob)gamma

  •         grad[i,j]focal_mod×weight×(prob(y[i]==j))

  •         hess[i,j]focal_mod×weight×prob×(1prob)+0.02

  •     end for

  • end forreturn  grad,hess