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.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();
private double m_GlobalOpt = 0;
protected Population m_ListOfOptima;
@ -126,6 +127,11 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
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
public Object[] getAdditionalDataValue(PopulationInterface pop) {
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
* 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 pop
@ -348,13 +356,15 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
for (int i=0; i<realOpts.size(); i++) {
// store the optimal fitness values and remember the smallest one
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)");
if (i==0 || (minOpt>realFits[i])) minOpt = realFits[i];
// check if the opt. was found and store the corr. found fitness
if (optsFound[i]!=null) {
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...
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.populations.Population;
import eva2.server.go.strategies.InterfaceOptimizer;
import eva2.tools.ToolBox;
/**
* Created by IntelliJ IDEA.
@ -87,7 +88,7 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
protected AbstractEAIndividual m_Template = 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.
* @return the clone
@ -252,8 +253,39 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String
*/
public String[] getAdditionalDataHeader() {
if (this instanceof InterfaceInterestingHistogram) return new String[]{STAT_SOLUTION_HEADER,"histogram","score"};
else return new String[]{STAT_SOLUTION_HEADER};
String[] header = null;
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
@ -261,12 +293,17 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String
*/
public String[] getAdditionalDataInfo() {
if (this instanceof InterfaceInterestingHistogram) {
return new String[]{"Representation of the current best individual",
String[] info=null;
if (this instanceof InterfaceInterestingHistogram)
info = new String[]{"Representation of the current best individual",
"Fitness histogram of the current population",
"Fitness threshold based score of the current population"};
}
return new String[]{"Representation of the current best individual"};
else info = 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
@ -274,9 +311,8 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
* @return String
*/
public Object[] getAdditionalDataValue(PopulationInterface pop) {
Object solObj;
// solObj = AbstractEAIndividual.getDefaultDataString(pop.getBestIndividual());
solObj = AbstractEAIndividual.getDefaultDataObject(pop.getBestIndividual());
String solStr = AbstractEAIndividual.getDefaultDataString(pop.getBestIndividual());
Object[] vals = null;
if (this instanceof InterfaceInterestingHistogram) {
int fitCrit=0;
SolutionHistogram hist = ((InterfaceInterestingHistogram)this).getHistogram();
@ -288,8 +324,13 @@ implements InterfaceOptimizationProblem /*, InterfaceParamControllable*/, Serial
}
Population sols = PostProcess.clusterBestUpdateHistogram((Population)maybeFiltered, this, hist, fitCrit, getDefaultAccuracy());
}
return new Object[]{solObj, hist, hist.getScore()};
} else return new Object[]{solObj};
vals = new Object[]{solStr, hist, hist.getScore()};
} 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

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

View File

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