Skip to main content
. 2024 Feb 7;24(4):1092. doi: 10.3390/s24041092
Algorithm 8 Compute Adaptive Weights
  • Require:  y,y^,focus_pairs,focus_multiplier

  • n_classescolumns(y^)

  • Initialize class_errors as a zero vector of length n_classes

  • for i=0 to n_classes1 do

  •     class_indices indices where y=i

  •     class_errors[i] mean absolute error of y^[class_indices,i] from 1

  • end for

  • Normalize class_errors by its maximum value

  • Initialize weights as an empty dictionary

  • for i=0 to n_classes1 do

  •     for j=i to n_classes1 do

  •         if i=j then

  •            weights[(i,j)]0.1+0.1×class_errors[i]

  •         else

  •            avg_error(class_errors[i]+class_errors[j])/2

  •            weights[(i,j)]weights[(j,i)]avg_error

  •            if (i,j) in focus_pairs or (j,i) in focus_pairs then

  •                weights[(i,j)]weights[(j,i)]avg_error×focus_multiplier

  •            end if

  •         end if

  •     end for

  • end forreturn  weights