Code cleanup, comments, javadoc fixes.

This commit is contained in:
Fabian Becker 2014-11-14 14:33:56 +01:00
parent 553002c834
commit b8b44b7644
39 changed files with 93 additions and 166 deletions

View File

@ -77,8 +77,7 @@ public class EvAInfo {
}
public static String getProperty(String key) {
String myVal = evaProperties.getProperty(key);
return myVal;
return evaProperties.getProperty(key);
}
public static Properties getProperties() {
@ -98,7 +97,6 @@ public class EvAInfo {
}
public static String propDefaultModule() {
String defaultModule = getProperty("DefaultModule");
return defaultModule;
return getProperty("DefaultModule");
}
}

View File

@ -120,7 +120,7 @@ public final class OptimizationBuilder {
Class<?>[] params = new Class[0];
try {
Constructor constructor = clazz.getConstructor(params);
instance = (T)constructor.newInstance(new Object[]{});
instance = (T)constructor.newInstance();
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) {
ex.printStackTrace();
}

View File

@ -2,6 +2,7 @@ package eva2.gui;
import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -50,11 +51,11 @@ public class ExtDesktopManager extends DefaultDesktopManager {
for (i = index; i < Math.min(WINDOW_LIST_START + 9, desktop.getWindowMenu().getItemCount()); i++) {
JMenuItem m = desktop.getWindowMenu().getItem(i);
JInternalFrame frame = (JInternalFrame) m.getClientProperty(FRAME);
frame.putClientProperty(INDEX, ((Integer) frame.getClientProperty(INDEX)).intValue() - 1);
frame.putClientProperty(INDEX, (Integer) frame.getClientProperty(INDEX) - 1);
int winIndex = i - WINDOW_LIST_START + 1;
m.setText((winIndex) + " " + frame.getTitle());
m.setMnemonic((char) (0x30 + winIndex));
m.setAccelerator(KeyStroke.getKeyStroke(0x30 + winIndex, Event.ALT_MASK));
m.setAccelerator(KeyStroke.getKeyStroke(0x30 + winIndex, InputEvent.ALT_MASK));
}
if (internalFrame.isSelected()) {

View File

@ -4,8 +4,8 @@ import javax.swing.*;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
public class JEFrame extends JInternalFrame {
@ -62,7 +62,7 @@ public class JEFrame extends JInternalFrame {
}
});
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK),
"ctrlFpressed"
);
this.getRootPane().getActionMap().put(
@ -75,7 +75,7 @@ public class JEFrame extends JInternalFrame {
}
);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK),
"ctrlOpressed"
);
this.getRootPane().getActionMap().put(
@ -91,7 +91,7 @@ public class JEFrame extends JInternalFrame {
}
);
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
KeyStroke.getKeyStroke(KeyEvent.VK_LESS, Event.CTRL_MASK),
KeyStroke.getKeyStroke(KeyEvent.VK_LESS, InputEvent.CTRL_MASK),
"ctrlSmallerpressed"
);
final JEFrame self = this;

View File

