Coding problem in pattern search optimization algorithm

조회 수: 3 (최근 30일)
Thomas Ewald
Thomas Ewald 2020년 2월 7일
댓글: Thomas Ewald 2021년 6월 3일
Hello,
i tried to use pattern search algorithm to find the minimum of a rather simple function of two variables. While running an error occures saying: "Operands to the || and && operators must be convertible to logical scalar values."
I was able to track the error down to line 94 in psAugConverged.m file, where it says "if ~isempty(infMessage) && strmatch('optimlib:optimfcnchk',infMessage)", which is causing the error. Sadly I cannot change this, bacause I do not have permission to change those files.
Is this a bug, can this be changed, and is there a way I can use the algorithm?
Best regards
Thomas

답변 (2개)

John D'Errico
John D'Errico 2020년 2월 7일
Your objective function needs to return a SCALAR value for any set of inputs. That is, you cannot minimize two (or more) independent objectives at once.
So this is NOT a problem of needing to change the code for patternsearch. If you got that error, it suggests that you have made a mistake. Your function returns more than one result for a set of inputs.
A common mistake that new users make is they want to use a tool like this as a regression tool, perhaps fitting a curve or line to a set of data. You cannot do that, at least not directly. What you need to do in that case is to compute ONE objective, thus reducing hte problem to a scalar result. This is why tools operate on the sum of squares of residuals.

Thomas Ewald
Thomas Ewald 2020년 2월 7일
Hello,
thanks for the quick reply!
As I can see it, my objective function is strictly returning a single value, not any array or anything else. I added a "isscalar" condition to the function, which throws an error if the value is not scalar, to be sure on that.
I caught the error message and it shows me the file and the line where the error occurs. Also it tells, that the error is caused by trying to compare (&&) the values, which are returned by the strmatch function, which can, in my understanding, return multiple values. Also the input argument (a string of some sort) of named function, which is causing the error due to the error message, is not an argument I create in my code, it is created by pattern search code.
I would be thankful for further help, best regards
Thomas
  댓글 수: 3
Orcan Maktal
Orcan Maktal 2021년 6월 3일
편집: Orcan Maktal 2021년 6월 3일
Could you solve your problem? Because I have the same issue, it iterates and fails with that error. I am optimizing an ODE, for such cases, it is normal that I have NaN.
Thomas Ewald
Thomas Ewald 2021년 6월 3일
Unfortunately, no. I changed to ga() instead, which works.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by