Some changes from branch mkron

This commit is contained in:
Marcel Kronfeld 2008-06-27 14:52:49 +00:00
parent 4ed16eee27
commit 34075b8c97
5 changed files with 80 additions and 16 deletions

View File

@ -12,7 +12,6 @@ import eva2.server.go.operators.cluster.InterfaceClustering;
import eva2.server.go.operators.distancemetric.InterfaceDistanceMetric;
import eva2.server.go.operators.distancemetric.PhenotypeMetric;
import eva2.server.go.operators.mutation.InterfaceMutation;
import eva2.server.go.operators.mutation.MutateESCovarianceMartixAdaption;
import eva2.server.go.operators.mutation.MutateESFixedStepSize;
import eva2.server.go.operators.mutation.MutateESMutativeStepSizeControl;
import eva2.server.go.operators.terminators.EvaluationTerminator;
@ -503,7 +502,7 @@ public class PostProcess {
listener.println("max peak ratio is " + mmkProb.getMaximumPeakRatio(getFoundOptima(solutions, mmkProb.getRealOptima(), mmkProb.getEpsilon(), true)));
for (double epsilon=0.1; epsilon > 0.00000001; epsilon/=10.) {
// out.println("no optima found: " + ((InterfaceMultimodalProblemKnown)mmProb).getNumberOfFoundOptima(pop));
listener.println("found " + getFoundOptima(solutions, mmkProb.getRealOptima(), epsilon, true).size() + " for epsilon = " + epsilon + ", maxPeakRatio: " + ((AbstractMultiModalProblemKnown)mmkProb).getMaximumPeakRatio(solutions, epsilon));
listener.println("found " + getFoundOptima(solutions, mmkProb.getRealOptima(), epsilon, true).size() + " for epsilon = " + epsilon + ", maxPeakRatio: " + AbstractMultiModalProblemKnown.getMaximumPeakRatio(mmkProb,solutions, epsilon));
}
}
}

View File

