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 6 Weighted Softmax Loss Function—Variant 1 Require: y, y^ y^←exp(y^−max(y^)) y^←y^/∑(y^) grad←zeromatrixwithshapeofy^ hess←zeromatrixwithshapeofy^ weights←{(0,1):0.1,(1,0):0.1,(0,2):0.17,(2,0):0.17,(1,2):0.1,(2,1):0.1} for i=0 to lengthofy−1 do for j=0 to numberofcolumnsiny^−1 do weight←weights[min(y[i],j),max(y[i],j)] if weight is not set then weight←0 end if prob←y^[i,j] grad[i,j]←weight×(prob−(y[i]==j)) hess[i,j]←weight×prob×(1−prob)+0.02 end for end forreturn grad,hess