Skip to content
Snippets Groups Projects
Commit 15534c3d authored by a.croix's avatar a.croix
Browse files

Change float to double in some function + writting Utils function

parent 3b757ecb
No related branches found
No related tags found
No related merge requests found
Pipeline #1005 failed
......@@ -2,8 +2,8 @@ package be.cylab.java.wowa.training;
public class SolutionDistance {
private float weights_w[];
private float weights_p[];
private double[] weights_w;
private double[] weights_p;
private double distance = Double.POSITIVE_INFINITY;
public float computeScoreTo() {
......@@ -21,4 +21,16 @@ public class SolutionDistance {
public static void sort(SolutionDistance[]) {
}
public double[] getWeights_w() {
return weights_w;
}
public double[] getWeights_p() {
return weights_p;
}
public double getDistance() {
return distance;
}
}
......@@ -5,31 +5,47 @@ import java.util.Arrays;
public class Utils {
public float[] normalizeWeights(float[] weights) {
float sum_weight = Utils.sumArrayElements(weights);
float[] weightsNormalized = null;
public double[] normalizeWeights(double[] weights) {
double sum_weight = Utils.sumArrayElements(weights);
double[] weightsNormalized = null;
for (int i = 0; i < weights.length; i++) {
weightsNormalized[i] = weights[i] / sum_weight;
}
return weightsNormalized;
}
public float findMaxDistance(SolutionDistance[] solutions) {
public double findMaxDistance(SolutionDistance[] solutions) {
double max = Double.NEGATIVE_INFINITY;
for (SolutionDistance solution : solutions) {
if(solution.getDistance() > max) {
max = solution.getDistance();
}
}
return max;
}
public float findMinDistance(SolutionDistance[] solutions) {
public double findMinDistance(SolutionDistance[] solutions) {
double min = Double.POSITIVE_INFINITY;
for (SolutionDistance solution : solutions) {
if (solution.getDistance() < min){
min = solution.getDistance();
}
}
return min;
}
public float sumTotalDistance(SolutionDistance[] solutions) {
public double sumTotalDistance(SolutionDistance[] solutions) {
double sum = 0;
for (SolutionDistance solution : solutions) {
sum += solution.getDistance();
}
return sum;
}
public static float sumArrayElements(float[] array) {
public static double sumArrayElements(double[] array) {
float sum = 0;
for (int i = 0; i < array.length; i++) {
sum += array[i];
for (double weight : array) {
sum += weight;
}
return sum;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment