How to use patternsearch to optimize two control vectors of a function; optimizing both variables instead of passing one of them?

1 回表示 (過去 30 日間)
Dear Alan, I have an optimization problem where my function has two control variables as the following
function [NetPV,finalSupply] = OptimizedRate (Weights,NRates)
Weights and NRates are vectors as: Weights = [x1 x2 x3] and NRates = [y1 y2 y3]
I want to optimized Weights and NRates not just passing one of them. I have seen some examples like: https://uk.mathworks.com/help/optim/ug/passing-extra-parameters.html
and tried them. However this pass NRates variable instead of optimizing it. [x,fval,exitflag,output] = patternsearch(@(Weights)OptimizedRate(Weights,NRates),x0,[],[],Aeq,beq,LB,UB,options);
I'm looking for away to optimize Weights and NRates variables jointly.
Thanks for your help!

採用された回答

Sean de Wolski
Sean de Wolski 2018 年 1 月 4 日
patternsearch(@(x)OptimizedRate(x(1),x(2)), [weight0 nRate0], ...
Index into one variable that is passed to the objective function.
  1 件のコメント
Yaser Khojah
Yaser Khojah 2018 年 1 月 4 日
Thanks, I just applied it but the optimizer is taking forever to run. What about the linear constraints?
For example: Weight 1 + Weight 2 .... = Demand and nRate 1 + nRate 2 + .... = Demand
Thank you.

サインインしてコメントする。

その他の回答 (1 件)

Alan Weiss
Alan Weiss 2018 年 1 月 4 日
I think that the simplest way is to combine your variables into one vector, x = [Weights,NRates], which is what any optimization solver needs. See Compute Objective Function.
For example,
function [NetPV,finalSupply] = mynewfun(x)
Weights = x(1:3);
NRates = x(4:6);
[NetPV,finalSupply] = OptimizedRate(Weights,NRates);
Optimize mynewfun instead of OptimizedRate. Be sure to give your initial point x0 as a 6-element vector.
Alan Weiss
MATLAB mathematical toolbox documentation
  3 件のコメント
Alan Weiss
Alan Weiss 2018 年 1 月 4 日
The linear constraints should be written in terms of the 6-D variable x.
Alan Weiss
MATLAB mathematical toolbox documentation
Yaser Khojah
Yaser Khojah 2018 年 1 月 4 日
Thanks Alan, is there an example I can follow?

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by