Merging MK revs 298:303 - simple plot legend, some additions for statistics on feasibility

This commit is contained in:
Marcel Kronfeld
2009-06-22 15:44:24 +00:00
parent 52d707f0e0
commit 014258e1a4
14 changed files with 587 additions and 174 deletions

View File

@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.Date;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
@@ -57,9 +58,12 @@ public class FunctionArea extends DArea implements Serializable {
private ScaledBorder m_Border;
private boolean m_log = false;
private boolean notifyNegLog = true;
private boolean m_legend = true;
private int m_x;
private int m_y;
private GraphPointSetLegend legendBox = null;
private DPointIcon m_CurrentPointIcon;
/**
*
@@ -90,6 +94,16 @@ public class FunctionArea extends DArea implements Serializable {
notifyNegLog = true;
}
/**
* Set a legend for the function area. If null is given, the former legend is deactivated.
*
* @param lBox
*/
protected void setLegend(GraphPointSetLegend lBox) {
legendBox=lBox;
if (lBox!=null && m_legend) repaint();
}
/**
* Plot a circle icon to the function area which is annotated with a char and
* a double value.
@@ -172,7 +186,7 @@ public class FunctionArea extends DArea implements Serializable {
popRep.setIcon(icon);
addDElement(popRep);
}
/**
*
*/
@@ -181,8 +195,8 @@ public class FunctionArea extends DArea implements Serializable {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
return ret;
int minindex = getNearestGraphIndex(x, y);
ret = ((GraphPointSet) (m_PointSetContainer.get(minindex))).getInfoString();
return ret;
if (minindex>=0) return ((GraphPointSet) (m_PointSetContainer.get(minindex))).getInfoString();
else return "none";
}
/**
@@ -196,8 +210,7 @@ public class FunctionArea extends DArea implements Serializable {
ret = ((GraphPointSet) (m_PointSetContainer.get(minindex))).isStatisticsGraph();
return ret;
}
/**
*
*/
@@ -209,20 +222,18 @@ public class FunctionArea extends DArea implements Serializable {
DPoint point2 = null;
double dist = 0;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
if (m_PointSetContainer.get(i)instanceof GraphPointSet) {
GraphPointSet pointset = (GraphPointSet) (m_PointSetContainer.get(i));
point2 = pointset.getNearestDPoint(point1);
if (point2 == null)
continue;
if (point1 == null)
System.err.println("point1 == null");
GraphPointSet pointset = m_PointSetContainer.get(i);
point2 = pointset.getNearestDPoint(point1);
if (point2 == null)
continue;
if (point1 == null)
System.err.println("point1 == null");
dist = (point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y);
//System.out.println("dist="+dist+"i="+i);
if (dist < distmin) {
distmin = dist;
minindex = i;
}
dist = (point1.x - point2.x) * (point1.x - point2.x) + (point1.y - point2.y) * (point1.y - point2.y);
//System.out.println("dist="+dist+"i="+i);
if (dist < distmin) {
distmin = dist;
minindex = i;
}
}
return minindex;
@@ -350,7 +361,13 @@ public class FunctionArea extends DArea implements Serializable {
}
/**
@Override
public void paint(Graphics g) {
super.paint(g);
if (legendBox!=null && (m_legend)) legendBox.paintIn(g, m_Border.getInnerRect(this));
}
/**
*
*/
public void setConnectedPoint(double[] p, int graphLabel) {
@@ -428,6 +445,7 @@ public class FunctionArea extends DArea implements Serializable {
return;
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index))).getGraphLabel();
clearGraph(GraphLabel);
updateLegend();
}
/**
@@ -439,6 +457,7 @@ public class FunctionArea extends DArea implements Serializable {
return;
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index))).getGraphLabel();
changeColorGraph(GraphLabel);
updateLegend();
}
/**
@@ -589,7 +608,7 @@ public class FunctionArea extends DArea implements Serializable {
//setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
setYScale(new Exp());
m_Border.setSrcdY(Math.log(10));
((java.text.DecimalFormat) m_Border.format_y).applyPattern("0.###E0");
m_Border.applyPattern(false, "0.###E0");
m_log = true;
} else {
m_log = false;
@@ -769,6 +788,14 @@ public class FunctionArea extends DArea implements Serializable {
}
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
JMenuItem togLegend = new JMenuItem("Toggle legend");
togLegend.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
toggleLegend();
}
});
GraphMenu.add(togLegend);
JMenuItem removeGraph = new JMenuItem("Remove graph");
removeGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
@@ -776,8 +803,7 @@ public class FunctionArea extends DArea implements Serializable {
}
});
GraphMenu.add(removeGraph);
}
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
JMenuItem changecolorGraph = new JMenuItem("Change color");
changecolorGraph.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
@@ -785,8 +811,7 @@ public class FunctionArea extends DArea implements Serializable {
}
});
GraphMenu.add(changecolorGraph);
}
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
JMenuItem removePoint = new JMenuItem("Remove point");
removePoint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ee) {
@@ -795,36 +820,13 @@ public class FunctionArea extends DArea implements Serializable {
});
GraphMenu.add(removePoint);
}
// if (isStatisticsGraph(e.getX(),e.getY())==true) {
// if (getVar(e.getX(),e.getY())==false) {
// JMenuItem showVar = new JMenuItem("Show varianz ");
// showVar.addActionListener(new ActionListener() {
// //
// public void actionPerformed(ActionEvent ee) {
// setVar(m_x,m_y,true);
// }
// });
// GraphMenu.add(showVar);
// }
// else {
// JMenuItem hideVar = new JMenuItem("Hide varianz ");
// hideVar.addActionListener(new ActionListener() {
// //
// public void actionPerformed(ActionEvent ee) {
// setVar(m_x,m_y,false);
// }
// });
// GraphMenu.add(hideVar);
// }
// }
GraphMenu.show(FunctionArea.this, e.getX(), e.getY());
}
}
});
}
/** This method allows to add a selection listner to the PointIcon
/** This method allows to add a selection listener to the PointIcon
* it should need more than one listener to this abstruse event
* @param a The selection listener
*/
@@ -832,17 +834,37 @@ public class FunctionArea extends DArea implements Serializable {
this.m_RefPointListener = a;
}
/** This method returns the selection listner to the PointIcon
/** This method returns the selection listener to the PointIcon
* @return InterfaceSelectionListener
*/
public InterfaceRefPointListener getRefPointSelectionListener() {
return this.m_RefPointListener;
}
/** This method allows to remove the selection listner to the PointIcon
/** This method allows to remove the selection listener to the PointIcon
*/
public void removeRefPointSelectionListeners() {
this.m_RefPointListener = null;
}
/**
* Recreate the legend object with the current point sets.
*
*/
public void updateLegend() {
GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer);
setLegend(lb);
}
/**
* Reset the legend clearing all information.
*/
public void clearLegend() {
setLegend(null);
}
private void toggleLegend() {
m_legend=!m_legend;
repaint();
}
}

