-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResult.java
More file actions
30 lines (27 loc) · 740 Bytes
/
Result.java
File metadata and controls
30 lines (27 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class Result {
public int predicted;
public float[] outputs;
public Result(float[] outputs) {
this.predicted = maxIndex(outputs);
this.outputs = outputs;
}
public int maxIndex(float[] data) {
int index = 0;
float max = data[0];
for (int i = 1; i < data.length; i++) {
if (data[i] > max) {
max = data[i];
index = i;
}
}
return index;
}
public float getCost(float[] predicted) {
float sum = 0;
for (int i = 0; i < predicted.length; i++) {
float diff = outputs[i]-predicted[i];
sum += diff*diff;
}
return (float) Math.sqrt(sum);
}
}