softMax method
Returns the index of the maximum value in the prediction list using the softmax function.
The softmax function takes a list of double values and returns a probability distribution over the elements by exponentiating each value and normalizing it by the sum of all exponentiated values.
The prediction
parameter is a list of double values representing the predicted scores
for each class.
Returns the index of the maximum value in the prediction list.
Implementation
int softMax(List<double?> prediction) {
double maxScore = double.negativeInfinity;
int maxScoreIndex = -1;
for (int i = 0; i < prediction.length; i++) {
if (prediction[i]! > maxScore) {
maxScore = prediction[i]!;
maxScoreIndex = i;
}
}
return maxScoreIndex;
}