What is the correction of error: Failure in initial user-supplied objective function evaluation. PARTICLESWARM cannot continue?

15 Ansichten (letzte 30 Tage)
I'm trying to solve an optimization problem using PARTICLESWARM function in MATLAB2014b. with aid of Open Source ECG Toolbox, version 1.0, November 2006 Released under the GNU General Public License.
The main objective of the code is to find the optimal parameters of the ECG model to achieve the minimum model error.
I have used PSO as optimizer to find these optimal parameters.
ends up with error:
Failure in initial user-supplied objective function evaluation. PARTICLESWARM cannot continue

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 24 Apr. 2018
Without reading your code, I can tell you that your initial swarm contained at least one point that led to a NaN or Inf or complex objective function value. To avoid this error,
  • Ensure that your objective function always returns finite real values, by carefully debugging it, OR
  • Pass an initial swarm where every point returns a real finite value. See the InitialSwarmMatrix option in particleswarm options.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
  4 Kommentare
MOSAB YOUSIF
MOSAB YOUSIF am 25 Apr. 2018

Thans alot Alan

i make the modification in function ECGOptimizeModel(x, indexes, meanphase)

can be, in this line:

options = optimoptions('particleswarm','SwarmSize',length(InitParams),'HybridFcn',@fminsearch,'Vectorized','on');

but i ends with error:

Error using particleswarm>makeState (line 699)
When OPTIONS.Vectorized is 'on', your objective function must return a vector of length equal to
the number of particles specified in OPTIONS.SwarmSize.
Error in particleswarm>pswcore (line 164)
state = makeState(nvars,lbMatrix,ubMatrix,objFcn,options);
Error in particleswarm (line 146)
[x,fval,exitFlag,output] = pswcore(objFcn,nvars,lbRow,ubRow,output,options);
Error in ECGOptimizeModel (line 16)
params = particleswarm(@(InitParams)
ECGModelError(InitParams,x,meanphase,0),length(InitParams),InitParams-2,InitParams+2,options)
Error in MY_ECGBeatFitterAuto (line 139)
        [params model er] = ECGOptimizeModel(y, indx, meanphase);

also i'm not figureout how to vectorize opjective function: can you help me with that, my objective function is:

function E = ECGModelError(X,ECGmn,Phasemn,flag);
%
% Synthetic ECG model error
%
% Open Source ECG Toolbox, version 1.0, November 2006
% Released under the GNU General Public License
% Copyright (C) 2006  Reza Sameni
% Sharif University of Technology, Tehran, Iran -- LIS-INPG, Grenoble, France
% reza.sameni@gmail.com
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details. You should have received a copy of the
% GNU General Public License along with this program; if not, write to the
% Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
% MA  02110-1301, USA.
L = (length(X)/3);
alphai = X(1:L);
bi = X(L+1:2*L);
tetai = X(2*L+1:3*L);
Z = zeros(size(ECGmn));
for j = 1:length(alphai),
    dtetai = rem(Phasemn - tetai(j) + pi,2*pi)-pi;
    Z = Z + alphai(j) .* exp(-dtetai .^2 ./ (2*bi(j) .^ 2));
end
if(flag==0)
    E = (Z-ECGmn);
elseif(flag==1)
    E = (Z);
end
sks2
sks2 am 18 Apr. 2020
This has perplexed me for a few weeks now.
The answer is to make sure your objective function can return a vector that is sized M x 1.
Vectorized particleswarm
If your objective function can evaluate all the particles at once, you can usually save time by setting the UseVectorized option to true. Your objective function should accept an M-by-N matrix, where each row represents one particle, and return an M-by-1 vector of objective function values. This option works the same way as the patternsearch and ga UseVectorized options. For patternsearch details, see Vectorize the Objective and Constraint Functions.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by