Updates to problem classes

This commit is contained in:
Marcel Kronfeld 2011-05-04 11:15:41 +00:00
parent 6403679a8c
commit 5c40d4a72e
4 changed files with 81 additions and 38 deletions

View File

@ -14,7 +14,8 @@ import eva2.tools.EVAERROR;
import eva2.tools.ToolBox; import eva2.tools.ToolBox;
import eva2.tools.math.Mathematics; import eva2.tools.math.Mathematics;
public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDouble implements Interface2DBorderProblem, InterfaceMultimodalProblemKnown { public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDouble
implements Interface2DBorderProblem, InterfaceMultimodalProblemKnown {
protected static InterfaceDistanceMetric m_Metric = new PhenotypeMetric(); protected static InterfaceDistanceMetric m_Metric = new PhenotypeMetric();
private double m_GlobalOpt = 0; private double m_GlobalOpt = 0;
protected Population m_ListOfOptima; protected Population m_ListOfOptima;
@ -126,6 +127,11 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
return ToolBox.appendArrays(new String[]{"numOptsFound", "maxPeakRatio"}, super.getAdditionalDataHeader()); return ToolBox.appendArrays(new String[]{"numOptsFound", "maxPeakRatio"}, super.getAdditionalDataHeader());
} }
@Override
public String[] getAdditionalDataInfo() {
return ToolBox.appendArrays(new String[]{"The number of optima identified with default accuracy", "The maximum peak ratio measure in [0,1], best at 1, if multiple local optima are known."}, super.getAdditionalDataInfo());
}
@Override @Override
public Object[] getAdditionalDataValue(PopulationInterface pop) { public Object[] getAdditionalDataValue(PopulationInterface pop) {
Object[] result = new Object[2]; Object[] result = new Object[2];
@ -333,7 +339,9 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
/** /**
* Returns -1 if the full list is not available. Otherwise calculates the maximum peak ratio * Returns -1 if the full list is not available. Otherwise calculates the maximum peak ratio
* based on the full list of known optima. Assumes that both realOpts and pop have fitness * based on the full list of known optima. Assumes that both realOpts and pop have fitness
* values assigned as in a maximization problem. This is the standard formulation of MPR. * values assigned as in a minimization problem. Using a fitness value fitThreshold, they are inverted
* and then treated as in maximization. An optimum which has not been found closely (by epsilon)
* in the population is assumed to be covered with an individual of fitness fitThreshold.
* *
* @param mmProb * @param mmProb
* @param pop * @param pop
@ -348,13 +356,15 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
for (int i=0; i<realOpts.size(); i++) { for (int i=0; i<realOpts.size(); i++) {
// store the optimal fitness values and remember the smallest one // store the optimal fitness values and remember the smallest one
realFits[i]=realOpts.getEAIndividual(i).getFitness(fitCrit); realFits[i]=realOpts.getEAIndividual(i).getFitness(fitCrit);
if (realFits[i]>fitThreshold) System.err.println("Warning: The fitness threshold to turn minimization fitness values into " + if (realFits[i]>fitThreshold) EVAERROR.errorMsgOnce("Warning: The fitness threshold to turn minimization fitness values into " +
"maximization values should be larger than any optimal fitness! (AbstractMultiModalProblemKnown)"); "maximization values should be larger than any optimal fitness! (AbstractMultiModalProblemKnown)");
if (i==0 || (minOpt>realFits[i])) minOpt = realFits[i]; if (i==0 || (minOpt>realFits[i])) minOpt = realFits[i];
// check if the opt. was found and store the corr. found fitness // check if the opt. was found and store the corr. found fitness
if (optsFound[i]!=null) { if (optsFound[i]!=null) {
foundFits[i] = new Double(optsFound[i].getFitness(fitCrit)); foundFits[i] = new Double(optsFound[i].getFitness(fitCrit));
} else foundFits[i]=fitThreshold; // note that it wasnt found -- will result in zero } else {
foundFits[i]=fitThreshold; // note that it wasnt found -- will result in zero
}
} }
// now we mirror all values with the threshold - provided they are below the threshold... // now we mirror all values with the threshold - provided they are below the threshold...
for (int i=0; i<realOpts.size(); i++) { for (int i=0; i<realOpts.size(); i++) {

View File

@ -35,6 +35,7 @@ import eva2.server.go.operators.terminators.PopulationMeasureTerminator.Directio
import eva2.server.go.operators.terminators.PopulationMeasureTerminator.StagnationTypeEnum; import eva2.server.go.operators.terminators.PopulationMeasureTerminator.StagnationTypeEnum;
import eva2.server.go.populations.Population; import eva2.server.go.populations.Population;
import eva2.server.go.strategies.InterfaceOptimizer; import eva2.server.go.strategies.InterfaceOptimizer;
import eva2.tools.ToolBox;
/** /**
* Created by IntelliJ IDEA. * Created by IntelliJ IDEA.
@ -87,7 +88,7 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
protected AbstractEAIndividual m_Template = null; protected AbstractEAIndividual m_Template = null;
// private transient ArrayList<ParamChangeListener> changeListeners = null; // private transient ArrayList<ParamChangeListener> changeListeners = null;
private double defaultAccuracy = 0.01; // default accuracy for identifying optima. private double defaultAccuracy = 0.001; // default accuracy for identifying optima.
/** This method returns a deep clone of the problem. /** This method returns a deep clone of the problem.
* @return the clone * @return the clone
@ -252,8 +253,39 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String * @return String
*/ */
public String[] getAdditionalDataHeader() { public String[] getAdditionalDataHeader() {
if (this instanceof InterfaceInterestingHistogram) return new String[]{STAT_SOLUTION_HEADER,"histogram","score"}; String[] header = null;
else return new String[]{STAT_SOLUTION_HEADER}; if (this instanceof InterfaceInterestingHistogram) header = new String[]{STAT_SOLUTION_HEADER,"histogram","score"};
else header = new String[]{STAT_SOLUTION_HEADER};
header = (String[])checkAndAppendAdd(0, getIndividualTemplate(), header, null);
header = (String[])checkAndAppendAdd(0, getIndividualTemplate().getCrossoverOperator(), header, null);
header = (String[])checkAndAppendAdd(0, getIndividualTemplate().getMutationOperator(), header, null);
return header;
}
/**
* Generic method to append additional information of another object.
*
* @param type indicate header (0), info (1), or value (2)
* @param o the object to retrieve data from
* @param dat the data array to which to append to
* @param pop the current population
* @return
*/
private static Object[] checkAndAppendAdd(int type, Object o, Object[] dat, PopulationInterface pop) {
if (o instanceof InterfaceAdditionalPopulationInformer) {
switch(type) {
case 0: // header
return ToolBox.appendArrays((String[])dat, (String[])((InterfaceAdditionalPopulationInformer)o).getAdditionalDataHeader());
case 1: // info
return ToolBox.appendArrays((String[])dat, (String[])((InterfaceAdditionalPopulationInformer)o).getAdditionalDataInfo());
case 2: // value
return ToolBox.appendArrays(dat, ((InterfaceAdditionalPopulationInformer)o).getAdditionalDataValue(pop));
default:
System.err.println("Error, invalid type in AbstractOptimizationProblem.appendAdd");
return dat;
}
} else return dat;
} }
/** This method returns the header for the additional data that is to be written into a file /** This method returns the header for the additional data that is to be written into a file
@ -261,12 +293,17 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String * @return String
*/ */
public String[] getAdditionalDataInfo() { public String[] getAdditionalDataInfo() {
if (this instanceof InterfaceInterestingHistogram) { String[] info=null;
return new String[]{"Representation of the current best individual", if (this instanceof InterfaceInterestingHistogram)
info = new String[]{"Representation of the current best individual",
"Fitness histogram of the current population", "Fitness histogram of the current population",
"Fitness threshold based score of the current population"}; "Fitness threshold based score of the current population"};
} else info = new String[]{"Representation of the current best individual"};
return new String[]{"Representation of the current best individual"};
info = (String[])checkAndAppendAdd(1, getIndividualTemplate(), info, null);
info = (String[])checkAndAppendAdd(1, getIndividualTemplate().getCrossoverOperator(), info, null);
info = (String[])checkAndAppendAdd(1, getIndividualTemplate().getMutationOperator(), info, null);
return info;
} }
/** This method returns the additional data that is to be written into a file /** This method returns the additional data that is to be written into a file
@ -274,9 +311,8 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String * @return String
*/ */
public Object[] getAdditionalDataValue(PopulationInterface pop) { public Object[] getAdditionalDataValue(PopulationInterface pop) {
Object solObj; String solStr = AbstractEAIndividual.getDefaultDataString(pop.getBestIndividual());
// solObj = AbstractEAIndividual.getDefaultDataString(pop.getBestIndividual()); Object[] vals = null;
solObj = AbstractEAIndividual.getDefaultDataObject(pop.getBestIndividual());
if (this instanceof InterfaceInterestingHistogram) { if (this instanceof InterfaceInterestingHistogram) {
int fitCrit=0; int fitCrit=0;
SolutionHistogram hist = ((InterfaceInterestingHistogram)this).getHistogram(); SolutionHistogram hist = ((InterfaceInterestingHistogram)this).getHistogram();
@ -288,8 +324,13 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
} }
Population sols = PostProcess.clusterBestUpdateHistogram((Population)maybeFiltered, this, hist, fitCrit, getDefaultAccuracy()); Population sols = PostProcess.clusterBestUpdateHistogram((Population)maybeFiltered, this, hist, fitCrit, getDefaultAccuracy());
} }
return new Object[]{solObj, hist, hist.getScore()}; vals = new Object[]{solStr, hist, hist.getScore()};
} else return new Object[]{solObj}; } else vals = new Object[]{solStr};
vals = checkAndAppendAdd(2, pop.getBestIndividual(), vals, pop);
vals = checkAndAppendAdd(2, ((AbstractEAIndividual)pop.getBestIndividual()).getCrossoverOperator(), vals, pop);
vals = checkAndAppendAdd(2, ((AbstractEAIndividual)pop.getBestIndividual()).getMutationOperator(), vals, pop);
return vals;
} }
/** /**

View File

@ -142,19 +142,18 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
double[] x; double[] x;
double[] fitness; double[] fitness;
x = getEvalArray(individual); x = getEvalArray(individual);
((InterfaceDataTypeDouble) individual).SetDoublePhenotype(x); ((InterfaceDataTypeDouble)individual).SetDoublePhenotype(x);
// evaluate the vector // evaluate the vector
fitness = this.eval(x); fitness = this.eval(x);
// if indicated, add Gaussian noise // if indicated, add Gaussian noise
if (m_Noise != 0) if (m_Noise != 0) RNG.addNoise(fitness, m_Noise);
RNG.addNoise(fitness, m_Noise); // set the fitness
// set the fitness setEvalFitness(individual, x, fitness);
setEvalFitness(individual, x, fitness); if (isWithConstraints()) {
if (isWithConstraints()) { individual.putData(rawFitKey, individual.getFitness().clone());
individual.putData(rawFitKey, individual.getFitness().clone()); addConstraints(individual, x);
addConstraints(individual, x); }
}
} }
protected double[] rotateMaybe(double[] x) { protected double[] rotateMaybe(double[] x) {
@ -573,10 +572,6 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
return "(De-)Activate constraints for the problem."; return "(De-)Activate constraints for the problem.";
} }
/*
* (non-Javadoc)
* @see eva2.server.go.problems.AbstractOptimizationProblem#getAdditionalDataHeader()
*/
@Override @Override
public String[] getAdditionalDataHeader() { public String[] getAdditionalDataHeader() {
String[] superHeader = super.getAdditionalDataHeader(); String[] superHeader = super.getAdditionalDataHeader();
@ -587,10 +582,6 @@ public abstract class AbstractProblemDouble extends AbstractOptimizationProblem
return superHeader; return superHeader;
} }
/*
* (non-Javadoc)
* @see eva2.server.go.problems.AbstractOptimizationProblem#getAdditionalDataInfo()
*/
@Override @Override
public String[] getAdditionalDataInfo() { public String[] getAdditionalDataInfo() {
String[] superInfo = super.getAdditionalDataInfo(); String[] superInfo = super.getAdditionalDataInfo();

View File

@ -11,7 +11,8 @@ import eva2.server.go.operators.mutation.MutateGAUniform;
import eva2.server.go.strategies.InterfaceOptimizer; import eva2.server.go.strategies.InterfaceOptimizer;
/** /**
* Created by IntelliJ IDEA. * The minimize bits problem for binary optimization.
*
* User: streiche * User: streiche
* Date: 21.03.2003 * Date: 21.03.2003
* Time: 13:05:33 * Time: 13:05:33