Merging stats from MK branch

This commit is contained in:
Marcel Kronfeld 2011-05-04 10:43:05 +00:00
parent 3e8c2b14dc
commit 6403679a8c
3 changed files with 60 additions and 40 deletions

View File

@ -94,8 +94,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected double[] currentMeanFit; protected double[] currentMeanFit;
protected double[] currentWorstFit; protected double[] currentWorstFit;
// protected double[] meanBestOfRunFitness; // protected double[] meanBestOfRunFitness;
protected double currentAvgPopDist; protected double currentAvgEucDistInPop, currentMaxEucDistInPop;
protected double currentMaxPopDist; protected double currentAvgPopDistMetric, currentMaxPopDistMetric;
protected IndividualInterface bestCurrentIndy, bestOfRunIndy, bestOfRunFeasibleIndy, bestFeasibleAllRuns, bestIndyAllRuns; protected IndividualInterface bestCurrentIndy, bestOfRunIndy, bestOfRunFeasibleIndy, bestFeasibleAllRuns, bestIndyAllRuns;
// collect feasible results of a run // collect feasible results of a run
@ -353,7 +353,10 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
// if (currentBestFit!= null) { // if (currentBestFit!= null) {
// if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n"); // if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n");
// } // }
if (optRunsPerformed >= m_StatsParams.getMultiRuns()) {
if (printFinalVerbosity()) printToTextListener("\n");
finalizeOutput();
}
fireDataListenersStartStop(optRunsPerformed, normal, false); fireDataListenersStartStop(optRunsPerformed, normal, false);
} }
@ -374,11 +377,11 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} }
private PopulationInterface makeStatsPop() { private PopulationInterface makeStatsPop() {
Population pop = new Population(4); Population pop = new Population(1);
if (bestCurrentIndy!=null) pop.add(bestCurrentIndy); // if (bestCurrentIndy!=null) pop.add(bestCurrentIndy);
if (bestOfRunIndy!=null) pop.add(bestOfRunIndy); // if (bestOfRunIndy!=null) pop.add(bestOfRunIndy);
if (bestOfRunFeasibleIndy!=null) pop.add(bestOfRunFeasibleIndy); // if (bestOfRunFeasibleIndy!=null) pop.add(bestOfRunFeasibleIndy);
if (bestIndyAllRuns!=null) pop.add(bestIndyAllRuns); if (bestIndyAllRuns!=null) pop.add(bestIndyAllRuns);
return pop; return pop;
} }
@ -757,8 +760,10 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
case runBest: ret[i] = bestOfRunIndy.getFitness()[defaultFitCriterion]; break; case runBest: ret[i] = bestOfRunIndy.getFitness()[defaultFitCriterion]; break;
case currentBestFeasible: ret[i] = (currentBestFeasibleFit==null) ? Double.NaN : currentBestFeasibleFit[defaultFitCriterion]; break; case currentBestFeasible: ret[i] = (currentBestFeasibleFit==null) ? Double.NaN : currentBestFeasibleFit[defaultFitCriterion]; break;
case runBestFeasible: ret[i] = (bestOfRunFeasibleIndy==null) ? Double.NaN : bestOfRunFeasibleIndy.getFitness()[defaultFitCriterion]; break; case runBestFeasible: ret[i] = (bestOfRunFeasibleIndy==null) ? Double.NaN : bestOfRunFeasibleIndy.getFitness()[defaultFitCriterion]; break;
case avgPopDistance: ret[i] = currentAvgPopDist; break; case avgEucPopDistance: ret[i] = currentAvgEucDistInPop; break;
case maxPopDistance: ret[i] = currentMaxPopDist; break; case maxEucPopDistance: ret[i] = currentMaxEucDistInPop; break;
case avgPopMetricDist: ret[i] = currentAvgPopDistMetric; break;
case maxPopMetricDist: ret[i] = currentMaxPopDistMetric; break;
} }
} }
// all standard fields should be filled now // all standard fields should be filled now
@ -819,7 +824,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
*/ */
protected List<String> getAdditionalHeaderMetaInfo(List<InterfaceAdditionalPopulationInformer> informerList, List<String> metaInfo) { protected List<String> getAdditionalHeaderMetaInfo(List<InterfaceAdditionalPopulationInformer> informerList, List<String> metaInfo) {
LinkedList<String> headers = new LinkedList<String>(); LinkedList<String> headers = new LinkedList<String>();
if (metaInfo!=null && (metaInfo.size()>0)) System.err.println("Warning, metaInfo list should be empty in AbstractStatistics.getAdditionalInfoInfo"); if (metaInfo!=null && (metaInfo.size()>0)) System.err.println("Warning, metaInfo list should be empty in AbstractStatistics.getAdditionalHeaderMetaInfo");
for (InterfaceAdditionalPopulationInformer informer : informerList) { for (InterfaceAdditionalPopulationInformer informer : informerList) {
headers.addAll(Arrays.asList(informer.getAdditionalDataHeader())); headers.addAll(Arrays.asList(informer.getAdditionalDataHeader()));
if (metaInfo!=null) metaInfo.addAll(Arrays.asList(informer.getAdditionalDataInfo())); if (metaInfo!=null) metaInfo.addAll(Arrays.asList(informer.getAdditionalDataInfo()));
@ -1011,12 +1016,21 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
functionCalls = pop.getFunctionCalls(); functionCalls = pop.getFunctionCalls();
if (lastIsShowFull || GraphSelectionEnum.doPlotAvgDist(lastFieldSelection) if (lastIsShowFull || GraphSelectionEnum.doPlotAvgEucDist(lastFieldSelection)
|| GraphSelectionEnum.doPlotMaxPopDist(lastFieldSelection)) { || GraphSelectionEnum.doPlotMaxEucDist(lastFieldSelection)) {
double[] measures = ((Population)pop).getPopulationMeasures((InterfaceDistanceMetric)null); double[] measures = ((Population)pop).getPopulationMeasures((InterfaceDistanceMetric)null);
if (measures != null) { if (measures != null) {
currentAvgPopDist = measures[0]; currentAvgEucDistInPop = measures[0];
currentMaxPopDist = measures[2]; currentMaxEucDistInPop = measures[2];
}
}
if (lastIsShowFull || GraphSelectionEnum.doPlotAvgPopMetricDist(lastFieldSelection)
|| GraphSelectionEnum.doPlotMaxPopMetricDist(lastFieldSelection)) {
double[] measures = ((Population)pop).getPopulationMeasures();
if (measures != null) {
currentAvgPopDistMetric = measures[0];
currentMaxPopDistMetric = measures[2];
} }
} }
} }
@ -1036,32 +1050,23 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
firstPlot = false; firstPlot = false;
currentBestFeasibleFit=null; currentBestFeasibleFit=null;
} }
if (TRACE) printToTextListener("A1\n");
if (pop.getSpecificData() != null) { // this is more or less deprecated. the standard population implementation will always return null. However the ES module wont if (pop.getSpecificData() != null) { // this is more or less deprecated. the standard population implementation will always return null. However the ES module wont
plotSpecificData(pop, informerList); plotSpecificData(pop, informerList);
return; return;
} }
if (TRACE) printToTextListener("A2\n");
collectPopData(pop); collectPopData(pop);
if (TRACE) printToTextListener("A3\n");
if (iterationCounter==0) { if (iterationCounter==0) {
if (TRACE) printToTextListener("A3.1 " + currentStatHeader.length + "\n");
String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter); String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter);
if (TRACE) printToTextListener("A3.2\n");
if (printHeaderByVerbosity()) printToTextListener(headerLine+'\n'); if (printHeaderByVerbosity()) printToTextListener(headerLine+'\n');
if (TRACE) printToTextListener("A3.3\n");
} }
if (TRACE) printToTextListener("A4\n");
lastSols = (opt!=null) ? new Population(opt.getAllSolutions().getSolutions()) : pop; lastSols = (opt!=null) ? new Population(opt.getAllSolutions().getSolutions()) : pop;
// Pair<String,Double[]> addData = getOutputData(informerList, lastSols); // Pair<String,Double[]> addData = getOutputData(informerList, lastSols);
// System.out.println("lastSols size: " + 500*PSymbolicRegression.getAvgIndySize(lastSols)); // System.out.println("lastSols size: " + 500*PSymbolicRegression.getAvgIndySize(lastSols));
// System.out.println("Mem use: " + getMemoryUse()); // System.out.println("Mem use: " + getMemoryUse());
if (TRACE) printToTextListener("A5\n");
Pair<String,Object[]> addData = getOutputData(informerList, lastSols); Pair<String,Object[]> addData = getOutputData(informerList, lastSols);
if (doTextOutput()) { // this is where the text output is actually written if (doTextOutput()) { // this is where the text output is actually written
if (printLineByVerbosity(iterationCounter)) { if (printLineByVerbosity(iterationCounter)) {
@ -1069,8 +1074,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
printToTextListener(addData.head()+'\n'); printToTextListener(addData.head()+'\n');
} }
} }
if (TRACE) printToTextListener("A6\n");
currentStatObjectData = addData.tail(); currentStatObjectData = addData.tail();
currentStatDoubleData = ToolBox.parseDoubles(currentStatObjectData); currentStatDoubleData = ToolBox.parseDoubles(currentStatObjectData);
if (currentStatObjectData!=null) { if (currentStatObjectData!=null) {
@ -1078,7 +1081,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} else { } else {
System.err.println("Warning in AbstractStatistics!"); System.err.println("Warning in AbstractStatistics!");
} }
if (TRACE) printToTextListener("A7\n");
if (sumDataCollection != null) { if (sumDataCollection != null) {
// Collect average data // Collect average data
@ -1099,7 +1101,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (sumDataEntry != null) updateSum(sumDataEntry, currentStatDoubleData); // this adds up data of a single iteration across multiple runs if (sumDataEntry != null) updateSum(sumDataEntry, currentStatDoubleData); // this adds up data of a single iteration across multiple runs
} }
} }
if (TRACE) printToTextListener("A8\n");
// if (doTextOutput()) { // if (doTextOutput()) {
// Pair<String,Double[]> addInfo = getOutputLine(informerList, lastSols); // Pair<String,Double[]> addInfo = getOutputLine(informerList, lastSols);

