diff --git a/resources/MatlabInterface/@JEInterface/JEInterface.m b/resources/MatlabInterface/@JEInterface/JEInterface.m index 46f454e9..3bc7e776 100644 --- a/resources/MatlabInterface/@JEInterface/JEInterface.m +++ b/resources/MatlabInterface/@JEInterface/JEInterface.m @@ -59,6 +59,8 @@ int.optParamValues = []; int.hexMask=hex2dec('ffffffff'); int.dataType=''; % to be set later! int.outputAllStatsFields=1; +int.seedPop=[]; +int.seedPopFit=[]; if (isa(fhandle, 'function_handle')) int.f = fhandle; diff --git a/resources/MatlabInterface/@JEInterface/getDesc.m b/resources/MatlabInterface/@JEInterface/getDesc.m index 7f16c9cf..0e8664a4 100644 --- a/resources/MatlabInterface/@JEInterface/getDesc.m +++ b/resources/MatlabInterface/@JEInterface/getDesc.m @@ -1,11 +1,17 @@ function desc = getDesc(int, ID) -% Return the String description of an indicated optimizer -% with member descriptions. +% For an integer ID, return the String description of the indicated optimizer +% with member descriptions. In case ID is of a different type, it is attempted +% to retrieve a String description for that object directly. import eva2.gui.BeanInspector; import eva2.server.modules.GOParameters; import eva2.OptimizerFactory; -params = OptimizerFactory.getParams(ID, int.mp); -desc = BeanInspector.getDescription(params.getOptimizer, false); +if isnumeric(ID) + params = OptimizerFactory.getParams(ID, int.mp); + desc = BeanInspector.getDescription(params.getOptimizer, false); +else + desc = BeanInspector.getDescription(ID, false); +end + diff --git a/resources/MatlabInterface/@JEInterface/optimize.m b/resources/MatlabInterface/@JEInterface/optimize.m index eb176c33..6ca2eaad 100644 --- a/resources/MatlabInterface/@JEInterface/optimize.m +++ b/resources/MatlabInterface/@JEInterface/optimize.m @@ -95,6 +95,11 @@ if ((nargin == 2) || (nargin == 3)) error('invalid Display option, only off/final/notify/iter are recognized'); end + if isempty(int.seedPop) % set the seed data + int.mp.clearSeedPopulation; + else + int.mp.setSeedPopulation(int.seedPop, int.seedPopFit); + end int=runEvalLoopJE(int, 1, optType, outputFilePrefix, -1, -1, -1); else diff --git a/resources/MatlabInterface/@JEInterface/setSeedPopFit.m b/resources/MatlabInterface/@JEInterface/setSeedPopFit.m new file mode 100644 index 00000000..f963528d --- /dev/null +++ b/resources/MatlabInterface/@JEInterface/setSeedPopFit.m @@ -0,0 +1,27 @@ +function int=setSeedPopFit(int, seedData, seedDataFit) +% int=setSeedPopulation(int, seedData) +% Set the seed data for optimization. A 2-D array of doubles is expected +% which will be converted to the appropriate data type if necessary. +% The seed data must fit the problem dimension, while the population size +% will be adapted if necessary. If the seed data is an empty array, the +% seed population will be initialized randomly as by default. +% int: the interface instance +% seedData: 2-D array of dimension popSize x problemDim or [] to reset +% and use random initial population + +if length(seedData)>1 + %size(int.range,1) + %int.dataType + %int.dim + if size(seedData,2)~=int.dim + error(['Mismatching dimension: seed data should be of size popSize x problemDim. Current problemDim is ' num2str(int.dim)]); + end + if size(seedData,1)~=size(seedDataFit,1) + error('Mismatching dimension of fitness array: expecting equal no. lines in seedData and seedDataFit!'); + end + int.seedPop=seedData; + int.seedPopFit=seedDataFit; +else + int.seedPop=[]; % reset it + int.seedPopFit=[]; +end diff --git a/resources/MatlabInterface/@JEInterface/setSeedPopulation.m b/resources/MatlabInterface/@JEInterface/setSeedPopulation.m new file mode 100644 index 00000000..16c7f871 --- /dev/null +++ b/resources/MatlabInterface/@JEInterface/setSeedPopulation.m @@ -0,0 +1,32 @@ +function int=setSeedPopulation(int, seedData) +% int=setSeedPopulation(int, seedData) +% Set the seed data for optimization. A 2-D array of doubles is expected +% which will be converted to the appropriate data type if necessary. +% The seed data must fit the problem dimension, while the population size +% will be adapted if necessary. If the seed data is an empty array, the +% seed population will be initialized randomly as by default. +% int: the interface instance +% seedData: 2-D array of dimension popSize x problemDim or [] to reset +% and use random initial population + +if length(seedData)>1 + %size(seedData) + %size(int.range,1) + %int.dataType + %int.dim + if size(seedData,2)~=int.dim + error(['Mismatching dimension: seed data should be of size popSize x problemDim. Current problemDim is ' num2str(int.dim)]); + end + + for i=1:size(seedData,1) + if (isempty(int.args)) + fit(i,:) = feval(int.f, seedData(i,:)); + else + fit(i,:) = feval(int.f, seedData(i,:), int.args); + end + end + int=setSeedPopFit(int,seedData,fit); +else + int.seedPop=[]; % reset it + int.seedPopFit=[]; +end