use of optimization constraint mask in matlab fmincon or similar

1 回表示 (過去 30 日間)
fima v
fima v 2022 年 2 月 4 日
編集済み: Shishir Reddy 2025 年 1 月 6 日
Hello, I know that fmincon uses expressions for describing constraints .
but i want my optimization function to use a value mask instead of expresson
how do i define fmincon so it will be as close as possible to some vector value.
IE my cost function will be as close as possible to some value mask
  1 件のコメント
Matt J
Matt J 2022 年 2 月 4 日
If you already know what the value that your cost function is supposed to have, what is there to minimize?

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

回答 (1 件)

Shishir Reddy
Shishir Reddy 2025 年 1 月 6 日
編集済み: Shishir Reddy 2025 年 1 月 6 日
Hi Fima
To use a value mask where specific elements of the optimization variable are fixed to certain values, the approach can be modified by incorporating these fixed values directly into the optimization process. Kindly refer to the following steps to understand about the workflow to solve this problem -
1. A mask should be created to specify which elements are fixed and which are free to be optimized.
target = [desired_value1, desired_value2, ..., desired_valueN];
% The mask is defined (1 for free, 0 for fixed)
mask = [1, 0, 1, ..., 0];
2. Initial guess has to be provided to the free variables.
3. The cost function has to be modified to only optimize the free variables.
function cost = costFunctionWithMask(x_free, target, mask)
x_full = target;
x_full(mask==1) = x_free
cost = sum((x_full - target).^2);
end
4. fmincon is run to optimize the free variables. After optimization, the free variables are combined with the fixed values to form the complete optimized vector
[x_free_opt, fval] = fmincon(objective, x0_free, A, b, Aeq, beq, lb, ub, nonlcon, options);
x_opt = combineWithMask(x_free_opt, target, mask);
These snippets provide a concise overview of how a value mask can be used to fix certain elements while optimizing others in MATLAB.
I hope this helps.

カテゴリ

Help Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by