Minor addition to MatlabInterface (flag to deactivate output of all statistic fields which is time-consuming for large populations)

This commit is contained in:
Marcel Kronfeld 2011-02-15 15:36:41 +00:00
parent f7917e62c2
commit 510add738e
6 changed files with 38 additions and 7 deletions

View File

@ -58,6 +58,7 @@ int.optParams = [];
int.optParamValues = [];
int.hexMask=hex2dec('ffffffff');
int.dataType=''; % to be set later!
int.outputAllStatsFields=1;
if (isa(fhandle, 'function_handle'))
int.f = fhandle;

View File

@ -77,6 +77,7 @@ if ((nargin == 2) || (nargin == 3))
eva2.OptimizerFactory.addTerminator(EvaluationTerminator(maxEvals), 0);
end
end
int.mp.setOutputAllStatFields(int.outputAllStatsFields==1);
% set display
if (strcmp(int.opts.Display,'off') || isempty(int.opts.Display))

View File

@ -0,0 +1,8 @@
function int = setOutputAllStatsFields(int, doOutputAllFields)
% (De-)Activate printing all available statistic data to the text log. Deactivation may
% improve performance for larger population sizes.
% int = setOutputAllStatsFields(int, doOutputAllFields)
% int: instance of JEInterface
% doOutputAllFields: 1 or 0 for activation or deactivation, respectively
int.outputAllStatsFields=doOutputAllFields;

View File

@ -177,12 +177,12 @@ public class MatlabEvalMediator {
* @return
*/
public Object getQuestion() {
logMP("-- Question: " + BeanInspector.toString(question) + "\n");
if (mp!=null) logMP("-- Question: " + BeanInspector.toString(question) + "\n");
return question;
}
double[] getAnswer() {
logMP("-- mediator delivering " + BeanInspector.toString(answer) + "\n");
if (mp!=null) logMP("-- mediator delivering " + BeanInspector.toString(answer) + "\n");
return answer;
}

View File

@ -51,6 +51,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
// private static String resOutFile = "matlabproblem-output.txt";
// transient PrintStream resOutStream = null;
int verbosityLevel = 0;
boolean outputAllStatsField = true;
private MatlabEvalMediator handler = null;
// private boolean isDouble = true;
private MatlabProblemDataTypeEnum dataType = MatlabProblemDataTypeEnum.typeDouble;
@ -345,7 +346,7 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
runnable.setVerbosityLevel(verbosityLevel);
if (verbosityLevel>0) runnable.setOutputTo(2); // both file + window
else runnable.setOutputTo(1); // only window
runnable.setOutputFullStatsToText(true);
runnable.setOutputFullStatsToText(outputAllStatsField);
// log("in MP optimize C\n");
if ((specParams != null) && (specParams.length > 0)) {
@ -383,6 +384,10 @@ public class MatlabProblem extends AbstractOptimizationProblem implements Interf
}
}
public void setOutputAllStatFields(boolean showAll) {
outputAllStatsField=showAll;
}
public void startPostProcess(InterfacePostProcessParams ppp) {
if (ppp.isDoPostProcessing()) {
if (allowSingleRunnable && (runnable != null) && (!runnable.isFinished())) {

View File

@ -1028,29 +1028,40 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
public synchronized void createNextGenerationPerformed(PopulationInterface
pop, InterfaceOptimizer opt, List<InterfaceAdditionalPopulationInformer> informerList) {
lastInformerList = informerList;
if (TRACE) printToTextListener(".. in createNextGenPerformed after " + pop.getFunctionCalls() + " evals.\n");
if (resultOut != null) resultOut.flush();
if (firstPlot) {
initPlots(pop, informerList);
// if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n');
firstPlot = false;
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
plotSpecificData(pop, informerList);
return;
}
if (TRACE) printToTextListener("A2\n");
collectPopData(pop);
if (TRACE) printToTextListener("A3\n");
if (iterationCounter==0) {
if (TRACE) printToTextListener("A3.1 " + currentStatHeader.length + "\n");
String headerLine = StringTools.concatFields(currentStatHeader, textFieldDelimiter);
if (TRACE) printToTextListener("A3.2\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;
// Pair<String,Double[]> addData = getOutputData(informerList, lastSols);
// System.out.println("lastSols size: " + 500*PSymbolicRegression.getAvgIndySize(lastSols));
// System.out.println("Mem use: " + getMemoryUse());
if (TRACE) printToTextListener("A5\n");
Pair<String,Object[]> addData = getOutputData(informerList, lastSols);
if (doTextOutput()) { // this is where the text output is actually written
if (printLineByVerbosity(iterationCounter)) {
@ -1058,6 +1069,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
printToTextListener(addData.head()+'\n');
}
}
if (TRACE) printToTextListener("A6\n");
currentStatObjectData = addData.tail();
currentStatDoubleData = ToolBox.parseDoubles(currentStatObjectData);
if (currentStatObjectData!=null) {
@ -1065,6 +1078,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} else {
System.err.println("Warning in AbstractStatistics!");
}
if (TRACE) printToTextListener("A7\n");
if (sumDataCollection != null) {
// Collect average data
@ -1085,7 +1099,8 @@ 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 (TRACE) printToTextListener("A8\n");
// if (doTextOutput()) {
// Pair<String,Double[]> addInfo = getOutputLine(informerList, lastSols);
//
@ -1099,7 +1114,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
// }
plotCurrentResults();
fireDataListeners();
if (TRACE) printToTextListener(".. done createNextGenPerformed after " + pop.getFunctionCalls() + " evals.\n");
if (resultOut != null) resultOut.flush();
iterationCounter++;
}