@ -215,7 +215,11 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
* @return int
*/
public int getNumberOfFoundOptima(Population pop) {
List<AbstractEAIndividual> sols = PostProcess.getFoundOptima(pop, m_Optima, m_Epsilon, true);
return getNoFoundOptimaOf(this, pop);
}
public static int getNoFoundOptimaOf(InterfaceMultimodalProblemKnown mmProb, Population pop) {
List<AbstractEAIndividual> sols = PostProcess.getFoundOptima(pop, mmProb.getRealOptima(), mmProb.getEpsilon(), true);
return sols.size();
}
@ -231,18 +235,18 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
* @return double
*/
public double getMaximumPeakRatio(Population pop) {
return getMaximumPeakRatio(pop, m_Epsilon);
return getMaximumPeakRatio(this, pop, m_Epsilon);
}
public double getMaximumPeakRatio(Population pop, double epsilon) {
public static double getMaximumPeakRatio(InterfaceMultimodalProblemKnown mmProb, Population pop, double epsilon) {
double optimaInvertedSum = 0, foundInvertedSum = 0;
AbstractEAIndividual[] optsFound = PostProcess.getFoundOptimaArray(pop, m_Optima, epsilon, true);
for (int i=0; i<m_Optima.size(); i++) {
Population realOpts = mmProb.getRealOptima();
AbstractEAIndividual[] optsFound = PostProcess.getFoundOptimaArray(pop, realOpts, epsilon, true);
for (int i=0; i<realOpts.size(); i++) {
// sum up known optimal fitness values
optimaInvertedSum += m_Optima.getEAIndividual(i).getFitness(0);
optimaInvertedSum += realOpts.getEAIndividual(i).getFitness(0);
// sum up best found hits, with inverted fitness
if (optsFound[i] != null) foundInvertedSum += m_GlobalOpt - optsFound[i].getFitness(0);
if (optsFound[i] != null) foundInvertedSum += realOpts.getBestEAIndividual().getFitness(0) - optsFound[i].getFitness(0);
}
return foundInvertedSum/optimaInvertedSum;

View File

@ -1,14 +1,14 @@
package eva2.server.go.strategies;
import wsi.ra.math.RNG;
import eva2.gui.GenericObjectEditor;
import eva2.gui.Plot;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.individuals.InterfaceDataTypeDouble;
import eva2.server.go.individuals.InterfaceESIndividual;
import eva2.server.go.populations.Population;
import eva2.server.go.problems.AbstractOptimizationProblem;
import eva2.server.go.problems.InterfaceOptimizationProblem;
import eva2.server.go.tools.AbstractObjectEditor;
import wsi.ra.math.RNG;
import eva2.tools.SelectedTag;
/**
@ -43,6 +43,9 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
private double maxSpeedLimit = 0.1;
private double minSpeedLimit = .003;
private boolean plotBestOnly = false;
private transient double[] lastBestPlot = null;
/**
* constant indication quantum particles
*/
@ -158,12 +161,45 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
resetFitness(indy);
if (this.m_Show) {
this.m_Plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey)));
plotIndy(position, null, (Integer)(indy.getData(indexKey)));
// if (this.m_Show) {
// this.m_Plot.setUnconnectedPoint(position[0], position[1], (Integer)(indy.getData(indexKey)));
//this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index+1);
}
// }
//System.out.println("quantum particle " + index + " set to " + newPos[0] + "/" + newPos[1]);
}
private void plotBestIndy() {
if (m_Plot != null) {
double[] curPosition = ((InterfaceDataTypeDouble)m_Population.getBestEAIndividual()).getDoubleData();
if (lastBestPlot != null) this.m_Plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], 0);
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], 0);
lastBestPlot = curPosition.clone();
}
}
protected void plotIndy(double[] curPosition, double[] curVelocity, int index) {
if (this.m_Show) {
if (plotBestOnly) {
return;
// if (index != ((Integer)(m_Population.getBestEAIndividual().getData(indexKey)))) return;
// else {
// if (lastBestPlot != null) this.m_Plot.setConnectedPoint(lastBestPlot[0], lastBestPlot[1], index);
// this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index);
// lastBestPlot = curPosition.clone();
// }
} else {
if (curVelocity == null) {
this.m_Plot.setUnconnectedPoint(curPosition[0], curPosition[1], index);
} else {
this.m_Plot.setConnectedPoint(curPosition[0], curPosition[1], index);
this.m_Plot.setConnectedPoint(curPosition[0] + curVelocity[0], curPosition[1] + curVelocity[1], index);
}
}
}
}
/**
* Return a uniformly distributed position vector within a sphere of radius r in relation to the given range.
@ -379,7 +415,10 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
protected void evaluatePopulation(Population population) {
envHasChanged = false;
super.evaluatePopulation(population);
if (m_Show && plotBestOnly) plotBestIndy();
envHasChanged = detectChange(m_Population);
// if (envHasChanged) {
// System.out.println("environmental change detected!");
// }
@ -638,4 +677,22 @@ public class DynamicParticleSwarmOptimization extends ParticleSwarmOptimization
public String phi3TipText() {
return "Acceleration of the problem specific attractor";
}
public Plot getPlot() {
return m_Plot;
}
/**
* @return the plotBestOnly
*/
public boolean isPlotBestOnly() {
return plotBestOnly;
}
/**
* @param plotBestOnly the plotBestOnly to set
*/
public void setPlotBestOnly(boolean plotBestOnly) {
this.plotBestOnly = plotBestOnly;
}
}

View File

@ -161,6 +161,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected void finalizeOutput() {
if (printFinalVerbosity()) printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt/(double)m_StatsParams.getMultiRuns() + '\n');
if (printFinalVerbosity()) printToTextListener(" Average function calls: " + (functionCallSum/optRunsPerformed) + "\n");
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener("Best overall individual: " + BeanInspector.toString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" solution : " + AbstractEAIndividual.getDefaultDataString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" fitness : " + BeanInspector.toString(bestIndividualAllover.getFitness()) + '\n');

View File

@ -110,7 +110,10 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
public void stopOptPerformed(boolean normal, String stopMessage) {
super.stopOptPerformed(normal, stopMessage);
if (optRunsPerformed > m_StatsParams.getMultiRuns()) System.err.println("error: this shouldnt happen (StatisticsWithGUI::stopOptPerformed)");
if (optRunsPerformed > m_StatsParams.getMultiRuns()) {
// this may happen if the user reduces the multirun parameter during late multiruns
System.err.println("error: more runs performed than defined.");
}
// unite the graphs only if the break was "normal"
if (normal && (m_StatsParams.getMultiRuns() > 1) && (m_StatGraph != null)) {
// unite the point sets for a multirun