Reputation: 379
I develop a gesture App. For this I need to have the highest score value of the drawn gesture.
So I actually have got 5 different double score values, like this:
06-04 00:38:34.605 21423-21423/de.gestureanywhere D/score﹕ score 3.6936744465393905|GOF2
06-04 00:38:34.605 21423-21423/de.gestureanywhere D/score﹕ score 2.021340609760623|Uhr
06-04 00:38:34.610 21423-21423/de.gestureanywhere D/score﹕ score 1.942381354120031|Spare Parts
06-04 00:38:34.610 21423-21423/de.gestureanywhere D/score﹕ score 1.1174127455877019|Screenshot Leicht
06-04 00:38:34.610 21423-21423/de.gestureanywhere D/score﹕ score 1.025620059028788|Shell
How to programmatically get the highest double value of prediction.score
of These values (so in this example 3.69)?
Thanks for helping
Upvotes: 0
Views: 73
Reputation: 126493
Use:
Double.MAX_VALUE
http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#MAX_VALUE
A constant holding the largest positive finite value of type double, (2-2-52)·21023. It is equal to the hexadecimal floating-point literal 0x1.fffffffffffffP+1023 and also equal to Double.longBitsToDouble(0x7fefffffffffffffL).
List<double[]> values = new ArrayList<double[]>();
values.add(new double[] {3.6936744465393905});
values.add(new double[] {2.021340609760623});
values.add(new double[] {1.942381354120031});
values.add(new double[] {1.1174127455877019});
values.add(new double[] {1.025620059028788});
double min=Double.MAX_VALUE, max=Double.MIN_VALUE;
for (double[] ds : values) {
for (double d : ds) {
if (d > max) max=d;
if (d < min ) min=d;
}
}
Log.i(TAG," Max value is: " + max);
Upvotes: 2
Reputation: 141
If you have the values in a list...
public double getMaxValue(List<Double> values){
double maxValue = Double.MIN_VALUE;
for(Double d : values){
maxValue = d > maxValue ? d : maxValue;
}
}
or if concerned about performance...
public double getMaxValue(List<Double> values){
double maxValue = Double.MIN_VALUE;
for(Double d : values){
if(d > maxValue){
d = maxValue
}
}
}
The first one makes always an assignation, meanwhile the second one only if the new value is greater than the old value.
Upvotes: 2