Minor adaptations.

This commit is contained in:
Marcel Kronfeld
2008-04-11 11:39:24 +00:00
parent 50511b0ed5
commit 7633618f59
18 changed files with 180 additions and 84 deletions

View File

@@ -142,4 +142,14 @@ public class OptimizerRunnable implements Runnable {
return ((InterfaceDataTypeInteger)indy).getIntegerData();
} else return null;
}
/**
* Set the verbosity level in the statistics module to the given value. See StatsParameter.
* @param vLev
*/
public void setVerbosityLevel(int vLev) {
if (vLev >= 0 && vLev < proc.getStatistics().getStatisticsParameter().getOutputVerbosity().getTags().length) {
proc.getStatistics().getStatisticsParameter().getOutputVerbosity().setSelectedTag(vLev);
} else System.err.println("Invalid verbosity leveln in OptimizerRunnable.setVerbosityLevel!");
}
}

View File

@@ -22,6 +22,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import wsi.ra.jproxy.RMIProxyLocal;
@@ -86,6 +87,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
m_Adapter.startOpt();
m_actStop.setEnabled(true);
m_RunButton.setEnabled(false);
m_PPButton.setEnabled(false);
// m_RestartButton.setEnabled(false);
m_JHelpButton.setEnabled(true);
} catch (Exception ee) {
@@ -124,7 +126,7 @@ public class JModuleGeneralPanel implements RemoteStateListener, Serializable {
m_PPButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
try {
m_Adapter.startPostProcessing();
if (!m_Adapter.startPostProcessing()) JOptionPane.showMessageDialog(null, "Post processing seems deactivated! Check the settings.", "Warning", JOptionPane.WARNING_MESSAGE);
// m_actStop.setEnabled(true);
// m_RunButton.setEnabled(false);
} catch (Exception ee) {

View File

@@ -9,9 +9,10 @@ import javaeva.server.go.individuals.ESIndividualDoubleData;
* Time: 19:15:03
* To change this template use File | Settings | File Templates.
*/
public class F14Problem extends F1Problem implements java.io.Serializable {
public class F14Problem extends F1Problem implements InterfaceMultimodalProblem, java.io.Serializable {
double rotation = 0.;
double rotationDX = 2;
public F14Problem() {
this.m_Template = new ESIndividualDoubleData();
this.m_ProblemDimension = 2;
@@ -35,8 +36,8 @@ public class F14Problem extends F1Problem implements java.io.Serializable {
*/
public double[] eval(double[] x) {
double[] result = new double[1];
double x0 = x[0]-2;
double x1 = x[1]-2;
double x0 = x[0]-rotationDX;
double x1 = x[1]-rotationDX;
if (rotation != 0.) {
double cosw = Math.cos(rotation);
double sinw = Math.sin(rotation);
@@ -59,6 +60,10 @@ public class F14Problem extends F1Problem implements java.io.Serializable {
public void setRotation(double rotation) {
this.rotation = 2 * Math.PI * rotation / 360.0;
}
public String rotationTipText() {
return "The rotation angle in degrees.";
}
/** This method returns a string describing the optimization problem.
* @return The description.
@@ -67,7 +72,7 @@ public class F14Problem extends F1Problem implements java.io.Serializable {
String result = "";
result += "F14 function:\n";
result += "Several local minima in a straight line\n";
result += "Several local minima in linear order which may be rotated.\n";
//result += this.m_Template.getSolutionRepresentationFor();
return result;
}
@@ -80,13 +85,13 @@ public class F14Problem extends F1Problem implements java.io.Serializable {
* @return The name.
*/
public String getName() {
return "F14 Problem";
return "F14-Problem";
}
/** This method returns a global info string
* @return description
*/
public String globalInfo() {
return "F14 function.";
return "F14 function: numerous optima in linear order which may be rotated.";
}
}

View File

@@ -32,7 +32,7 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
transient PrintStream dos = null;
protected double[][] range = null;
private static final String defTestOut = "matlabproblem-testout.dat";
boolean forwardStatisticsOutput = false;
int verbosityLevel = 0;
private MatlabEvalMediator handler = null;
public static boolean hideFromGOE = true;
@@ -133,8 +133,11 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
// this.jmInterface = jmInterface;
// }
public void setStatsOutput(boolean forwardStats) {
forwardStatisticsOutput = forwardStats;
public void setStatsOutput(int verboLevel) {
if ((verboLevel >= 0) && (verboLevel <= 3)) {
verbosityLevel = verboLevel;
}
else System.err.println("Error, invalid verbosity level for statistics output!");
}
public String jmiInterfaceNameTipText() {
@@ -225,6 +228,8 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
runnable = OptimizerFactory.getOptRunnable(optType, (AbstractOptimizationProblem)this, outputFilePrefix);
// runnable.getGOParams().setPostProcessParams(new PostProcessParams(0, 0.01, 5));
runnable.setTextListener(this);
runnable.setVerbosityLevel(verbosityLevel);
if ((specParams != null) && (specParams.length > 0)) {
if ((specValues == null) || (specValues.length != specParams.length)) {
System.err.println("mismatching value list for parameter arguments: " + specValues);
@@ -388,7 +393,7 @@ public class MatlabProblem extends AbstractProblemDouble implements InterfaceTex
}
public void print(String str) {
if (forwardStatisticsOutput) {
if (verbosityLevel > 0) {
// matlab displays sysout output in the command window, so we simply use this channel
System.out.print(str);
}

View File

@@ -56,8 +56,8 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
protected int m_TopologyRange = 2;
protected double m_InitialVelocity = 0.2;
protected double m_SpeedLimit = 0.1;
protected double m_Phi1 = 2.8;
protected double m_Phi2 = 1.3;
protected double m_Phi1 = 2.05;
protected double m_Phi2 = 2.05;
// for multi-swarm topology: radius of the swarm relative to the range
protected double m_swarmRadius = 0.2;
// for multi-swarm: maximum sub swarm size. zero means unlimited
@@ -105,7 +105,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
public ParticleSwarmOptimization() {
this.m_Topology = new SelectedTag( "Linear", "Grid", "Star", "Multi-Swarm", "Tree", "HPSO", "Random" );
m_Topology.setSelectedTag(2);
m_Topology.setSelectedTag(1);
algType = new SelectedTag("Inertness", "Constriction");
algType.setSelectedTag(1);
@@ -1680,7 +1680,7 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
setGOEShowProperties(getClass());
}
public void setGOEShowProperties(Class cls) {
public void setGOEShowProperties(Class<?> cls) {
GenericObjectEditor.setShowProperty(cls, "topologyRange", (m_Topology.getSelectedTag().getID() < 2) || (m_Topology.getSelectedTag().getID() == 6));
GenericObjectEditor.setShowProperty(cls, "subSwarmRadius", (m_Topology.getSelectedTag().getID() == 3));
GenericObjectEditor.setShowProperty(cls, "subSwarmSize", (m_Topology.getSelectedTag().getID() == 3));
@@ -1821,17 +1821,18 @@ public class ParticleSwarmOptimization implements InterfaceOptimizer, java.io.Se
return treeStruct;
}
public void setTreeStruct(int treeStruct) {
public void SetTreeStruct(int treeStruct) {
this.treeStruct = treeStruct;
}
public boolean isUseAlternative() {
return useAlternative;
}
public void setUseAlternative(boolean useAlternative) {
this.useAlternative = useAlternative;
}
// This was for testing rotation operators
// public boolean isUseAlternative() {
// return useAlternative;
// }
//
// public void setUseAlternative(boolean useAlternative) {
// this.useAlternative = useAlternative;
// }
public int getTreeBranchDegree() {
return treeBranchDeg;

View File

@@ -19,9 +19,6 @@ import java.util.Vector;
import javaeva.gui.JTabbedModuleFrame;
import javaeva.gui.LogPanel;
import javaeva.server.go.InterfaceProcessor;
import javaeva.server.go.operators.postprocess.PostProcessParams;
import javaeva.server.stat.InterfaceTextListener;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RemoteStateListener;
/*==========================================================================*
@@ -112,11 +109,14 @@ abstract public class AbstractModuleAdapter implements ModuleAdapter, Serializab
}
public boolean hasPostProcessing() {
return (m_Processor instanceof Processor);
return ((m_Processor instanceof Processor) && ((Processor)m_Processor).getGOParams().getPostProcessParams().isDoPostProcessing());
}
public void startPostProcessing() {
if (hasPostProcessing()) ((Processor)m_Processor).performPostProcessing();
public boolean startPostProcessing() {
if (hasPostProcessing() && ((Processor)m_Processor).getGOParams().getPostProcessParams().isDoPostProcessing()) {
((Processor)m_Processor).performPostProcessing();
return true;
} else return false;
}
/**

View File

@@ -29,8 +29,16 @@ public interface ModuleAdapter extends RemoteStateListener {
public void restartOpt();
public void stopOpt();
public void runScript();
/**
* Return true if post processing is available in principle, else false.
* @return true if post processing is available in principle, else false
*/
public boolean hasPostProcessing();
public void startPostProcessing();
/**
* Return true if post processing was performed, else false.
* @return true if post processing was performed, else false
*/
public boolean startPostProcessing();
public void addRemoteStateListener(RemoteStateListener x);
public String getAdapterName();
public void setConnection(boolean flag);

View File

@@ -14,6 +14,7 @@ import javaeva.server.go.problems.AbstractOptimizationProblem;
import javaeva.server.go.tools.RandomNumberGenerator;
import javaeva.server.stat.InterfaceStatistics;
import javaeva.server.stat.InterfaceTextListener;
import javaeva.server.stat.StatisticsWithGUI;
import wsi.ra.jproxy.RemoteStateListener;
/**
@@ -144,8 +145,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
e.printStackTrace();
//m_Statistics.stopOptPerformed(false);
setOptRunning(false); // normal finish
if (m_ListenerModule!=null) m_ListenerModule.performedStop(); // is only needed in client server mode
if (m_ListenerModule!=null) m_ListenerModule.updateProgress(0, "Error in optimization: " + e.getMessage());
if (m_ListenerModule!=null) {
m_ListenerModule.performedStop(); // is only needed in client server mode
String errMsg = e.getMessage();
if ((errMsg == null) || (errMsg.length() == 0)) errMsg="check console output for error messages.";
m_ListenerModule.updateProgress(0, "Error in optimization: " + errMsg);
}
}
return resPop;
}
@@ -266,7 +271,7 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
public String getInfoString() {
//StringBuffer sb = new StringBuffer("processing ");
StringBuffer sb = new StringBuffer(this.goParams.getProblem().getName());
sb.append("/");
sb.append("+");
sb.append(this.goParams.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)
@@ -315,7 +320,11 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
*/
public Population performPostProcessing(PostProcessParams ppp, InterfaceTextListener listener) {
if (ppp.isDoPostProcessing()) {
if (listener != null) listener.println("Post processing params: " + BeanInspector.toString(ppp));
if (listener != null) {
listener.println("Post processing params: " + BeanInspector.toString(ppp));
// if textwindow was closed, check if it should be reopened for pp
if (m_Statistics instanceof StatisticsWithGUI) ((StatisticsWithGUI)m_Statistics).maybeShowProxyPrinter();
}
Population resultPop = goParams.getOptimizer().getAllSolutions();
if (resultPop.getFunctionCalls() != goParams.getOptimizer().getPopulation().getFunctionCalls()) {
// System.err.println("bad case in Processor::performNewPostProcessing ");

View File

@@ -18,8 +18,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
private PrintWriter resultOut;
public final static boolean TRACE = false;
protected InterfaceStatisticsParameter m_StatsParams;
protected String startDate;
protected long startTime;
// protected String startDate;
// protected long startTime;
/**
* Keep track of all intermediate fitness values, best, avg. and worst, averaging over all runs
@@ -70,20 +70,22 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
return textListeners.remove(listener);
}
protected void initOutput() {
SimpleDateFormat formatter = new SimpleDateFormat(
"E'_'yyyy.MM.dd'_at_'hh.mm.ss");
startDate = formatter.format(new Date());
startTime = System.currentTimeMillis();
/**
* Collect start date and time of the run and if indicated, open a file output stream.
*
* @param infoString
*/
protected void initOutput(String infoString) {
SimpleDateFormat formatter = new SimpleDateFormat("E'_'yyyy.MM.dd'_at_'hh.mm.ss");
String startDate = formatter.format(new Date());
// open the result file:
String resFName = m_StatsParams.getResultFileName();
if ((m_StatsParams.getOutputTo().getSelectedTagID()!=1) // not "text only"
&& (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatsParameter.VERBOSITY_NONE)) { // verbosity accordingly high
//!resFName.equalsIgnoreCase("none") && !resFName.equals("")) {
String name = resFName + "_" + startDate + ".txt";
if (TRACE) System.out.println("FileName =" + name);
String fname = makeOutputFileName(m_StatsParams.getResultFilePrefix(), infoString, startDate);
if (TRACE) System.out.println("FileName =" + fname);
try {
resultOut = new PrintWriter(new FileOutputStream(name));
resultOut = new PrintWriter(new FileOutputStream(fname));
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error: " + e);
@@ -93,6 +95,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
} else resultOut = null;
}
private String makeOutputFileName(String prefix, String infoString, String startDate) {
return (prefix + "_" + infoString).replace(' ', '_') + "_" + startDate + ".txt";
}
/**
* If set to true, before every run the parameters will be stored to a file at the start
* of each run. Default is true.
@@ -111,7 +116,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
optRunsPerformed = 0;
convergenceCnt = 0;
if (saveParams) m_StatsParams.saveInstance();
initOutput();
initOutput(infoString);
bestCurrentIndividual = null;
bestIndivdualAllover = null;
if (refineMultiRuns) meanCollection = new ArrayList<double[][]>();

View File

@@ -46,8 +46,8 @@ public interface InterfaceStatisticsParameter {
public SelectedTag getPlotFitness();
public void setPlotFitness(SelectedTag newMethod);
public String getResultFileName();
public void SetResultFileName(String x);
public String getResultFilePrefix();
public void SetResultFilePrefix(String x);
public void setConvergenceRateThreshold(double x);
public double getConvergenceRateThreshold();

View File

@@ -70,7 +70,7 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
*/
public StatisticsStandalone(String resultFileName) {
this(new StatsParameter());
m_StatsParams.SetResultFileName(resultFileName);
m_StatsParams.SetResultFilePrefix(resultFileName);
}
/**

View File

@@ -100,7 +100,6 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
*/
public synchronized void startOptPerformed(String infoString, int runNumber, Object goParams) {
super.startOptPerformed(infoString, runNumber, goParams);
m_GraphInfoString = infoString;
// m_TextCounter = m_StatisticsParameter.GetTextoutput();
@@ -136,11 +135,15 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
// m_ConvergenceCnt = 0;
// }
}
public void maybeShowProxyPrinter() {
if (m_ProxyPrinter != null) m_ProxyPrinter.setShow((m_StatsParams).isShowTextOutput());
}
protected void initPlots(List<String[]> description) {
if (TRACE) System.out.println("initPlots");
if (m_ProxyPrinter != null) m_ProxyPrinter.setShow((m_StatsParams).isShowTextOutput());
maybeShowProxyPrinter();
m_FitnessFrame = new GraphWindow[description.size()];
for (int i = 0; i < m_FitnessFrame.length; i++) {

View File

@@ -41,7 +41,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
public final static int VERBOSITY_FINAL = 1;
public final static int VERBOSITY_KTH_IT = 2;
public final static int VERBOSITY_ALL = 3;
SelectedTag outputVerbosity = new SelectedTag("No output", "Results", "K-th iteration", "All iterations");
SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations");
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
private int verboK = 10;
@@ -125,6 +125,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix;
verboK = Source.verboK;
}
/**
@@ -268,7 +269,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
/**
*
*/
public void SetResultFileName(String x) {
public void SetResultFilePrefix(String x) {
if (x==null) m_ResultFilePrefix = "";
else m_ResultFilePrefix = x;
}
@@ -276,7 +277,7 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
/**
*
*/
public String getResultFileName() {
public String getResultFilePrefix() {
return m_ResultFilePrefix;
}