jeco.core.util.Maths Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jeco-core Show documentation
Show all versions of jeco-core Show documentation
Java Evolutionary COmputation library
The newest version!
package jeco.core.util;
import java.util.Collections;
import java.util.List;
import jeco.core.problem.Solutions;
import jeco.core.problem.Variable;
import org.uma.jmetal.qualityindicator.impl.Hypervolume;
/**
* Utility functions. Must be refactored.
*
* @author jlrisco, J. M. Colmenar
*/
public class Maths {
public static double sum(List numbers) {
double res = 0;
for (Double number : numbers) {
res += number;
}
return res;
}
public static double mean(List numbers) {
if (numbers.isEmpty()) {
return 0;
}
double res = sum(numbers) / numbers.size();
return res;
}
public static double median(List numbers) {
Collections.sort(numbers);
int middle = numbers.size() / 2;
if (numbers.size() % 2 == 1) {
return numbers.get(middle);
} else {
return (numbers.get(middle - 1) + numbers.get(middle)) / 2.0;
}
}
public static double std(List numbers) {
double res = 0;
double avg = mean(numbers);
for(Double number : numbers) {
res += Math.pow(number-avg, 2);
}
res = Math.sqrt(res/(numbers.size()-1));
return res;
}
public static > double calculateHypervolume(Solutions solFront, int numObjectives) {
double [][] front = new double[solFront.size()][numObjectives];
for (int i = 0; i < solFront.size(); i++) {
for (int obj=0; obj