Skip to content

Instantly share code, notes, and snippets.

@johnolafenwa
Created June 2, 2018 04:04
Show Gist options
  • Select an option

  • Save johnolafenwa/819dedd1c1063e3c7a517c616aa41517 to your computer and use it in GitHub Desktop.

Select an option

Save johnolafenwa/819dedd1c1063e3c7a517c616aa41517 to your computer and use it in GitHub Desktop.
//FUNCTION TO COMPUTE THE MAXIMUM PREDICTION AND ITS CONFIDENCE
public Object[] argmax(float[] array){
int best = -1;
float best_confidence = 0.0f;
for(int i = 0;i < array.length;i++){
float value = array[i];
if (value > best_confidence){
best_confidence = value;
best = i;
}
}
return new Object[]{best,best_confidence};
}
@kiransringeri
Copy link

Hi,
This result came up when I was looking for any existing argmax in Java.
But this code only works for positive numbers right? If the array has zero or any negative numbers, it fails.
Also it doesn't check if the passed array is null or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment