Refactor Statistics and log number of multiruns to show process.

This commit is contained in:
Fabian Becker 2013-10-12 00:49:08 +02:00
parent 10612f177a
commit 5e94821eb5
6 changed files with 25 additions and 86 deletions

View File

@ -108,7 +108,7 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab
public void setOptimizationParameters(InterfaceOptimizationParameters goParams) { public void setOptimizationParameters(InterfaceOptimizationParameters goParams) {
if ((processor != null) && (processor instanceof Processor)) { if ((processor != null) && (processor instanceof Processor)) {
((Processor) processor).setGOParams(goParams); ((Processor) processor).setOptimizationParameters(goParams);
} }
} }

View File

@ -230,6 +230,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
String popLog = null; //"populationLog.txt"; String popLog = null; //"populationLog.txt";
while (isOptimizationRunning() && (runCounter < statistics.getStatisticsParameter().getMultiRuns())) { while (isOptimizationRunning() && (runCounter < statistics.getStatisticsParameter().getMultiRuns())) {
LOGGER.info(String.format("Starting Optimization %d/%d", runCounter + 1, statistics.getStatisticsParameter().getMultiRuns()));
statistics.startOptPerformed(getInfoString(), runCounter, optimizationParameters, getInformerList()); statistics.startOptPerformed(getInfoString(), runCounter, optimizationParameters, getInformerList());
this.optimizationParameters.getProblem().initializeProblem(); this.optimizationParameters.getProblem().initializeProblem();
@ -240,7 +241,6 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
this.optimizationParameters.getOptimizer().init(); this.optimizationParameters.getOptimizer().init();
} }
//statistics.createNextGenerationPerformed((PopulationInterface)this.m_ModulParameter.getOptimizer().getPopulation());
if (optimizationStateListener != null) { if (optimizationStateListener != null) {
optimizationStateListener.updateProgress(getStatusPercent(optimizationParameters.getOptimizer().getPopulation(), runCounter, statistics.getStatisticsParameter().getMultiRuns()), null); optimizationStateListener.updateProgress(getStatusPercent(optimizationParameters.getOptimizer().getPopulation(), runCounter, statistics.getStatisticsParameter().getMultiRuns()), null);
} }
@ -257,8 +257,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
if (popLog != null) { if (popLog != null) {
EVAHELP.logString(this.optimizationParameters.getOptimizer().getPopulation().getIndyList(), popLog); EVAHELP.logString(this.optimizationParameters.getOptimizer().getPopulation().getIndyList(), popLog);
} }
} } while (isOptimizationRunning() && !this.optimizationParameters.getTerminator().isTerminated(this.optimizationParameters.getOptimizer().getAllSolutions()));
while (isOptimizationRunning() && !this.optimizationParameters.getTerminator().isTerminated(this.optimizationParameters.getOptimizer().getAllSolutions()));
runCounter++; runCounter++;
maybeFinishParamCtrl(optimizationParameters); maybeFinishParamCtrl(optimizationParameters);
userAborted = !isOptimizationRunning(); // stop is "normal" if opt wasnt set false by the user (and thus still true) userAborted = !isOptimizationRunning(); // stop is "normal" if opt wasnt set false by the user (and thus still true)
@ -403,33 +403,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
return informerList; return informerList;
} }
/**
* This method writes Data to file.
*
* @param line The line that is to be added to the file
*/
// private void writeToFile(String line) {
// //String write = line + "\n";
// if (this.m_OutputFile == null) return;
// try {
// this.m_OutputFile.write(line, 0, line.length());
// this.m_OutputFile.write('\n');
// this.m_OutputFile.flush();
// } catch (IOException e) {
// System.err.println("Problems writing to output file!");
// }
// }
@Override @Override
public String getInfoString() { public String getInfoString() {
//StringBuffer sb = new StringBuffer("processing "); //StringBuffer sb = new StringBuffer("processing ");
StringBuilder sb = new StringBuilder(this.optimizationParameters.getProblem().getName()); StringBuilder sb = new StringBuilder(this.optimizationParameters.getProblem().getName());
sb.append("+"); sb.append("+");
sb.append(this.optimizationParameters.getOptimizer().getName()); sb.append(this.optimizationParameters.getOptimizer().getName());
// commented out because the number of multi-runs can be changed after start
// so it might create misinformation (would still be the user's fault, though)
// sb.append(" for ");
// sb.append(statistics.getStatistisParameter().getMultiRuns());
// sb.append(" runs");
return sb.toString(); return sb.toString();
} }
@ -447,11 +426,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
return optimizationParameters; return optimizationParameters;
} }
public void setGOParams(InterfaceOptimizationParameters params) { public void setOptimizationParameters(InterfaceOptimizationParameters params) {
if (params != null) { if (params != null) {
optimizationParameters = params; optimizationParameters = params;
} else { } else {
System.err.println("Setting parameters failed (parameters were null) (Processor.setGOParams)"); System.err.println("Setting parameters failed (parameters were null) (Processor.setOptimizationParameters)");
} }
} }
@ -487,16 +466,8 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
} }
Population resultPop = (Population) (optimizationParameters.getOptimizer().getAllSolutions().getSolutions().clone()); Population resultPop = (Population) (optimizationParameters.getOptimizer().getAllSolutions().getSolutions().clone());
if (resultPop.getFunctionCalls() != optimizationParameters.getOptimizer().getPopulation().getFunctionCalls()) { if (resultPop.getFunctionCalls() != optimizationParameters.getOptimizer().getPopulation().getFunctionCalls()) {
// System.err.println("bad case in Processor::performNewPostProcessing ");
resultPop.setFunctionCalls(optimizationParameters.getOptimizer().getPopulation().getFunctionCalls()); resultPop.setFunctionCalls(optimizationParameters.getOptimizer().getPopulation().getFunctionCalls());
} }
// if (!resultPop.contains(statistics.getBestSolution())) {
// resultPop.add(statistics.getBestSolution());
// this is a minor cheat but guarantees that the best solution ever found is contained in the final results
// This was evil in case multiple runs were performed with PP, because the best of an earlier run is added which is confusing.
// the minor cheat should not be necessary anymore anyways, since the getAllSolutions() variant replaced the earlier getPopulation() call
// resultPop.synchSize();
// }
PostProcess.checkAccuracy((AbstractOptimizationProblem) optimizationParameters.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(), PostProcess.checkAccuracy((AbstractOptimizationProblem) optimizationParameters.getProblem(), resultPop, ppp.getAccuracies(), ppp.getAccAssumeConv(),
-1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener); -1, ppp.getAccMaxEval(), (SolutionHistogram[]) null, true, listener);

View File

@ -219,7 +219,6 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
System.out.println("Error: " + e); System.out.println("Error: " + e);
} }
resultOut.println("StartDate:" + startDate); resultOut.println("StartDate:" + startDate);
resultOut.println("On Host:" + getHostName());
} else { } else {
resultOut = null; resultOut = null;
} }
@ -652,34 +651,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
sbuf.append("\n"); sbuf.append("\n");
} }
} }
// double[][] mean;
// StringBuffer sbuf = new StringBuffer("Iteration\tFun.Calls\tBest\tMean\tWorst\n");
// double step = result.size()/(iterationsToShow-1.);
// int printedIteration=0;
//
// for(int i = 1; i < result.size()+1; i++) {
// // print the first, last and intermediate iterations requested by the integer parameter
// // first one is printed always, as printedIteration=0
// if ((i==result.size()) || ((i-1)==Math.round(printedIteration*step))) {
// printedIteration++;
// mean = result.get(i-1);
// sbuf.append(i);
// sbuf.append("\t");
// sbuf.append(BeanInspector.toString(mean[0]));
// sbuf.append("\t");
// sbuf.append(BeanInspector.toString(mean[1]));
// sbuf.append("\t");
// sbuf.append(BeanInspector.toString(mean[2]));
// sbuf.append("\t");
// sbuf.append(BeanInspector.toString(mean[3]));
// sbuf.append("\n");
// }
// }
// return sbuf.toString();
} }
public abstract String getHostName();
@Override @Override
public void printToTextListener(String s) { public void printToTextListener(String s) {

View File

@ -6,7 +6,7 @@ import eva2.tools.StringSelection;
/** /**
* An interface to encapsulate statistics parameters. * An interface to encapsulate statistics parameters.
* *
* @see StatsParameter * @see StatisticsParameter
*/ */
public interface InterfaceStatisticsParameter { public interface InterfaceStatisticsParameter {
String getName(); String getName();

View File

@ -44,12 +44,12 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window"); SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
private int verboK = 10; private int verboK = 10;
private int m_Textoutput = 0; private int m_Textoutput = 0;
private int m_MultiRuns = 1; private int multiRuns = 1;
private String m_ResultFilePrefix = "EvA2"; private String resultFilePrefix = "EvA2";
protected String m_Name = "not defined"; protected String m_Name = "not defined";
private boolean m_useStatPlot = true; private boolean useStatPlot = true;
private boolean showAdditionalProblemInfo = false; private boolean showAdditionalProblemInfo = false;
private double m_ConvergenceRateThreshold = 0.001; private double convergenceRateThreshold = 0.001;
private StringSelection graphSel = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings()); private StringSelection graphSel = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings());
/** /**
@ -97,7 +97,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public String toString() { public String toString() {
String ret = "\r\nStatisticsParameter (" + super.toString() + "):\r\nm_MultiRuns=" + m_MultiRuns String ret = "\r\nStatisticsParameter (" + super.toString() + "):\r\nmultiRuns=" + multiRuns
+ ", m_Textoutput=" + m_Textoutput + ", m_Textoutput=" + m_Textoutput
+ // ", m_Plotoutput=" + m_Plotoutput + + // ", m_Plotoutput=" + m_Plotoutput +
", verbosity= " + outputVerbosity.getSelectedString() ", verbosity= " + outputVerbosity.getSelectedString()
@ -123,13 +123,13 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
* *
*/ */
private StatisticsParameter(StatisticsParameter Source) { private StatisticsParameter(StatisticsParameter Source) {
m_ConvergenceRateThreshold = Source.m_ConvergenceRateThreshold; convergenceRateThreshold = Source.convergenceRateThreshold;
m_useStatPlot = Source.m_useStatPlot; useStatPlot = Source.useStatPlot;
m_Textoutput = Source.m_Textoutput; m_Textoutput = Source.m_Textoutput;
// m_Plotoutput = Source.m_Plotoutput; // m_Plotoutput = Source.m_Plotoutput;
// m_PlotFitness = Source.m_PlotFitness; // m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns; multiRuns = Source.multiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix; resultFilePrefix = Source.resultFilePrefix;
verboK = Source.verboK; verboK = Source.verboK;
} }
@ -153,7 +153,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public void setMultiRuns(int x) { public void setMultiRuns(int x) {
m_MultiRuns = x; multiRuns = x;
} }
/** /**
@ -161,7 +161,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public int getMultiRuns() { public int getMultiRuns() {
return m_MultiRuns; return multiRuns;
} }
/** /**
@ -184,7 +184,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public boolean getUseStatPlot() { public boolean getUseStatPlot() {
return m_useStatPlot; return useStatPlot;
} }
/** /**
@ -192,7 +192,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public void setUseStatPlot(boolean x) { public void setUseStatPlot(boolean x) {
m_useStatPlot = x; useStatPlot = x;
} }
public String useStatPlotTipText() { public String useStatPlotTipText() {
@ -205,9 +205,9 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
@Override @Override
public void setResultFilePrefix(String x) { public void setResultFilePrefix(String x) {
if (x == null) { if (x == null) {
m_ResultFilePrefix = ""; resultFilePrefix = "";
} else { } else {
m_ResultFilePrefix = x; resultFilePrefix = x;
} }
} }
@ -216,7 +216,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public String getResultFilePrefix() { public String getResultFilePrefix() {
return m_ResultFilePrefix; return resultFilePrefix;
} }
@Override @Override
@ -250,7 +250,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public void setConvergenceRateThreshold(double x) { public void setConvergenceRateThreshold(double x) {
m_ConvergenceRateThreshold = x; convergenceRateThreshold = x;
} }
/** /**
@ -258,7 +258,7 @@ public class StatisticsParameter implements InterfaceStatisticsParameter, Interf
*/ */
@Override @Override
public double getConvergenceRateThreshold() { public double getConvergenceRateThreshold() {
return m_ConvergenceRateThreshold; return convergenceRateThreshold;
} }
@Override @Override

View File

@ -267,9 +267,4 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
} }
// } // }
} }
@Override
public String getHostName() {
return hostName;
}
} }