Created
June 2, 2018 04:04
-
-
Save johnolafenwa/819dedd1c1063e3c7a517c616aa41517 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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}; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.