View File

@@ -27,7 +27,7 @@ import java.util.Arrays;
*
*/
public class GraphPointSet {
private String m_InfoString = "InfoString";
private String m_InfoString = "Incomplete_Run";
private int m_GraphLabel;
private int colorOffset = 0;
private ArrayList m_PointSetContainer = new ArrayList();

View File

@@ -0,0 +1,118 @@
package eva2.gui;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import wsi.ra.chart2d.SlimRect;
import eva2.tools.Pair;
/**
* A class representing the legend of a plot. It is created from a list of GraphPointSets as
* used in FunctionArea. Painting is done in FunctionArea. As an alternative, an own frame
* could be created.
*
* @author mkron
*
*/
public class GraphPointSetLegend {
Pair<String,Color>[] legendEntries;
public GraphPointSetLegend(List<GraphPointSet> pointSetContainer) {
legendEntries = new Pair[pointSetContainer.size()];
for (int i = 0; i < pointSetContainer.size(); i++) {
GraphPointSet pointset = pointSetContainer.get(i);
legendEntries[i] = new Pair<String,Color>(pointset.getInfoString(), pointset.getColor());
}
}
/**
* Add the legend labels to a container.
* @param comp
*/
public void addToContainer(JComponent comp) {
for (int i = 0; i < legendEntries.length; i++) {
JLabel label = new JLabel(legendEntries[i].head);
label.setForeground(legendEntries[i].tail);
comp.add(label);
}
}
public static JPanel makeLegendPanel(Color bgCol, ArrayList<GraphPointSet> pointSetContainer) {
JPanel pan = new JPanel();
pan.setBackground(bgCol);
pan.setLayout(new BoxLayout(pan, BoxLayout.Y_AXIS));
GraphPointSetLegend lBox=new GraphPointSetLegend(pointSetContainer);
lBox.addToContainer(pan);
return pan;
}
public static JFrame makeLegendFrame(Color bgCol, ArrayList<GraphPointSet> pointSetContainer) {
JFrame frame = new JFrame("Legend");
// LegendBox lBox = new LegendBox(bgCol, pointSetContainer);
frame.add(makeLegendPanel(bgCol, pointSetContainer));
frame.pack();
frame.setVisible(true);
return frame;
}
public void paintIn(JComponent component) {
Graphics g = component.getGraphics();
FontMetrics fm = g.getFontMetrics();
int yOffs=5+fm.getHeight();
int xOffs=0;
Color origCol = g.getColor();
for (int i=0; i<legendEntries.length; i++) {
g.setColor(legendEntries[i].tail);
Rectangle2D rect = fm.getStringBounds(legendEntries[i].head, g);
xOffs = (int) (component.getWidth()-rect.getWidth()-5);
g.drawString(legendEntries[i].head, xOffs, yOffs);
yOffs+=(5+rect.getHeight());
}
g.setColor(origCol);
}
// public void paintIn(Graphics g, Dimension dim) {
// paintIn(g, dim.width);
// }
//
// public void paintIn(Graphics g, Rectangle rect) {
// paintIn(g, rect.width);
// }
//
// public void paintIn(Graphics g, DRectangle rect) {
// paintIn(g, (int)rect.width);
// }
public void paintIn(Graphics g, SlimRect rect) {
paintIn(g, (int)rect.getX(), (int)rect.getY(), (int)rect.getX()+(int)rect.getWidth());
}
private void paintIn(Graphics g, int x, int y, int maxX) {
FontMetrics fm = g.getFontMetrics();
// System.out.println("In LegendBox.paintIn!");
int yOffs=5+y+fm.getHeight();
int xOffs=x;
Color origCol = g.getColor();
for (int i=0; i<legendEntries.length; i++) {
g.setColor(legendEntries[i].tail);
Rectangle2D stringBounds = fm.getStringBounds(legendEntries[i].head, g);
xOffs = (int) (maxX-stringBounds.getWidth()-5);
g.drawString(legendEntries[i].head, xOffs, yOffs);
// g.drawString(legendEntries[i].head, 80, 80);
yOffs+=(5+stringBounds.getHeight());
}
g.setColor(origCol);
}
}

View File

@@ -68,6 +68,10 @@ public class GraphWindow {
return (m_Plotter != null) && (m_Plotter.isValid());
}
public PlotInterface getPlotter() {
return m_Plotter;
}
/**
*
*/
@@ -101,7 +105,7 @@ public class GraphWindow {
*/
public Graph getNewGraph(String InfoString) {
m_GraphCounter++;
if (TRACE) System.out.println("Graph.getNewGraph No:"+m_GraphCounter);
if (TRACE) System.out.println("Graph.getNewGraph No:"+m_GraphCounter + " - " + InfoString);
return new Graph (InfoString,m_Plotter,m_GraphCounter);
}
}

View File

@@ -327,6 +327,7 @@ public class Plot implements PlotInterface, Serializable {
public void clearAll () {
m_PlotArea.clearAll();
m_PlotArea.removeAllDElements();
m_PlotArea.clearLegend();
m_Frame.repaint();
}
/**
@@ -443,6 +444,7 @@ public class Plot implements PlotInterface, Serializable {
public String getName() {
return this.m_PlotName;
}
/**
*
*/

View File

@@ -50,6 +50,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
private double m_ConstraintViolation = 0;
public boolean m_AreaConst4ParallelViolated = false;
public boolean m_Marked = false; // is for GUI only!
public boolean m_isPenalized = false; // may be set true for penalty based constraints
protected double[] m_SelectionProbability = new double[1];;
public double m_CrossoverProbability = 1.0;
@@ -144,6 +145,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
m_ConstraintViolation = individual.m_ConstraintViolation;
m_AreaConst4ParallelViolated = individual.m_AreaConst4ParallelViolated;
m_Marked = individual.m_Marked;
m_isPenalized = individual.m_isPenalized;
individualIndex = individual.individualIndex;
if (individual.parentIDs != null) {
parentIDs = new Long[individual.parentIDs.length];
@@ -447,6 +449,7 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* individual
*/
public void resetConstraintViolation() {
m_isPenalized=false;
this.m_ConstraintViolation = 0;
}
@@ -494,6 +497,21 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
this.m_Marked = true;
}
/**
* Allows marking an individual as infeasible if fitness penalty is used.
* @return
*/
public boolean isMarkedPenalized() {
return m_isPenalized;
}
/**
* Allows marking an individual as infeasible if fitness penalty is used.
* @return
*/
public void SetMarkPenalized(boolean p) {
m_isPenalized=p;
}
/** This method can be used to read the current fitness of the individual.
* Please note that the fitness can be based on multiple criteria therefore
* double[] is used instead of a single double.

View File

@@ -444,6 +444,50 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
return getIndexOfBestOrWorstIndividual(false, false, fitIndex);
}
/**
* Return the best feasible individual or null if the population contains
* no or only infeasible individuals. This considers both aspects: the constraint setting
* as well as penalization. An individual is feasible only if it is both unpenalized and
* not violating the constraints.
*
* @param fitIndex
* @return the best feasible individual or null if none is feasible
*/
public AbstractEAIndividual getBestFeasibleIndividual(int fitIndex) {
int index=getIndexOfBestOrWorstFeasibleIndividual(true, fitIndex);
if (index<0) return null;
else return getEAIndividual(index);
}
// /**
// * Return the best individual which has a zero penalty value (is feasible concerning
// * penalty). If all are penalized, null is returned.
// *
// * @param fitIndex
// * @return
// */
// public AbstractEAIndividual getBestUnpenalizedIndividual(int fitIndex) {
// int result = -1;
// double[] curSelFitness = null;
// boolean allViolate = true;
//
// for (int i = 0; i < super.size(); i++) {
// if (!(getEAIndividual(i).isMarkedPenalized())) {
// allViolate = false;
// if ((result<0) || (compareFit(true, getEAIndividual(i).getFitness(), curSelFitness, fitIndex))) {
// // fit i is better than remembered
// result = i;
// curSelFitness = getEAIndividual(i).getFitness(); // remember fit i
// }
// }
// }
// if (allViolate) {
// return null;
// } else {
// return getEAIndividual(result);
// }
// }
/**
* This method will return the index of the current best (worst) individual from the
* population. If indicated, only those are regarded which do not violate the constraints.
@@ -485,7 +529,8 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
minViol = ((AbstractEAIndividual)super.get(i)).getConstraintViolation();
}
}
System.err.println("Population reports: All individuals violate the constraints, choosing smallest constraint violation.");
// System.err.println("Population reports: All individuals violate the constraints, choosing smallest constraint violation.");
// this is now really reported nicer...
} else {
// not all violate, maybe all are NaN!
// so just select a random one
@@ -496,6 +541,31 @@ public class Population extends ArrayList implements PopulationInterface, Clonea
return result;
}
/**
* Search the population for the best (worst) considering the given criterion (or all criteria
* for fitIndex<0) which also does not violate constraints.
* Returns -1 if no feasible solution is found, else the index of the best feasible solution.
*
* @param bBest
* @param fitIndex
* @return -1 if no feasible solution is found, else the index of the best feasible individual
*/
public int getIndexOfBestOrWorstFeasibleIndividual(boolean bBest, int fitIndex) {
int result = -1;
double[] curSelFitness = null;
for (int i = 0; i < super.size(); i++) {
if (!(getEAIndividual(i).violatesConstraint()) && !(getEAIndividual(i).isMarkedPenalized())) {
if ((result<0) || (compareFit(bBest, getEAIndividual(i).getFitness(), curSelFitness, fitIndex))) {
// fit i is better than remembered
result = i;
curSelFitness = getEAIndividual(i).getFitness(); // remember fit i
}
}
}
return result;
}
/**
* This method returns the current best individual from the population.
* If the population is empty, null is returned.

View File

@@ -11,10 +11,20 @@ import eva2.gui.BeanInspector;
import eva2.server.go.IndividualInterface;
import eva2.server.go.PopulationInterface;
import eva2.server.go.individuals.AbstractEAIndividual;
import eva2.server.go.populations.Population;
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.Mathematics;
/**
* An abstract class handling statistics. Most important stuff happens in startOptPerformed, stopOptPerformed
* and createNextGenerationPerformed. Any measures (run based or multi-run based) are reset in startOptPerformed,
* updated per iteration in createNextGenerationPerformed and reported to listeners in stopOptPerformed.
* Several different verbosity levels are regarded.
* The method plotCurrentResults should be implemented to plot further results per iteration.
*
* @author mkron
*
*/
public abstract class AbstractStatistics implements InterfaceTextListener, InterfaceStatistics {
private PrintWriter resultOut;
public final static boolean TRACE = false;
@@ -42,14 +52,19 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected int functionCalls;
protected int functionCallSum;
protected int convergenceCnt;
protected int feasibleFoundAfter;
protected int numOfRunsFeasibleFound;
protected double feasibleFoundAfterSum;
protected int optRunsPerformed;
protected double[] currentBestFit;
protected double[] currentBestFeasibleFit;
protected double[] meanBestFeasibleFit;
protected double[] meanFitness;
protected double[] currentWorstFit;
protected double[] meanBestOfRunFitness;
protected double avgPopDist;
protected double maxPopDist;
protected IndividualInterface bestCurrentIndividual, bestRunIndividual, bestIndividualAllover;
protected IndividualInterface bestCurrentIndividual, bestRunIndividual, bestRunFeasibleIndy, bestIndividualAllover;
private ArrayList<InterfaceTextListener> textListeners;
@@ -121,11 +136,17 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
initOutput(infoString);
bestIndividualAllover = null;
meanBestOfRunFitness = null;
meanBestFeasibleFit = null;
if (refineMultiRuns) meanCollection = new ArrayList<double[][]>();
else meanCollection = null;
feasibleFoundAfterSum=-1;
numOfRunsFeasibleFound=0;
}
feasibleFoundAfter=-1;
bestCurrentIndividual = null;
bestRunIndividual = null;
currentBestFeasibleFit=null;
bestRunFeasibleIndy = null;
runIterCnt = 0;
if (printRunIntroVerbosity()) printToTextListener("\n****** Multirun "+runNumber);
if (params != null) {
@@ -165,6 +186,32 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
meanBestOfRunFitness=bestRunIndividual.getFitness().clone();
} else addMean(meanBestOfRunFitness, bestRunIndividual.getFitness());
}
if (feasibleFoundAfter>0) {
if (printRunStoppedVerbosity()) printToTextListener(" Feasible ind. found after " + feasibleFoundAfter + " evaluations.\n");
} else {
if (printRunStoppedVerbosity()) printToTextListener(" NO feasible individual found.\n");
}
if (bestRunFeasibleIndy != null) {
if (meanBestFeasibleFit==null) {
meanBestFeasibleFit=currentBestFeasibleFit.clone();
} else addMean(meanBestFeasibleFit, currentBestFeasibleFit);
if (printRunStoppedVerbosity()) {
if ((bestRunFeasibleIndy instanceof AbstractEAIndividual) && ((AbstractEAIndividual)bestRunFeasibleIndy).equalGenotypes((AbstractEAIndividual)bestRunIndividual)) {
printToTextListener(" Run best feasible individual equals best individual.\n");
} else {
if (bestRunFeasibleIndy instanceof AbstractEAIndividual) {
if (((AbstractEAIndividual)bestRunIndividual).violatesConstraint())
printToTextListener(" Run best individual violates constraints by " + ((AbstractEAIndividual)bestRunIndividual).getConstraintViolation() + "\n");
if (((AbstractEAIndividual)bestRunIndividual).isMarkedPenalized())
printToTextListener(" Run best individual is penalized.\n");
}
printToTextListener(" Run best feasible ind.: " + BeanInspector.toString(bestRunFeasibleIndy) + "\n");
printToTextListener(" Feas. solution data : " + AbstractEAIndividual.getDefaultDataString(bestRunFeasibleIndy) + "\n");
printToTextListener(" Feas. solution fit : " + BeanInspector.toString(bestRunFeasibleIndy.getFitness()) + "\n");
}
}
}
// if (currentBestFit!= null) {
// if (printRunStoppedVerbosity()) printToTextListener(" Best Fitness: " + BeanInspector.toString(currentBestFit) + "\n");
// }
@@ -174,6 +221,12 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
protected void finalizeOutput() {
if (printFinalVerbosity()) printToTextListener("*******\n Runs performed: " + optRunsPerformed + ", reached target " + convergenceCnt + " times with threshold " + m_StatsParams.getConvergenceRateThreshold() + ", rate " + convergenceCnt/(double)m_StatsParams.getMultiRuns() + '\n');
if (printFinalVerbosity()) printToTextListener(" Average function calls: " + (functionCallSum/optRunsPerformed) + "\n");
if (printFinalVerbosity() && (feasibleFoundAfterSum>=0.)) {
printToTextListener(" Feasible solution found in " + numOfRunsFeasibleFound + " of " + optRunsPerformed + " runs \n");
printToTextListener(" Average evaluations until feasible ind. was found in " + numOfRunsFeasibleFound + " runs: " + feasibleFoundAfterSum/numOfRunsFeasibleFound + " evaluations\n");
}
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" Overall best individual: " + BeanInspector.toString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" Overall solution data : " + AbstractEAIndividual.getDefaultDataString(bestIndividualAllover) + '\n');
if (printFinalVerbosity() && (bestIndividualAllover != null)) printToTextListener(" Overall solution fit : " + BeanInspector.toString(bestIndividualAllover.getFitness()) + '\n');
@@ -181,7 +234,13 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (meanBestOfRunFitness!=null) {
Mathematics.svDiv((double)optRunsPerformed, meanBestOfRunFitness, meanBestOfRunFitness);
if (printFinalVerbosity()) {
printToTextListener(" Averaged best fitness per run: " + BeanInspector.toString(meanBestOfRunFitness)+"\n");
printToTextListener(" Average best fitness per run: " + BeanInspector.toString(meanBestOfRunFitness)+"\n");
}
}
if (meanBestFeasibleFit!=null) {
Mathematics.svDiv((double)numOfRunsFeasibleFound, meanBestFeasibleFit, meanBestFeasibleFit);
if (printFinalVerbosity()) {
printToTextListener(" Average best feasible fitness in " + numOfRunsFeasibleFound + " runs: " + BeanInspector.toString(meanBestFeasibleFit)+"\n");
}
}
if (refineMultiRuns && (meanCollection != null)) {
@@ -298,6 +357,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
functionCalls = calls;
currentBestFit = bestfit;
currentWorstFit = worstfit;
currentBestFeasibleFit = null;
meanFitness = null;
if (firstPlot) {
@@ -336,6 +396,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
initPlots(m_StatsParams.getPlotDescriptions());
// if (doTextOutput()) printToTextListener(getOutputHeader(informer, pop)+'\n');
firstPlot = false;
currentBestFeasibleFit=null;
}
if ((runIterCnt==0) && printHeaderByVerbosity()) printToTextListener(getOutputHeader(informerList, pop)+'\n');
@@ -361,6 +422,23 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (currentBestFit == null) {
System.err.println("BestFitness==null !");
}
if (pop instanceof Population) {
AbstractEAIndividual curBestFeasible = ((Population)pop).getBestFeasibleIndividual(-1);
if (curBestFeasible!=null) { // a feasible ind. was found!
if (currentBestFeasibleFit==null) { // feasible indy found for the first time
numOfRunsFeasibleFound++;
feasibleFoundAfter=((Population)pop).getFunctionCalls();
if (feasibleFoundAfterSum<0) feasibleFoundAfterSum=0.; // initial signalling value was -1.
feasibleFoundAfterSum+=feasibleFoundAfter;
}
currentBestFeasibleFit = curBestFeasible.getFitness().clone();
if ((bestRunFeasibleIndy==null) || (secondIsBetter(bestRunFeasibleIndy, curBestFeasible))) {
bestRunFeasibleIndy=curBestFeasible;
}
}
}
meanFitness = pop.getMeanFitness().clone();
currentWorstFit = pop.getWorstIndividual().getFitness().clone();
functionCalls = pop.getFunctionCalls();

View File

@@ -18,20 +18,21 @@ import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RMIProxyLocal;
import wsi.ra.jproxy.RMIProxyRemote;
import eva2.gui.BeanInspector;
import eva2.gui.Graph;
import eva2.gui.GraphWindow;
import eva2.gui.JTextoutputFrame;
import eva2.gui.JTextoutputFrameInterface;
import eva2.gui.Plot;
import eva2.gui.PlotInterface;
import eva2.server.EvAServer;
import eva2.server.go.PopulationInterface;
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR;
import wsi.ra.jproxy.MainAdapterClient;
import wsi.ra.jproxy.RMIProxyLocal;
import wsi.ra.jproxy.RMIProxyRemote;
/*==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
@@ -105,39 +106,48 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
// m_TextCounter = m_StatisticsParameter.GetTextoutput();
m_PlotCounter = m_StatsParams.GetPlotoutput();
if ((m_FitnessFrame!=null) && (m_FitnessFrame[0]!=null)) {
PlotInterface p = m_FitnessFrame[0].getPlotter();
if ((p!=null) && p.isValid()) ((Plot)p).getFunctionArea().clearLegend();
}
}
public void stopOptPerformed(boolean normal, String stopMessage) {
super.stopOptPerformed(normal, stopMessage);
if (optRunsPerformed > m_StatsParams.getMultiRuns()) {
// this may happen if the user reduces the multirun parameter during late multiruns
System.err.println("error: more runs performed than defined.");
}
int fullRuns=optRunsPerformed;
if (!normal) fullRuns--;
// unite the graphs only if the break was "normal"
if (normal && (m_StatsParams.getMultiRuns() > 1) && (m_StatGraph != null)) {
if ((m_StatsParams.getMultiRuns() > 1) && (m_StatGraph != null)) {
// unite the point sets for a multirun
for (int i = 0; i < m_FitnessGraph.length; i++) {
for (int j = 0; j < m_FitnessGraph[i].length; j++) {
if (m_FitnessFrame[i].isValid()) {
m_StatGraph[i][j].setInfoString(
(m_FitnessGraph[i][j].getInfo().length() > 0 ? (m_FitnessGraph[i][j].getInfo() + "_") : "" )
+ (m_StatsParams.GetInfoString().length() > 0 ? (m_StatsParams.GetInfoString() + "_") : "" )
+ m_StatsParams.GetInfoString()
+ "Mean_of_" + fullRuns + " ",
(float) 2.0);
if (normal && m_FitnessFrame[i].isValid()) {
m_StatGraph[i][j].addGraph(m_FitnessGraph[i][j]);
m_StatGraph[i][j].setInfoString(
(m_FitnessGraph[i][j].getInfo().length() > 0 ? (m_FitnessGraph[i][j].getInfo() + "_") : "" )
+ (m_StatsParams.GetInfoString().length() > 0 ? (m_StatsParams.GetInfoString() + "_") : "" )
+ m_StatsParams.GetInfoString()
+ "Mean_of_" + optRunsPerformed + " ",
(float) 2.0);
m_FitnessGraph[i][j].clear();
}
}
}
}
// this is inconsistent, shouldnt be necessary here but reset in startOpt...
// if (optRunsPerformed == m_StatisticsParameter.getMultiRuns()) {
// finalizeRuns(m_ConvergenceCnt);
// m_OptRunsPerformed = 0;
// m_ConvergenceCnt = 0;
// }
PlotInterface p = m_FitnessFrame[0].getPlotter();
if ((optRunsPerformed >= m_StatsParams.getMultiRuns()) || !normal) {
// update the legend after the last multirun or after a user break
if ((p!=null) && p.isValid()) {
((Plot)p).getFunctionArea().updateLegend();
}
}
}
public void maybeShowProxyPrinter() {
@@ -149,13 +159,13 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
maybeShowProxyPrinter();
int graphCount = description.size();
// System.out.println("Initializing " + graphCount + " plots (StatisticsWithGUI)");
m_FitnessFrame = new GraphWindow[graphCount];
for (int i = 0; i < m_FitnessFrame.length; i++) {
// m_FitnessFrame[i] = GraphWindow.getInstance(m_MainAdapterClient, m_GraphInfoString + " " + i + " " + " on " + m_MyHostName + ", VM " + EvAServer.m_NumberOfVM, "function calls", "fitness");
m_FitnessFrame[i] = GraphWindow.getInstance(m_MainAdapterClient, "Optimization " + i + " " + " on " + m_MyHostName + ", VM " + EvAServer.m_NumberOfVM, "function calls", "fitness");
}
m_FitnessGraph = new Graph[graphCount][];
// contains one graph for every value to be plotted (best / worst / best+worst)
// TODO Im really not sure why this is a 2-dimensional array. shouldnt one be enough?
@@ -163,7 +173,7 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
m_FitnessGraph[i] = new Graph[((String[]) description.get(i)).length];
for (int j = 0; j < m_FitnessGraph[i].length; j++) {
String[] d = (String[]) description.get(i);
// this is where the column string for ascii export is created!
// this is where the column string for ascii export is created! Uah!
m_FitnessGraph[i][j] =
m_FitnessFrame[i].getNewGraph(d[j] + "_" +
m_StatsParams.GetInfoString() +
@@ -215,12 +225,20 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
m_PlotCounter = m_StatsParams.GetPlotoutput();
boolean doPlotBest = (fitnessplot_setting == StatsParameter.PLOT_BEST)
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST)
|| (fitnessplot_setting == StatsParameter.PLOT_CURBEST_AND_RUNBEST)
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
boolean doPlotWorst = (fitnessplot_setting == StatsParameter.PLOT_WORST)
|| (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_WORST);
boolean doPlotMeasures = (fitnessplot_setting == StatsParameter.PLOT_BEST_AND_MEASURES);
boolean doPlotBestFeasible = false;
// TODO <-- das hier besser?
// Oder erstmal ganz weg und dafür gesamtergebnis berechnen (textfenster)
// ZB: wie oft wurde feasible sol. gefunden (analog convergence counter)
// Durchschnitt: erste feasible sol., fitness der feasible sol...
int subGraph=0;
if (doPlotBest) {
plotFitnessPoint(0, 0, functionCalls, currentBestFit[0]);
plotFitnessPoint(0, subGraph++, functionCalls, currentBestFit[0]);
if (fitnessplot_setting == StatsParameter.PLOT_CURBEST_AND_RUNBEST) plotFitnessPoint(0, subGraph++, functionCalls, bestRunIndividual.getFitness()[0]);
}
if (doPlotWorst) {
// schlechteste Fitness plotten
@@ -229,11 +247,14 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
System.err.println("m_WorstFitness==null in plotStatisticsPerformed");
return;
}
plotFitnessPoint(0, (doPlotBest ? 1 : 0) , functionCalls, currentWorstFit[0]);
plotFitnessPoint(0, subGraph++ , functionCalls, currentWorstFit[0]);
}
if (doPlotMeasures) {
plotFitnessPoint(0, 1, functionCalls, avgPopDist);
plotFitnessPoint(0, 2, functionCalls, maxPopDist);
plotFitnessPoint(0, subGraph++, functionCalls, avgPopDist);
plotFitnessPoint(0, subGraph++, functionCalls, maxPopDist);
}
if (doPlotBestFeasible && currentBestFeasibleFit!=null) {
plotFitnessPoint(0, subGraph++, functionCalls, currentBestFeasibleFit[0]);
}
}
}

View File

@@ -33,11 +33,13 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
public final static int PLOT_WORST = 1;
public final static int PLOT_BEST_AND_WORST = 2;
public final static int PLOT_BEST_AND_MEASURES = 3;
public final static int PLOT_CURBEST_AND_RUNBEST = 4;
public final static Tag[] TAGS_PLOT_FITNESS = {
new Tag(PLOT_BEST, "plot best fitness"),
new Tag(PLOT_WORST, "plot worst fitness"),
new Tag(PLOT_BEST_AND_WORST, "both best and worst"),
new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures")
new Tag(PLOT_BEST_AND_MEASURES, "both best and population measures"),
new Tag(PLOT_CURBEST_AND_RUNBEST, "current best and best of run")
};
public final static int VERBOSITY_NONE = 0;
@@ -113,7 +115,9 @@ public class StatsParameter implements InterfaceStatisticsParameter, Serializabl
case StatsParameter.PLOT_BEST_AND_MEASURES:
desc.add(new String[] {"Best", "AvgDist", "MaxDist"});
break;
}
case StatsParameter.PLOT_CURBEST_AND_RUNBEST:
desc.add(new String[] {"Cur.Best", "Run Best"});
break; }
return desc;
}