View File

@ -12,7 +12,7 @@ import eva2.tools.StringSelection;
public enum GraphSelectionEnum { public enum GraphSelectionEnum {
// DONT change this order, or the relation to AbstractStatistics will be lost // DONT change this order, or the relation to AbstractStatistics will be lost
currentBest, meanFit, currentWorst, runBest, currentBestFeasible, runBestFeasible, currentBest, meanFit, currentWorst, runBest, currentBestFeasible, runBestFeasible,
avgPopDistance, maxPopDistance; avgEucPopDistance, maxEucPopDistance, avgPopMetricDist, maxPopMetricDist;
private static String[] toolTips = { private static String[] toolTips = {
"The current best fitness within the population", "The current best fitness within the population",
@ -21,8 +21,10 @@ public enum GraphSelectionEnum {
"The best fitness up to the current generation", "The best fitness up to the current generation",
"The best feasible fitness within the population", "The best feasible fitness within the population",
"The best feasible fitness up to the current generation", "The best feasible fitness up to the current generation",
"The average phenotypic distance of individuals in the population", "The average euclidean distance of individuals in the current population",
"The maximum phenotypic distance of individuals in the population" "The maximum euclidean distance of individuals in the current population",
"The average distance of individuals in the current population metric",
"The maximum distance of individuals in the current population metric",
}; };
public static String[] getInfoStrings() { public static String[] getInfoStrings() {
@ -55,11 +57,19 @@ public enum GraphSelectionEnum {
// return sel.isSelected(GraphSelectionEnum.runBestFeasible.ordinal()); // return sel.isSelected(GraphSelectionEnum.runBestFeasible.ordinal());
// } // }
// //
public static boolean doPlotAvgDist(StringSelection sel) { public static boolean doPlotAvgEucDist(StringSelection sel) {
return sel.isSelected(GraphSelectionEnum.avgPopDistance.ordinal()); return sel.isSelected(GraphSelectionEnum.avgEucPopDistance.ordinal());
} }
public static boolean doPlotMaxPopDist(StringSelection sel) { public static boolean doPlotMaxEucDist(StringSelection sel) {
return sel.isSelected(GraphSelectionEnum.maxPopDistance.ordinal()); return sel.isSelected(GraphSelectionEnum.maxEucPopDistance.ordinal());
}
public static boolean doPlotAvgPopMetricDist(StringSelection sel) {
return sel.isSelected(GraphSelectionEnum.avgPopMetricDist.ordinal());
}
public static boolean doPlotMaxPopMetricDist(StringSelection sel) {
return sel.isSelected(GraphSelectionEnum.maxPopMetricDist.ordinal());
} }
} }

View File

@ -9,6 +9,7 @@ import eva2.gui.BeanInspector;
import eva2.gui.GenericObjectEditor; import eva2.gui.GenericObjectEditor;
import eva2.server.go.InterfaceNotifyOnInformers; import eva2.server.go.InterfaceNotifyOnInformers;
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer; import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR;
import eva2.tools.SelectedTag; import eva2.tools.SelectedTag;
import eva2.tools.Serializer; import eva2.tools.Serializer;
import eva2.tools.StringSelection; import eva2.tools.StringSelection;
@ -384,10 +385,18 @@ public class StatsParameter implements InterfaceStatisticsParameter, InterfaceNo
ArrayList<String> infoFields = new ArrayList<String>(); ArrayList<String> infoFields = new ArrayList<String>();
// parse list of header elements, show additional Strings according to names. // parse list of header elements, show additional Strings according to names.
for (InterfaceAdditionalPopulationInformer inf : informers) { for (InterfaceAdditionalPopulationInformer inf : informers) {
headerFields.addAll(Arrays.asList(inf.getAdditionalDataHeader())); String[] dataHeader = inf.getAdditionalDataHeader();
headerFields.addAll(Arrays.asList(dataHeader));
if (infoFields.size()<headerFields.size()) { // add info strings for tool tips - fill up with null if none have been returned. if (infoFields.size()<headerFields.size()) { // add info strings for tool tips - fill up with null if none have been returned.
String[] infos = inf.getAdditionalDataInfo(); String[] infos = inf.getAdditionalDataInfo();
if (infos!=null) infoFields.addAll(Arrays.asList(infos)); if (infos!=null) {
if (infos.length!=dataHeader.length) {
System.out.println(BeanInspector.toString(infos));
System.out.println(BeanInspector.toString(dataHeader));
EVAERROR.errorMsgOnce("Warning, mismatching number of headers and additional data fields for " + inf.getClass() + " ("+dataHeader.length+ " vs. " + infos.length + ").");
}
infoFields.addAll(Arrays.asList(infos));
}
while (infoFields.size()<headerFields.size()) infoFields.add(null); while (infoFields.size()<headerFields.size()) infoFields.add(null);
} }
// header += inf.getAdditionalDataHeader(null); // lets hope this works with a null // header += inf.getAdditionalDataHeader(null); // lets hope this works with a null