diff --git a/resources/MatlabInterface/@JEInterface/JEInterface.m b/resources/MatlabInterface/@JEInterface/JEInterface.m
index bd973e3c..d647155a 100644
--- a/resources/MatlabInterface/@JEInterface/JEInterface.m
+++ b/resources/MatlabInterface/@JEInterface/JEInterface.m
@@ -12,6 +12,18 @@ function int = JEInterface(interfaceName, fhandle, range, varargin)
% JavaEvA default values.
% defaultArgs: (optional) additional constant argument to the target
% function, empty by default.
+% Recognized options are:
+% TolX: convergence criterion in the solution space
+% TolFun: convergence criterion in the target space
+% MaxFunEvals: maximum number of function evaluations
+% Display: 'off'/'final'/'notify'/'iter', where 'notify' corresponds to
+% displaying every k-th iteration, which k=10 as default.
+% The termination criterion of a run is a combination of the TolX, TolFun and
+% MaxFunEvals criteria. The run terminates if MaxFunEvals has been reached
+% or the best solution changes both in domain and codomain less than TolX
+% and TolFun for a certain time, e.g. 100 evaluations.
+% To ignore a criterion, set it to 0. E.g. to perform 10^5 evaluations in
+% any case, set TolX=TolFun=0 and MaxFunEvals=10^5.
int.args = [];
int.opts = optimset('MaxFunEvals', javaeva.OptimizerFactory.getDefaultFitCalls, 'TolX', 1e-4, 'TolFun', 1e-4);
diff --git a/resources/MatlabInterface/@JEInterface/optimize.m b/resources/MatlabInterface/@JEInterface/optimize.m
index effae025..f6e59dc9 100644
--- a/resources/MatlabInterface/@JEInterface/optimize.m
+++ b/resources/MatlabInterface/@JEInterface/optimize.m
@@ -1,18 +1,18 @@
function retInt = optimize(int, optType, varargin)
% Start a JavaEvA optimization run.
% optimize(interface, optType, [, outputFilePrefix ] )
-% where
+% where
% interface: instance of JEInterface
% optType: integer indicating the type of the optimization strategy
% to use.
% resultFilePrefix: (optional) char prefix for an optional verbose
% output file
-if (int.finished == 0)
+if (int.finished == 0)
error('please wait for the current run to finish');
end
if ((nargin == 2) || (nargin == 3))
- if (nargin == 3)
+ if (nargin == 3)
outputFilePrefix = varargin{1};
else
outputFilePrefix = 'none';
@@ -27,9 +27,9 @@ if ((nargin == 2) || (nargin == 3))
xTol = int.opts.TolX;
maxEvals = int.opts.MaxFunEvals;
fTol = int.opts.TolFun;
-
+
import javaeva.server.go.operators.terminators.PhenotypeConvergenceTerminator;
- import javaeva.server.go.operators.terminators.FitnessConvergenceTerminator;
+ import javaeva.server.go.operators.terminators.FitnessConvergenceTerminator;
import javaeva.server.go.operators.terminators.CombinedTerminator;
import javaeva.server.go.operators.terminators.EvaluationTerminator;
import javaeva.OptimizerFactory;
@@ -39,6 +39,7 @@ if ((nargin == 2) || (nargin == 3))
% values of 1e-4 in . Thats what we do as well
if (isempty(int.opts.TolX)) ; xTol = 1e-4; end
if (isempty(int.opts.TolFun)) ; fTol = 1e-4; end
+
% construct Terminators
if ((xTol > 0) && (fTol > 0))
% both criteria are given, use combination
@@ -48,12 +49,12 @@ if ((nargin == 2) || (nargin == 3))
else if (fTol > 0 ) % only fitness covnergence
convTerm = FitnessConvergenceTerminator(fTol, 100, 1, 1);
else
- convTerm = 'undef'; % signal that there is no terminator yet
+ convTerm = 'undef'; % signal that there is no terminator yet
end
end
end
- if (ischar(convTerm)) % if no convergence terminator is defined so far, use fitness calls
+ if (ischar(convTerm)) % if no convergence terminator is defined so far, use fitness calls
if (isempty(maxEvals))
error('Error: no termination criterion defined! Please check options.');
% int.opts.MaxFunEvals = OptimizerFactory.getDefaultFitCalls;
@@ -61,9 +62,9 @@ if ((nargin == 2) || (nargin == 3))
end
convTerm = EvaluationTerminator(maxEvals);
javaeva.OptimizerFactory.setTerminator(convTerm);
- else % there is a convergence terminator
+ else % there is a convergence terminator
javaeva.OptimizerFactory.setTerminator(convTerm); % so set it
- if (~isempty(maxEvals))
+ if (~isempty(maxEvals) && (maxEvals > 0))
% if TolX/TolFun plus MaxFunEvals is defined additionally, combine an
% EvaluationTerminator in disjunction, as Matlab does.
javaeva.OptimizerFactory.addTerminator(EvaluationTerminator(maxEvals), 0);
@@ -73,14 +74,21 @@ if ((nargin == 2) || (nargin == 3))
% set display
if (strcmp(int.opts.Display,'off') || isempty(int.opts.Display))
int.mp.setStatsOutput(0);
- elseif (strcmp(int.opts.Display, 'iter'))
+ elseif (strcmp(int.opts.Display, 'final'))
int.mp.setStatsOutput(1);
+ elseif (strcmp(int.opts.Display, 'notify'))
+ % 'notify' is not the perfect notion for "show every k-th
+ % iteration", but optimset wont allow changing names.
+ int.mp.setStatsOutput(2);
+ elseif (strcmp(int.opts.Display, 'iter'))
+ % this should rather be 2 in JE slang, but in matlab slang its more like 3
+ int.mp.setStatsOutput(3);
else
- error('invalid Display option, only off/iter are recognized');
+ error('invalid Display option, only off/final/notify/iter are recognized');
end
-
+
int=runEvalLoopJE(int, 1, optType, outputFilePrefix, -1, -1, -1);
-
+
else
error('Wrong number of arguments!')
end
diff --git a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m
index 1fae3eaf..cee8dc85 100644
--- a/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m
+++ b/resources/MatlabInterface/@JEInterface/runEvalLoopJE.m
@@ -2,6 +2,10 @@ function int=runEvalLoopJE(int, optOrPostProc, optType, outputFilePrefix, steps,
% Internal method starting a JavaEvA optimization loop.
% Calling this directly may interfere with optimization.
+% This function handles the communciation between JE and Matlab, main
+% optimization configuration is done in the
+% optimize/optimizeWith/postProcess functions from which this one should be
+% called.
% optOrPostProc: 1 for optimize, 2 for postProcess
% optType, outputFilePrefix are parameters for optimize, dont care when
% postprocessing.
@@ -35,17 +39,19 @@ end
% own stop button). we decide this by checking if the global variable
% stopOptimization is empty. if it is then it is not the toolbox calling
% and we create an own button to stop it.
-if isempty(stopOptimization),
- % create a cancel button box (case without SBtoolbox)
- h=figure('Position',[100 600 250 80], 'MenuBar', 'none', 'Name', 'JavaEvA optimization running...', 'NumberTitle','off');
- uicontrol(h,'Style', 'pushbutton', 'String', 'Cancel', 'Position', [25 25 60 30], 'Callback', 'global stopOptimization; stopOptimization=1;');
- uicontrol(h,'Style', 'text', 'String', stopText, 'Position', [100 25 120 30]);
- drawnow;
- % set it to 0 now
+if isempty(stopOptimization),
+ % set switch to 0 now
stopOptimization = 0;
+
+ % create a cancel button box (case without SBtoolbox)
+ boxHandle=figure('Position',[100 600 250 80], 'MenuBar', 'none', 'Name', 'JavaEvA optimization running...', 'NumberTitle','off');
+ uicontrol(boxHandle,'Style', 'pushbutton', 'String', 'Cancel', 'Position', [25 25 60 30], 'Callback', 'global stopOptimization; stopOptimization=1;');
+ uicontrol(boxHandle,'Style', 'text', 'String', stopText, 'Position', [100 25 120 30]);
+ drawnow;
% set flag for non toolbox optimization
nontoolboxopt = 1;
else
+ % disp('seems like the toolbox is going on');
% its an estimation using the toolbox' parameter estimation thing
nontoolboxopt = 0;
end
@@ -77,10 +83,12 @@ catch
disp('Error in evaluate!');
%int.mediator.quit; % just in case
%int.mediator='';
- if (nontoolboxopt == 1)
- if (ishandle(h)) , close(h); end
- clear global stopOptimization
- end
+
+ % why should this be done more than once in the end?
+ %if (nontoolboxopt == 1)
+ % if (ishandle(int.boxHandle)) , close(int.boxHandle); int.boxHandle=''; end
+ % clear global stopOptimization
+ %end
end
% write back results
@@ -94,6 +102,6 @@ int.mediator='';
% and not from the toolboxes parameter estimation function (which has an
% own stop button). we decide this by checking nontoolboxopt
if nontoolboxopt == 1,
- if (ishandle(h)) , close(h); end
+ if (ishandle(boxHandle)) , close(boxHandle); end
clear global stopOptimization
end
diff --git a/resources/MatlabInterface/@JEInterface/stopOptimize.m b/resources/MatlabInterface/@JEInterface/stopOptimize.m
index 5f99303b..19efcea4 100644
--- a/resources/MatlabInterface/@JEInterface/stopOptimize.m
+++ b/resources/MatlabInterface/@JEInterface/stopOptimize.m
@@ -16,6 +16,7 @@ if (nargin > 1) && (ischar(varargin{1}) && (strcmp(varargin{1},'kill')==1))
JEMediator.quit; % just in case
JEMediator='';
clear global JEMediator;
+ clear global stopOptimization;
else
disp('no mediator to kill');
end
diff --git a/resources/ParticleSwarmOptimization.html b/resources/ParticleSwarmOptimization.html
index 66bf080e..826234d8 100644
--- a/resources/ParticleSwarmOptimization.html
+++ b/resources/ParticleSwarmOptimization.html
@@ -11,13 +11,31 @@ behaviour seen in animals like birds or ants. A swarm of particles is a set of i
"flying" across the search space with individual velocity vectors. There is no selection as in
classic Evolutionary Algorithms. Instead, the individuals exchange knowledge about the space they
have come across. Each one is attracted to the best position the individual has seen so far (cognitive
-component) and to the best position known by its neighbors (social component).
+component) and to the best position known by its neighbors (social component).
+
The neighborhood is defined by the swarm velocity, which may be a linear ordering, a grid and some others. The influence of the velocity of the last time-step is taken into account using an inertness/ constriction parameter, which controls the convergence behaviour of the swarm. +
The influence of social and cognitive attraction are weighed using the phi parameters. In the constriction variant there is a dependence enforced between constriction and the phi, making sure that -the swarm converges slowly but steadily, see the publications of Clerc, e.g.+The topology defines the communication structure of the swarm. In linear topology, each particle has contact +to n others in two directions, so there is a linear overlay structure. The grid topology connects a particle +in 4 directions, while the star variant is completely connected. The random variant just connects each +particle to k others by random and anew in every generation cycle. +Basically, the more connections are available, the quicker will information about good areas spread through +the swarm and lead to quicker convergence, thereby increasing the risk of converging prematurely. +By default, the random (e.g. with range=4) or grid structure (e.g. with range=2) are good choices. +
++The multi-swarm approach splits the main swarm in sub-swarms defined by the distance to a local "leader", +as in the dynamic multi-swarm approaches by Shi and Branke, for example. The tree structure orders the +swarm to a tree of degree k, where the fittest individuals are on top and inform all their children nodes. +In this case, the higher the degree, the quicker will information spread. HPSO is a hierarchical tree variant +by Janson and Middendorf, 2005.