View full-text article in PMC Sensors (Basel). 2024 Feb 7;24(4):1092. doi: 10.3390/s24041092 Search in PMC Search in PubMed View in NLM Catalog Add to search Copyright and License information © 2024 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/). PMC Copyright notice Algorithm 7 Weighted Softmax Loss with Edge Penalty Require: y,y^ Initialize grad and hess as zero matrices of the same shape as y^ Define class pair weights Set extra_penalty←1.2 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)) prob←y^[i,j] penalty←extra_penalty if y[i] or j is an edge class, else 1 grad[i,j]←penalty×weight×(prob−(y[i]==j)) hess[i,j]←penalty×weight×prob×(1−prob)+0.02 end for end forreturn grad,hess