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

11 views (last 30 days)
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

Accepted Answer

Alan Weiss
Alan Weiss on 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
sks2 on 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.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by