@ -42,7 +42,7 @@ public class JExtToolBar extends JToolBar {
if (k != null) {
int modifiers = k.getModifiers();
if (modifiers > 0) {
result.append(KeyEvent.getKeyModifiersText(modifiers) + "+");
result.append(KeyEvent.getKeyModifiersText(modifiers)).append("+");
}
result.append(KeyEvent.getKeyText(k.getKeyCode()));
}

View File

@ -10,8 +10,8 @@ import javax.swing.text.Keymap;
import javax.swing.undo.CannotRedoException;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.*;
import java.util.Hashtable;
@ -26,7 +26,7 @@ public class JTextEditorInternalFrame extends JDocFrame {
private class UndoAction extends ExtAction {
public UndoAction() {
super("R<EFBFBD>ckg<EFBFBD>ngig", new ImageIcon("images/EditUndo.gif"), "Macht die letzte Aktion r<>ckg<6B>ngig",
KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK));
KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
setEnabled(false);
}
@ -57,7 +57,7 @@ public class JTextEditorInternalFrame extends JDocFrame {
///////////////////////////////////////////
private class RedoAction extends ExtAction {
public RedoAction() {
super("Wiederholen", "Wiederholt die letzte Aktion", KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK | Event.SHIFT_MASK));
super("Wiederholen", "Wiederholt die letzte Aktion", KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
setEnabled(false);
}

View File

@ -160,14 +160,14 @@ public class FilePathEditor extends JPanel implements PropertyEditor {
ActionListener fileChooserAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
if (event.getActionCommand() == "ApproveSelection") {
if (event.getActionCommand().equals("ApproveSelection")) {
filePath.setCompleteFilePath(fileChooser.getSelectedFile().getAbsolutePath());
propertyChangeSupport.firePropertyChange("", filePath, null);
Window w = (Window) fileChooser.getTopLevelAncestor();
w.dispose();
panel = null;
}
if (event.getActionCommand() == "CancelSelection") {
if (event.getActionCommand().equals("CancelSelection")) {
filePath.setCompleteFilePath(fileChooser.getSelectedFile().getAbsolutePath());
propertyChangeSupport.firePropertyChange("", filePath, null);
Window w = (Window) fileChooser.getTopLevelAncestor();

View File

@ -48,8 +48,7 @@ public class GenericObjectEditor implements PropertyEditor {
}
classes.add(current);
} catch (ClassNotFoundException ex) {
LOGGER.log(Level.WARNING,
String.format("Requesting className: %1$s, Couldn't load: %2%s", className, current), ex);
LOGGER.log(Level.WARNING, String.format("Requesting className: %1$s, Couldn't load: %2$s", className, current), ex);
}
}
return classes;

View File

@ -192,15 +192,7 @@ public class DPointSetMultiIcon extends DComponent {
}
public int getSize() {
int size = Math.min(xMI.getSize(), yMI.getSize());
// int size = x.getSize();
// if( size != y.getSize() ) throw
// new ArrayStoreException(
// "The number of x-values is not equal to the number of y-values.\n"
// +"The size of the DPointSet isn<73>t clear."
// );
return size;
return Math.min(xMI.getSize(), yMI.getSize());
}
/**

View File

@ -1162,7 +1162,6 @@ public abstract class AbstractEAIndividual implements IndividualInterface, java.
* Try to convert the individuals position to double[] and return it.
* Returns null if there is no conversion available.
*
* @param indy
* @return double valued position of an individual or null
*/
public double[] getDoublePosition() {

View File

@ -73,7 +73,7 @@ public class EAIndividualComparator implements Comparator<Object>, Serializable
public boolean equals(Object other) {
if (other instanceof EAIndividualComparator) {
EAIndividualComparator o = (EAIndividualComparator) other;
if ((indyDataKey == o.indyDataKey) || (indyDataKey != null && (indyDataKey.equals(o.indyDataKey)))) {
if ((indyDataKey.equals(o.indyDataKey)) || (indyDataKey != null && (indyDataKey.equals(o.indyDataKey)))) {
if ((fitCriterion == o.fitCriterion) && (preferFeasible == o.preferFeasible)) {
return true;
}

View File

@ -31,7 +31,7 @@ public interface IndividualInterface {
* Check whether the instance is dominating the given other individual and return
* true in this case.
*
* @param other a second individual of the same type
* @param fitness other a second individual of the same type
* @return true if the instance dominates the other individual, else false
*/
boolean isDominant(double[] fitness);

View File

@ -350,9 +350,7 @@ public abstract class AbstractGPNode implements InterfaceProgram, java.io.Serial
try {
node = (AbstractGPNode) c.newInstance();
ret = ret + " (" + node.getOpIdentifier() + "," + node.getArity() + ")";
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
}

View File

@ -100,7 +100,7 @@ public class MOCCOChooseReferenceSolution extends MOCCOPhase implements Interfac
gbc.gridx = 2;
gbc.gridy = i + 1;
gbc.weightx = 1;
textA = new JTextField("" + (Double) referenceSolution.getData(obj[i].getIdentName()));
textA = new JTextField("" + referenceSolution.getData(obj[i].getIdentName()));
textA.setEditable(false);
tmpP.add(textA, gbc);

View File

@ -265,7 +265,7 @@ public class MOCCOParameterizeGDF extends MOCCOPhase implements InterfaceProcess
double[] result = new double[tmpA.size()];
for (int i = 0; i < result.length; i++) {
result[i] = ((Double) tmpA.get(i)).doubleValue();
result[i] = (Double) tmpA.get(i);
}
return result;
}

View File

@ -127,7 +127,7 @@ public class MOCCOParameterizeSTEP extends MOCCOPhase implements InterfaceProces
}
gbc.gridx = 2;
gbc.gridy = i + 1;
this.refSolTextField[i] = new JTextField("" + (Double) refSolution.getData(obj[i].getIdentName()));
this.refSolTextField[i] = new JTextField("" + refSolution.getData(obj[i].getIdentName()));
this.refSolTextField[i].setEditable(false);
panelSTEP.add(this.refSolTextField[i], gbc);
gbc.gridx = 3;
@ -336,7 +336,7 @@ public class MOCCOParameterizeSTEP extends MOCCOPhase implements InterfaceProces
double[] result = new double[tmpA.size()];
for (int i = 0; i < result.length; i++) {
result[i] = ((Double) tmpA.get(i)).doubleValue();
result[i] = (Double) tmpA.get(i);
}
return result;
}

View File

@ -183,13 +183,12 @@ public class Processor extends Thread implements InterfaceProcessor, InterfacePo
errMsg = "check console output for error messages.";
}
errMsg = "Exception in Processor: " + errMsg;
e.printStackTrace();
LOGGER.log(Level.SEVERE, errMsg, e);
e.printStackTrace();
try {
JOptionPane.showMessageDialog(null, StringTools.wrapLine(errMsg, 60, 0.2), "Error in Optimization", JOptionPane.ERROR_MESSAGE);
} catch (Exception | Error ignored) {
}
//statistics.stopOptimizationPerformed(false);
setOptimizationRunning(false); // normal finish
if (optimizationStateListener != null) {
optimizationStateListener.performedStop(); // is only needed in client server mode

View File

@ -157,9 +157,9 @@ public class ArchivingPESAII extends AbstractArchiving implements java.io.Serial
}
}
// now i got all the boogies of the same grid element
// lets assign them thier squeeze factor
// lets assign them their squeeze factor
for (int j = 0; j < coll.size(); j++) {
result[((Integer) coll.get(j))] = coll.size();
result[(int) coll.get(j)] = coll.size();
tmpIndy = pop.get(((Integer) coll.get(j)).intValue());
tmpIndy.putData("SqueezeFactor", coll.size());
tmpIndy.putData("GridBox", curGrid);

View File

@ -34,7 +34,7 @@ public class AdaptiveCrossoverEAMixer extends CrossoverEAMixer implements Interf
/**
* Create a mutation mixer with equal weights of the given mutation operators.
*
* @param mutators
* @param crossovers
*/
public AdaptiveCrossoverEAMixer(InterfaceCrossover... crossovers) {
this.crossoverMixer = new PropertyCrossoverMixer(crossovers);

View File

@ -138,7 +138,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
for (int i = 0; i < parents.length; i++) {
tmpVec = Mathematics.vvSub(parents[i], mean);
if (Mathematics.isValidVec(tmpVec)) {
if (Mathematics.isValidVector(tmpVec)) {
if (result.size() == 0) {
result.add(tmpVec);
} else {
@ -149,7 +149,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
toro = Mathematics.svMult(tmpD, toro);
tmpVec = Mathematics.vvSub(tmpVec, toro);
}
if (Mathematics.isValidVec(tmpVec)) {
if (Mathematics.isValidVector(tmpVec)) {
result.add(tmpVec);
}
}
@ -171,7 +171,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
while (completeList.size() < mean.length) {
tmpVec = RNG.gaussianVector(mean.length, 1., true);
if (Mathematics.isValidVec(tmpVec)) {
if (Mathematics.isValidVector(tmpVec)) {
// apply the infamous Gram-Schmidt
for (int j = 0; j < completeList.size(); j++) {
toro = (double[]) completeList.get(j);
@ -179,7 +179,7 @@ public class CrossoverESUNDX implements InterfaceCrossover, java.io.Serializable
toro = Mathematics.svMult(tmpD, toro);
tmpVec = Mathematics.vvSub(tmpVec, toro);
}
if (Mathematics.isValidVec(tmpVec)) {
if (Mathematics.isValidVector(tmpVec)) {
Mathematics.normVect(tmpVec, tmpVec);
tmpVec = Mathematics.svMult(Mathematics.vvMult(theOther, tmpVec), tmpVec);
result.add(tmpVec);

View File

@ -67,12 +67,10 @@ public class CrossoverOBGAPMX implements InterfaceCrossover, java.io.Serializabl
((InterfaceOBGAIndividual) result[0]).setOBGenotype(pperm1);
((InterfaceOBGAIndividual) result[1]).setOBGenotype(pperm2);
//((InterfaceDataTypePermutation) result[0]).SetPermutationDataLamarckian(pperm1);
//((InterfaceDataTypePermutation) result[1]).SetPermutationDataLamarckian(pperm2);
}
//in case the crossover was successfull lets give the mutation operators a chance to mate the strategy parameters
for (int i = 0; i < result.length; i++) {
result[i].getMutationOperator().crossoverOnStrategyParameters(indy1, partners);
//in case the crossover was successful lets give the mutation operators a chance to mate the strategy parameters
for (AbstractEAIndividual indy : result) {
indy.getMutationOperator().crossoverOnStrategyParameters(indy1, partners);
}

View File

@ -81,7 +81,7 @@ public class MutateGIOrdinal implements InterfaceMutation, java.io.Serializable
mutInd = RNG.randomInt(0, x.length - 1);
mutate = RNG.gaussianDouble(this.stepSize);
// ToDo: WTF?
mutate *= (range[mutInd][1] - range[mutInd][1]);
mutate *= (0);
mut = (int) Math.round(mutate);
if (mut == 0) {
if (RNG.flipCoin(0.5)) {

View File

@ -103,7 +103,7 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
int[] tmp = new int[x.length];
int[] without = new int[x.length - length];
int[] insert = new int[length];
System.arraycopy(x, 0 + from, insert, 0, length);
System.arraycopy(x, from, insert, 0, length);
for (int i = 0; i < without.length; i++) {
if (i < from) {
without[i] = x[i];
@ -112,7 +112,7 @@ public class MutateGITranslocate implements InterfaceMutation, java.io.Serializa
}
}
System.arraycopy(without, 0, tmp, 0, to);
System.arraycopy(insert, to - to, tmp, to, to + length - to);
System.arraycopy(insert, 0, tmp, to, to + length - to);
System.arraycopy(without, to + length - length, tmp, to + length, x.length - (to + length));
// System.out.println(""+from+"/"+to+"/"+length);
// this.printInt("After ", tmp);

View File

@ -601,9 +601,9 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
printedIteration++;
meanData = data.get(i - 1);
sbuf.append(i);
for (int k = 0; k < meanData.length; k++) {
for (Double value : meanData) {
sbuf.append(delim);
sbuf.append(BeanInspector.toString(meanData[k]));
sbuf.append(BeanInspector.toString(value));
}
sbuf.append("\n");
}
@ -777,7 +777,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
* @see #getSimpleOutputHeader()
*/
protected Object[] getSimpleOutputValues() {
GraphSelectionEnum[] selEnumVals = null;
GraphSelectionEnum[] selEnumVals;
selEnumVals = GraphSelectionEnum.values();
Object[] ret = new Object[1 + selEnumVals.length];
ret[0] = functionCalls;
@ -1121,8 +1121,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
* Returns true if the given iteration is a verbose one according to StatsParameter - meaning
* that full iteration data should be plotted.
*
* @param iteration
* @return
* @param iteration Iteration number
* @return true if current iteration is verbose
*/
private boolean printLineByVerbosity(int iteration) {
return (statisticsParameter.getOutputVerbosity() == InterfaceStatisticsParameters.OutputVerbosity.ALL)
@ -1177,8 +1177,8 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
/**
* Compare two individual interfaces and return true if the second one is dominant.
*
* @param indy1
* @param indy2
* @param indy1 First individual
* @param indy2 Second individual
* @return true if the second individual is dominant, else false
*/
public static boolean secondIsBetter(IndividualInterface indy1, IndividualInterface indy2) {
@ -1191,7 +1191,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
if (indy1 instanceof AbstractEAIndividual) {
return ((AbstractEAIndividual) indy2).isDominatingDebConstraints((AbstractEAIndividual) indy1);
}
return (indy2.isDominant(indy1));
return indy2.isDominant(indy1);
}
@Override

View File

@ -345,9 +345,7 @@ public class StatisticalEvaluation {
for (OptimizationJob j : jobList) {
if (lSoFar == null) {
lSoFar = new LinkedList<>();
for (String f : j.getFieldHeaders()) {
lSoFar.add(f);
}
Collections.addAll(lSoFar, j.getFieldHeaders());
} else {
for (String f : lSoFar) {
if (j.getFieldIndex(f) >= 0) {

View File

@ -29,6 +29,7 @@ import eva2.problems.*;
import eva2.tools.chart2d.*;
import eva2.util.annotation.Description;
import eva2.util.annotation.Hidden;
import eva2.util.annotation.Parameter;
import java.io.*;
import java.text.SimpleDateFormat;
@ -435,7 +436,6 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
* Schedule new particles to be added to this swarm, rndly inited over the
* search space by the problem
*
* @param size number of particles to be created
* @param particleIndices set of indices that should be used for the added
* particles, if null new indices are created
*/
@ -2016,15 +2016,15 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
/**
* Set parameters as to Brits, Engelbrecht & Bergh: A Niching Particle Swarm
* Optimizer. SEAL 2002. Exeption: the swarm size is 100 by default, because
* Optimizer. SEAL 2002. Exception: the swarm size is 100 by default, because
* 30 (of the orig. paper) seems way too low.
*
* @param an already existing NichePSO instance or null to create a new one
* @param npso an already existing NichePSO instance or null to create a new one
* @param problem
* @param randSeed
* @param evalCnt
* @return
* @see #stdNPSO(AbstractOptimizer, long, int)
* @see #stdNPSO(eva2.problems.AbstractOptimizationProblem, long, int)
*/
public static OptimizationParameters stdNPSO(NichePSO npso, AbstractOptimizationProblem problem, long randSeed, int evalCnt) {
if (npso == null) {
@ -2074,7 +2074,7 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
* @param randSeed
* @param evalCnt
* @return
* @see #stdNPSO(AbstractOptimizer, long, int)
* @see #stdNPSO(eva2.problems.AbstractOptimizationProblem, long, int)
*/
public static OptimizationParameters starNPSO(NichePSO npso, AbstractOptimizationProblem problem, long randSeed, int evalCnt) {
starNPSO(npso, evalCnt);
@ -2087,7 +2087,6 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
}
int popSize = 200;
npso.setMainSwarmSize(popSize);
// double avgRange = Mathematics.getAvgRange(((InterfaceDataTypeDouble)problem.getIndividualTemplate()).getDoubleRange());
// set strategies
npso.setDeactivationStrategy(new StandardDeactivationStrategy());
@ -2101,14 +2100,10 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
npso.getMainSwarm().setAlgoType(ParticleSwarmOptimization.PSOType.Inertness);
npso.setMainSwarmAlgoType(ParticleSwarmOptimization.PSOType.Inertness);
npso.getMainSwarm().setPhi1(1.2);
// npso.SetMainSwarmPhi2(0); // by default no communication in the mainswarm
npso.setMainSwarmTopologyTag(0); // this doesnt have any effect due to no communication
npso.setMainSwarmTopologyRange(0);
npso.mainSwarmAlgoType = ParticleSwarmOptimization.PSOType.Inertness;
npso.getMainSwarm().setParameterControl(new ParamAdaption[]{getDefaultInertnessAdaption()});
// npso.setMainSwarmInertness(new LinearParameterAging(0.7, 0.2, evalCnt/popSize));
// npso.getMainSwarm().setSpeedLimit(avgRange/2.);
// npso.getMainSwarm().setCheckSpeedLimit(true);
// parameters for the subswarms
npso.getSubswarmOptimizerTemplate().setGcpso(true);
@ -2116,8 +2111,6 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
npso.getSubswarmOptimizerTemplate().setAlgoType(ParticleSwarmOptimization.PSOType.Constriction);
npso.getSubswarmOptimizerTemplate().setConstriction(2.05, 2.05);
// npso.getSubswarmOptimizerTemplate().setInertnessAging(new NoParameterAging(npso.getSubswarmOptimizerTemplate().getInertnessOrChi()));
// System.out.println(BeanInspector.niceToString(npso));
return npso;
}
@ -2128,13 +2121,15 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
@Override
public String[] getAdditionalDataInfo() {
return new String[]{"Size of the main swarm of explorers",
return new String[]{
"Size of the main swarm of explorers",
"Number of sub-swarms currently active",
"Average sub-swarm size",
"The number of stored potential local optima",
"The median correlation of stored solutions",
"The mean distance of stored solutions",
"Current inertness of the main swarm"};
"Current inertness of the main swarm"
};
}
@Override
@ -2179,11 +2174,8 @@ public class NichePSO extends AbstractOptimizer implements InterfaceAdditionalPo
return paramControl.getSingleAdapters();
}
@Parameter(description = "You may define dynamic paramter control strategies using the parameter name.")
public void setParameterControl(ParamAdaption[] paramControl) {
this.paramControl.setSingleAdapters(paramControl);
}
public String parameterControlTipText() {
return "You may define dynamic paramter control strategies using the parameter name.";
}
}

View File

@ -942,19 +942,11 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java
}
}
}
// this was the binary variant
// k = (2*sortedIndex+1);
// if (k < pop.size()) {
// compareAndSet(localBestFitness, localBestPosition, (AbstractEAIndividual)sortedPop[k], useHistoric);
// k++;
// if (k < pop.size()) compareAndSet(localBestFitness, localBestPosition, (AbstractEAIndividual)sortedPop[k], useHistoric);
// }
}
break;
case hpso: // Hierarchical PSO
if (index >= 0) {
k = getParentIndex(topologyRange, index, pop.size());
// compareAndSet(localBestFitness, localBestPosition, (AbstractEAIndividual)pop.get(k), useHistoric);
indy = pop.get(k);
System.arraycopy(indy.getData(partBestFitKey), 0, localBestFitness, 0, localBestFitness.length);
System.arraycopy(indy.getData(partBestPosKey), 0, localBestPosition, 0, localBestPosition.length);
@ -1488,7 +1480,7 @@ public class ParticleSwarmOptimization extends AbstractOptimizer implements java
AbstractEAIndividual indy = pop.getEAIndividual(i);
if (indy == null) {
System.err.println("Error in PSO.setPopulation!");
} else if (!indy.hasData(this.partTypeKey)) {
} else if (!indy.hasData(partTypeKey)) {
initIndividualDefaults(indy, initialVelocity);
initIndividualMemory(indy);
indy.putData(indexKey, i);

View File

@ -42,7 +42,7 @@ public abstract class AbstractDynTransProblem extends AbstractSynchronousOptimiz
* Evaluate the function at the individuals position using an arbitrary translation which may be dynamically changing.
*
* @param individual the individual to be evaluated
* @param t timestamp of the evaluation
* @param time timestamp of the evaluation
*/
@Override
public void evaluateAt(AbstractEAIndividual individual, double time) {

View File

@ -284,7 +284,7 @@ public abstract class AbstractMultiModalProblemKnown extends AbstractProblemDoub
* based on the full list of known optima. Assumes that both realOpts and population have fitness
* values assigned as in a maximization problem. This is the standard formulation of MPR.
*
* @param mmProb
* @param realOpts
* @param pop
* @param epsilon
* @return

View File

@ -49,8 +49,8 @@ public abstract class AbstractProblemBinary extends AbstractOptimizationProblem
* Evaluate a BitSet representing a possible solution. This is the target
* function implementation.
*
* @param x a BitSet representing a possible
* @return
* @param bs a BitSet representing a possible solution
* @return Fitness
*/
public abstract double[] evaluate(BitSet bs);

View File

@ -44,7 +44,6 @@ public class B1Problem extends AbstractProblemBinary implements java.io.Serializ
* values of the individual will be set inside this method.
*
* @param b The BitSet that is to be evaluated.
* @param l The length of the BitSet.
* @return Double[]
*/
@Override
@ -63,7 +62,7 @@ public class B1Problem extends AbstractProblemBinary implements java.io.Serializ
/**
* This method allows you to output a string that describes a found solution
* in a way that is most suiteable for a given problem.
* in a way that is most suitable for a given problem.
*
* @param individual The individual that is to be shown.
* @return The description.

View File

@ -262,7 +262,6 @@ public class BKnapsackProblem extends AbstractProblemBinary implements java.io.S
* values of the individual will be set inside this method.
*
* @param b The BitSet that is to be evaluated.
* @param l The length of the BitSet.
* @return Double[]
*/
@Override

View File

@ -529,7 +529,7 @@ public class BasicResourceLoader implements ResourceLoader {
/**
* Gets the byte data from a file.
*
* @param fileName Description of the Parameter
* @param stream Stream to read from
* @return the byte array of the file.
*/
private byte[] getBytesFromStream(InputStream stream) {

View File

@ -288,7 +288,7 @@ public class MultirunRefiner {
*/
public static String refineToText(ArrayList<double[]> result) {
double[] mean;
StringBuffer sbuf = new StringBuffer("Event\tBest\tMean\tWorst\n");
StringBuilder sbuf = new StringBuilder("Event\tBest\tMean\tWorst\n");
for (int i = 0; i < result.size(); i++) {
mean = result.get(i);

View File

@ -215,7 +215,7 @@ public final class BayNet {
* @param j edge to this node
*/
public void addEdge(Integer i, Integer j) {
if (i != j) {
if (!i.equals(j)) {
if (!this.network[i][j]) {
this.network[i][j] = true;
this.rootNodes.remove(j);
@ -253,7 +253,8 @@ public final class BayNet {
/**
* find the next value where all the parents are already set
*
* @param data
* @param probabilities
* @param nodes
* @return
*/
private int findNext(double[] probabilities, List<BayNode> nodes) {
@ -358,7 +359,6 @@ public final class BayNet {
* calculate the next probability
*
* @param data the already calculated data
* @param probabilities the already calculated probabilities
* @param toCalculate the Nodes that have yet to be calculated
* @param next the node for which to calculate the probability
* @return the new probabilities array
@ -463,10 +463,9 @@ public final class BayNet {
/**
* check if the given Network is acyclic
*
* @param net the Network
* @return is the net acyclic
* @return true if the net is acyclic
*/
public boolean isACyclic() {
public boolean isAcyclic() {
List<Pair<Integer, Integer>> deletedEdges = new LinkedList<>();
List<BayNode> nodes = getRootNodes();
boolean res = false;

View File

@ -37,16 +37,16 @@ public class CholeskyDecomposition implements java.io.Serializable {
/**
* Cholesky algorithm for symmetric and positive definite matrix.
*
* @param A Square, symmetric matrix.
* @param arg A square, symmetric matrix.
* @return Structure to access L and isspd flag.
*/
public CholeskyDecomposition(Matrix Arg) {
public CholeskyDecomposition(Matrix matrix) {
// Initialize.
double[][] A = Arg.getArray();
n = Arg.getRowDimension();
double[][] A = matrix.getArray();
n = matrix.getRowDimension();
L = new double[n][n];
isspd = (Arg.getColumnDimension() == n);
isspd = (matrix.getColumnDimension() == n);
// Main loop.
for (int j = 0; j < n; j++) {
double[] Lrowj = L[j];

View File

@ -274,7 +274,6 @@ public class Matrix implements Cloneable, Serializable {
/**
* Return the diagonal array for a matrix.
*
* @param M
* @return
*/
public double[] diag() {
@ -290,7 +289,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return Two-dimensional array copy of matrix elements.
*/
public double[][] getArrayCopy() {
double[][] C = new double[m][n];
for (int i = 0; i < m; i++) {
@ -304,7 +302,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return Matrix elements packed in a one-dimensional array by columns.
*/
public double[] getColumnPackedCopy() {
double[] vals = new double[m * n];
for (int i = 0; i < m; i++) {
@ -337,11 +334,10 @@ public class Matrix implements Cloneable, Serializable {
*
* @return Matrix elements packed in a one-dimensional array by rows.
*/
public double[] getRowPackedCopy() {
double[] vals = new double[m * n];
for (int i = 0; i < m; i++) {
System.arraycopy(A[i], 0, vals, i * n + 0, n);
System.arraycopy(A[i], 0, vals, i * n, n);
}
return vals;
}
@ -351,7 +347,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return m, the number of rows.
*/
public int getRowDimension() {
return m;
}
@ -361,7 +356,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return n, the number of columns.
*/
public int getColumnDimension() {
return n;
}
@ -374,7 +368,6 @@ public class Matrix implements Cloneable, Serializable {
* @return A(i, j)
* @throws ArrayIndexOutOfBoundsException
*/
public double get(int i, int j) {
return A[i][j];
}
@ -394,7 +387,7 @@ public class Matrix implements Cloneable, Serializable {
double[][] B = X.getArray();
try {
for (int i = i0; i <= i1; i++) {
System.arraycopy(A[i], j0, B[i - i0], j0 - j0, j1 + 1 - j0);
System.arraycopy(A[i], j0, B[i - i0], 0, j1 + 1 - j0);
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new ArrayIndexOutOfBoundsException("Submatrix indices");
@ -410,7 +403,6 @@ public class Matrix implements Cloneable, Serializable {
* @return A(r(:), c(:))
* @throws ArrayIndexOutOfBoundsException Submatrix indices
*/
public Matrix getMatrix(int[] r, int[] c) {
Matrix X = new Matrix(r.length, c.length);
double[][] B = X.getArray();
@ -455,8 +447,8 @@ public class Matrix implements Cloneable, Serializable {
* Get a submatrix.
*
* @param r Array of row indices.
* @param i0 Initial column index
* @param i1 Final column index
* @param j0 Initial column index
* @param j1 Final column index
* @return A(r(:), j0:j1)
* @throws ArrayIndexOutOfBoundsException Submatrix indices
*/
@ -466,7 +458,7 @@ public class Matrix implements Cloneable, Serializable {
double[][] B = X.getArray();
try {
for (int i = 0; i < r.length; i++) {
System.arraycopy(A[r[i]], j0, B[i], j0 - j0, j1 + 1 - j0);
System.arraycopy(A[r[i]], j0, B[i], 0, j1 + 1 - j0);
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new ArrayIndexOutOfBoundsException("Submatrix indices");
@ -802,7 +794,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A.*B
*/
public Matrix arrayTimes(Matrix B) {
checkMatrixDimensions(B);
Matrix X = new Matrix(m, n);
@ -821,7 +812,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A.*B
*/
public Matrix arrayTimesEquals(Matrix B) {
checkMatrixDimensions(B);
for (int i = 0; i < m; i++) {
@ -838,7 +828,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A./B
*/
public Matrix arrayRightDivide(Matrix B) {
checkMatrixDimensions(B);
Matrix X = new Matrix(m, n);
@ -857,7 +846,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A./B
*/
public Matrix arrayRightDivideEquals(Matrix B) {
checkMatrixDimensions(B);
for (int i = 0; i < m; i++) {
@ -874,7 +862,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A.\B
*/
public Matrix arrayLeftDivide(Matrix B) {
checkMatrixDimensions(B);
Matrix X = new Matrix(m, n);
@ -893,7 +880,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B another matrix
* @return A.\B
*/
public Matrix arrayLeftDivideEquals(Matrix B) {
checkMatrixDimensions(B);
for (int i = 0; i < m; i++) {
@ -910,7 +896,6 @@ public class Matrix implements Cloneable, Serializable {
* @param s scalar
* @return s*A
*/
public Matrix times(double s) {
Matrix X = new Matrix(m, n);
double[][] C = X.getArray();
@ -983,7 +968,6 @@ public class Matrix implements Cloneable, Serializable {
* @param s scalar
* @return replace A by s*A
*/
public Matrix timesEquals(double s) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
@ -1000,7 +984,6 @@ public class Matrix implements Cloneable, Serializable {
* @return Matrix product, A * B
* @throws IllegalArgumentException Matrix inner dimensions must agree.
*/
public Matrix times(Matrix B) {
if (B.m != n) {
throw new IllegalArgumentException("Matrix inner dimensions must agree.");
@ -1048,7 +1031,6 @@ public class Matrix implements Cloneable, Serializable {
* @return LUDecomposition
* @see LUDecomposition
*/
public LUDecomposition lu() {
return new LUDecomposition(this);
}
@ -1059,7 +1041,6 @@ public class Matrix implements Cloneable, Serializable {
* @return QRDecomposition
* @see QRDecomposition
*/
public QRDecomposition qr() {
return new QRDecomposition(this);
}
@ -1070,7 +1051,6 @@ public class Matrix implements Cloneable, Serializable {
* @return CholeskyDecomposition
* @see CholeskyDecomposition
*/
public CholeskyDecomposition chol() {
return new CholeskyDecomposition(this);
}
@ -1081,7 +1061,6 @@ public class Matrix implements Cloneable, Serializable {
* @return SingularValueDecomposition
* @see SingularValueDecomposition
*/
public SingularValueDecomposition svd() {
return new SingularValueDecomposition(this);
}
@ -1092,7 +1071,6 @@ public class Matrix implements Cloneable, Serializable {
* @return EigenvalueDecomposition
* @see EigenvalueDecomposition
*/
public EigenvalueDecomposition eig() {
return new EigenvalueDecomposition(this);
}
@ -1103,7 +1081,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B right hand side
* @return solution if A is square, least squares solution otherwise
*/
public Matrix solve(Matrix B) {
//System.out.print("m="+m+"n"+n);
return (m == n ? (new LUDecomposition(this)).solve(B) :
@ -1116,7 +1093,6 @@ public class Matrix implements Cloneable, Serializable {
* @param B right hand side
* @return solution if A is square, least squares solution otherwise.
*/
public Matrix solveTranspose(Matrix B) {
return transpose().solve(B.transpose());
}
@ -1126,7 +1102,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return inverse(A) if A is square, pseudoinverse otherwise.
*/
public Matrix inverse() {
return solve(identity(m, m));
}
@ -1136,7 +1111,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return determinant
*/
public double det() {
return new LUDecomposition(this).det();
}
@ -1146,7 +1120,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return effective numerical rank, obtained from SVD.
*/
public int rank() {
return new SingularValueDecomposition(this).rank();
}
@ -1156,7 +1129,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return ratio of largest to smallest singular value.
*/
public double cond() {
return new SingularValueDecomposition(this).cond();
}
@ -1166,7 +1138,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @return sum of the diagonal elements.
*/
public double trace() {
double t = 0;
for (int i = 0; i < Math.min(m, n); i++) {
@ -1182,7 +1153,6 @@ public class Matrix implements Cloneable, Serializable {
* @param n Number of colums.
* @return An m-by-n matrix with uniformly distributed random elements.
*/
public static Matrix random(int m, int n) {
Matrix A = new Matrix(m, n);
double[][] X = A.getArray();
@ -1201,7 +1171,6 @@ public class Matrix implements Cloneable, Serializable {
* @param n Number of colums.
* @return An m-by-n matrix with ones on the diagonal and zeros elsewhere.
*/
public static Matrix identity(int m, int n) {
Matrix A = new Matrix(m, n);
double[][] X = A.getArray();
@ -1242,7 +1211,6 @@ public class Matrix implements Cloneable, Serializable {
* @param w Column width.
* @param d Number of digits after the decimal.
*/
public void print(int w, int d) {
print(new PrintWriter(System.out, true), w, d);
}
@ -1255,7 +1223,6 @@ public class Matrix implements Cloneable, Serializable {
* @param w Column width.
* @param d Number of digits after the decimal.
*/
public void print(PrintWriter output, int w, int d) {
DecimalFormat format = new DecimalFormat();
format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
@ -1277,7 +1244,6 @@ public class Matrix implements Cloneable, Serializable {
* @param width Field width for each column.
* @see java.text.DecimalFormat#setDecimalFormatSymbols
*/
public void print(NumberFormat format, int width) {
print(new PrintWriter(System.out, true), format, width);
}
@ -1325,7 +1291,6 @@ public class Matrix implements Cloneable, Serializable {
*
* @param input the input stream.
*/
public static Matrix read(BufferedReader input) throws java.io.IOException {
StreamTokenizer tokenizer = new StreamTokenizer(input);
@ -1382,7 +1347,6 @@ public class Matrix implements Cloneable, Serializable {
/**
* Check if size(A) == size(B) *
*/
private void checkMatrixDimensions(Matrix B) {
if (B.m != m || B.n != n) {
System.out.println("B.m" + B.m);
@ -1397,7 +1361,7 @@ public class Matrix implements Cloneable, Serializable {
* Subtract a line from the indicated line of this matrix in place.
*
* @param rowIndex
* @param B
* @param v
*/
public void rowSubtract(int rowIndex, double[] v) {
if ((v.length != n) || (rowIndex < 0) || (rowIndex >= m)) {

View File

@ -454,7 +454,7 @@ public final class Mathematics {
*/
public static boolean isValidVec(double[][] d) {
for (int i = 0; i < d.length; i++) {
if (!isValidVec(d[i])) {
if (!isValidVector(d[i])) {
return false;
}
}
@ -468,7 +468,7 @@ public final class Mathematics {
* @param d
* @return
*/
public static boolean isValidVec(double[] d) {
public static boolean isValidVector(double[] d) {
double sum = 0;
for (int i = 0; i < d.length; i++) {
if (Double.isNaN(d[i])) {
@ -479,7 +479,7 @@ public final class Mathematics {
if (Double.isNaN(sum)) {
return false;
}
return Math.abs(sum) >= 0.000000000000000001;
return Math.abs(sum) >= 10E-18;
}
/**

View File

@ -58,7 +58,7 @@ public abstract class AbstractDataSet {
/**
* Modifies the X data.
*
* @param the data modifier
* @param modifier the data modifier
*/
public void modifyXData(AbstractDataModifier modifier) {
modifier.modifyX(xDoubleData);
@ -67,7 +67,7 @@ public abstract class AbstractDataSet {
/**
* Modifies the Y data.
*
* @param the data modifier
* @param modifier the data modifier
*/
public void modifyYData(AbstractDataModifier modifier) {
modifier.modifyY(yDoubleData);
@ -76,7 +76,7 @@ public abstract class AbstractDataSet {
/**
* Modifies the data.
*
* @param the data modifier
* @param modifier the data modifier
*/
public void modifyData(AbstractDataModifier modifier) {
modifier.modify(xDoubleData, yDoubleData);