How to use a constraint on the output of a goal function?

6 次查看(过去 30 天)
I have an optimization problem where I have 5 variables to optimize. I am using fmincon now wih sqp approach, but in future I may use some other methods as well. The issue is that for some specific combinations of my variables, the goal becomes a complex number, which is not desriable. I was wondering how to avoid these combinations.
For example, if F is my goal I want to set some check to see if F is a real number (and then accept it as a candidate). How can I do it? I have checked the documentation and I have just found setting up a constraint function that works as F <= 0, however I can't think of a clever way to tune this to my complex number problem.

采纳的回答

Torsten
Torsten 2023-10-12
编辑:Torsten 2023-10-12
You must ask yourself: How could the objective function become complex-valued ? Maybe you have a log(x) expression in it and the x became negative ? Or you have an x^a expression in it and the x became negative ?
Once you found the reason, you might be able to set a constraint - either as a lower or upper bound on parameters or in the function "nonlcon" - to avoid this.
  3 个评论
Torsten
Torsten 2023-10-12
编辑:Torsten 2023-10-12
The first thing I would try is to define the product of the F_n as objective function.
The second thing I would try is to check in your objective function whether all F_n are > 0. If not, return -Inf or NaN (assuming you want to maximize).
The third thing I would try is to define F_n >= 0 for all n in "nonlcon" as constraints.
Tworit Dash
Tworit Dash 2023-10-16
I will try the second way; because I want to compute F inside the Goal function. And I can not try the product, because it is kind of a log-likelihood which in linear form is very low in value.

请先登录,再进行评论。

更多回答(0 个)

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by