topK static method
Returns the top-k indices sorted by descending probability.
Implementation
static List<int> topK(List<double> values, int k) {
final indexed = List.generate(values.length, (i) => MapEntry(i, values[i]));
indexed.sort((a, b) => b.value.compareTo(a.value));
return indexed.take(k).map((e) => e.key).toList();
}