parent
f8c7158c18
commit
d0a3d2e434
@ -1,6 +1,7 @@
|
|||||||
package eva2.optimization.individuals;
|
package eva2.optimization.individuals;
|
||||||
|
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
@ -79,8 +80,8 @@ public class IndividualWeightedFitnessComparator implements Comparator<AbstractE
|
|||||||
double[] f1 = o1.getFitness();
|
double[] f1 = o1.getFitness();
|
||||||
double[] f2 = o2.getFitness();
|
double[] f2 = o2.getFitness();
|
||||||
|
|
||||||
double score1 = calcScore(f1);
|
double score1 = calculateScore(f1);
|
||||||
double score2 = calcScore(f2);
|
double score2 = calculateScore(f2);
|
||||||
|
|
||||||
if (score1 < score2) {
|
if (score1 < score2) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -95,7 +96,7 @@ public class IndividualWeightedFitnessComparator implements Comparator<AbstractE
|
|||||||
* @param f
|
* @param f
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private double calcScore(double[] f) {
|
private double calculateScore(double[] f) {
|
||||||
if (f == null || fitWeights == null) {
|
if (f == null || fitWeights == null) {
|
||||||
throw new RuntimeException("Error, missing information in " + this.getClass());
|
throw new RuntimeException("Error, missing information in " + this.getClass());
|
||||||
}
|
}
|
||||||
@ -117,9 +118,9 @@ public class IndividualWeightedFitnessComparator implements Comparator<AbstractE
|
|||||||
* @param indy
|
* @param indy
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public double calcScore(AbstractEAIndividual indy) {
|
public double calculateScore(AbstractEAIndividual indy) {
|
||||||
double[] f = indy.getFitness();
|
double[] f = indy.getFitness();
|
||||||
return calcScore(f);
|
return calculateScore(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -133,6 +134,7 @@ public class IndividualWeightedFitnessComparator implements Comparator<AbstractE
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Weights of the fitness values in the linear combination")
|
||||||
public void setFitWeights(double[] fitWeights) {
|
public void setFitWeights(double[] fitWeights) {
|
||||||
this.fitWeights = fitWeights;
|
this.fitWeights = fitWeights;
|
||||||
}
|
}
|
||||||
@ -140,23 +142,4 @@ public class IndividualWeightedFitnessComparator implements Comparator<AbstractE
|
|||||||
public double[] getFitWeights() {
|
public double[] getFitWeights() {
|
||||||
return fitWeights;
|
return fitWeights;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fitWeightsTipText() {
|
|
||||||
return "Weights of the fitness values in the linear combination";
|
|
||||||
}
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// TF1Problem prob = new TF1Problem();
|
|
||||||
// Population pop = new Population(10);
|
|
||||||
// prob.initializePopulation(pop);
|
|
||||||
// prob.evaluate(pop);
|
|
||||||
// System.out.println(pop.getStringRepresentation());
|
|
||||||
// System.out.println("***");
|
|
||||||
// IndividualWeightedFitnessComparator wfComp = new IndividualWeightedFitnessComparator(new double[]{0.5,0.5});
|
|
||||||
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
|
|
||||||
// wfComp.setFitWeights(new double[] {0.1, 0.9});
|
|
||||||
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
|
|
||||||
// wfComp.setFitWeights(new double[] {0.9, 0.1});
|
|
||||||
// System.out.println("***"); System.out.println(pop.getSortedPop(wfComp).getStringRepresentation());
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,11 @@ public class DiversityTerminator extends PopulationMeasureTerminator implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calculateInitialMeasure(PopulationInterface pop) {
|
protected double calculateInitialMeasure(PopulationInterface pop) {
|
||||||
return calcPopulationMeasure(pop);
|
return calculatePopulationMeasure(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
double[] measures = ((Population) pop).getPopulationMeasures(metric);
|
double[] measures = ((Population) pop).getPopulationMeasures(metric);
|
||||||
int measureIndex = criterion.ordinal();
|
int measureIndex = criterion.ordinal();
|
||||||
return measures[measureIndex];
|
return measures[measureIndex];
|
||||||
|
@ -35,7 +35,7 @@ public class FitnessConvergenceTerminator extends PopulationMeasureTerminator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
// if (oldFit==null) return Double.MAX_VALUE;
|
// if (oldFit==null) return Double.MAX_VALUE;
|
||||||
// return EuclideanMetric.euclideanDistance(oldFit, pop.getBestFitness());
|
// return EuclideanMetric.euclideanDistance(oldFit, pop.getBestFitness());
|
||||||
return Mathematics.norm(pop.getBestFitness());
|
return Mathematics.norm(pop.getBestFitness());
|
||||||
|
@ -7,6 +7,7 @@ import eva2.problems.InterfaceMultimodalProblemKnown;
|
|||||||
import eva2.problems.InterfaceOptimizationProblem;
|
import eva2.problems.InterfaceOptimizationProblem;
|
||||||
import eva2.tools.EVAERROR;
|
import eva2.tools.EVAERROR;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@ -25,8 +26,7 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
|
|||||||
private int reqOptima = 1;
|
private int reqOptima = 1;
|
||||||
private String msg = "";
|
private String msg = "";
|
||||||
|
|
||||||
public KnownOptimaFoundTerminator() {
|
public KnownOptimaFoundTerminator() {}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
|
public void initialize(InterfaceOptimizationProblem prob) throws IllegalArgumentException {
|
||||||
@ -71,21 +71,18 @@ public class KnownOptimaFoundTerminator implements InterfaceTerminator, Serializ
|
|||||||
/**
|
/**
|
||||||
* @return the reqOptima
|
* @return the reqOptima
|
||||||
*/
|
*/
|
||||||
public int getReqOptima() {
|
public int getRequiredOptima() {
|
||||||
return reqOptima;
|
return reqOptima;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param reqOptima the reqOptima to set
|
* @param reqOptima the reqOptima to set
|
||||||
*/
|
*/
|
||||||
public void setReqOptima(int reqOptima) {
|
@Parameter(description = "The number of optima that need to be found to terminate the optimization.")
|
||||||
|
public void setRequiredOptima(int reqOptima) {
|
||||||
this.reqOptima = reqOptima;
|
this.reqOptima = reqOptima;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String reqOptimaTipText() {
|
|
||||||
return "The number of optima that need to be found to terminate the optimization.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "KnownOptimaFoundTerminator requiring " + reqOptima + " optima.";
|
return "KnownOptimaFoundTerminator requiring " + reqOptima + " optima.";
|
||||||
|
@ -69,7 +69,7 @@ public class ParetoMetricTerminator extends PopulationMeasureTerminator implemen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
return calculateInitialMeasure(pop);
|
return calculateInitialMeasure(pop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class PhenotypeConvergenceTerminator extends PopulationMeasureTerminator
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
return pMetric.distance(oldIndy, (AbstractEAIndividual) pop.getBestIndividual());
|
return pMetric.distance(oldIndy, (AbstractEAIndividual) pop.getBestIndividual());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import eva2.optimization.individuals.IndividualWeightedFitnessComparator;
|
|||||||
import eva2.optimization.population.Population;
|
import eva2.optimization.population.Population;
|
||||||
import eva2.optimization.population.PopulationInterface;
|
import eva2.optimization.population.PopulationInterface;
|
||||||
import eva2.util.annotation.Description;
|
import eva2.util.annotation.Description;
|
||||||
|
import eva2.util.annotation.Parameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Terminate if a score based on the archive of the population converges.
|
* Terminate if a score based on the archive of the population converges.
|
||||||
@ -19,17 +20,17 @@ public class PopulationArchiveTerminator extends PopulationMeasureTerminator {
|
|||||||
if (archive == null || (archive.size() < 1)) {
|
if (archive == null || (archive.size() < 1)) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
return wfComp.calcScore(archive.getBestEAIndividual(wfComp));
|
return wfComp.calculateScore(archive.getBestEAIndividual(wfComp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected double calcPopulationMeasure(PopulationInterface pop) {
|
protected double calculatePopulationMeasure(PopulationInterface pop) {
|
||||||
Population archive = ((Population) pop).getArchive();
|
Population archive = ((Population) pop).getArchive();
|
||||||
if (archive == null || (archive.size() < 1)) {
|
if (archive == null || (archive.size() < 1)) {
|
||||||
return Double.MAX_VALUE;
|
return Double.MAX_VALUE;
|
||||||
} else {
|
} else {
|
||||||
return wfComp.calcScore(archive.getBestEAIndividual(wfComp));
|
return wfComp.calculateScore(archive.getBestEAIndividual(wfComp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,11 +43,8 @@ public class PopulationArchiveTerminator extends PopulationMeasureTerminator {
|
|||||||
return wfComp.getFitWeights();
|
return wfComp.getFitWeights();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Parameter(description = "Weights of the fitness values in the linear combination")
|
||||||
public void setFitWeights(double[] fWeights) {
|
public void setFitWeights(double[] fWeights) {
|
||||||
wfComp.setFitWeights(fWeights);
|
wfComp.setFitWeights(fWeights);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String fitWeightsTipText() {
|
|
||||||
return wfComp.fitWeightsTipText();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @param pop
|
* @param pop
|
||||||
*/
|
*/
|
||||||
protected void saveState(PopulationInterface pop) {
|
protected void saveState(PopulationInterface pop) {
|
||||||
oldMeasure = calcPopulationMeasure(pop);
|
oldMeasure = calculatePopulationMeasure(pop);
|
||||||
oldPopFitCalls = pop.getFunctionCalls();
|
oldPopFitCalls = pop.getFunctionCalls();
|
||||||
oldPopGens = pop.getGeneration();
|
oldPopGens = pop.getGeneration();
|
||||||
firstTime = false;
|
firstTime = false;
|
||||||
@ -170,7 +170,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @param pop
|
* @param pop
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected abstract double calcPopulationMeasure(PopulationInterface pop);
|
protected abstract double calculatePopulationMeasure(PopulationInterface pop);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the population measure did not exceed the
|
* Return true if the population measure did not exceed the
|
||||||
@ -180,7 +180,7 @@ public abstract class PopulationMeasureTerminator implements InterfaceTerminator
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected boolean isStillConverged(PopulationInterface pop) {
|
protected boolean isStillConverged(PopulationInterface pop) {
|
||||||
double measure = calcPopulationMeasure(pop);
|
double measure = calculatePopulationMeasure(pop);
|
||||||
double allowedLower = Double.NEGATIVE_INFINITY, allowedUpper = Double.POSITIVE_INFINITY;
|
double allowedLower = Double.NEGATIVE_INFINITY, allowedUpper = Double.POSITIVE_INFINITY;
|
||||||
boolean ret;
|
boolean ret;
|
||||||
switch (changeType) {
|
switch (changeType) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user