use of optimization constraint mask in matlab fmincon or similar
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Matt J
le 4 Fév 2022
If you already know what the value that your cost function is supposed to have, what is there to minimize?
Réponses (1)
Shishir Reddy
le 6 Jan 2025
Modifié(e) : Shishir Reddy
le 6 Jan 2025
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Optimization Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!