optimization problem with 'fminunc' solver for varying size variables?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, All. I have one objective function that I would like to minimize with a large set of variables (well, not that large about 100). I have managed to put all these variables into one vector as x0 for initial condition. The problem is that I am also trying to optimize different partial sets of these variables. Say, I want to optimize 75 parameters while remaining the other 25 as their initial values (as constant) etc.. I have been thinking of create of logic vector like [1 1 0 1 0...] to mask the 25 parameters not involved with the optimization process. But could not realize it yet. Please give some hints, any idea is welcome. Thanks
0 Commenti
Risposta accettata
Walter Roberson
il 1 Lug 2016
Two possible ways:
1) switch to fmincon and for the variables that are to be constants, set their lb and ub to be the same constant
2) construct an anonymous function that takes in a vector of length (e.g.) 75, and creates a new vector of length 100 with the remaining locations filled with the constants. For example,
ReOrder = @(Vector, NewOrder) Vector(NewOrder);
this_objective = @(x) original_objective_function ( ReOrder( [x(:), ConstantParameters(:)], ProperOrder) );
ProperOrder would be a vector indicating for first the (e.g.) 75 parameters and then the (e.g.) 25 constants, where each one goes in the order expected by original_objective_function. For example if you had a logical vector Treat_As_Constant then
ProperOrder = [find(~Treat_As_Constant(:)); find(Treat_As_Constant)];
3 Commenti
Walter Roberson
il 1 Lug 2016
original_objective_function = @(x) 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [-1 2];
%utility
ReOrder = @(Vector, NewOrder) Vector(NewOrder);
% 1 - variable not be optimized
Treat_As_Constant = logical([1 0]); %or [true, false]
[~, ProperOrder] = sort([find(~Treat_As_Constant(:)); find(Treat_As_Constant(:))]);
% define refine anonymous function
Constant_Parameters = x0(Treat_As_Constant);
this_objective = @(x) original_objective_function( ReOrder( [x(:); Constant_Parameters(:)], ProperOrder) );
%minimize over non-constant values
x_uncon = fminunc(this_objective, x0(~Treat_As_Constant));
%reconstruct pulling constant parameters into place
x = ReOrder([x_uncon(:), Constant_Parameters(:)], ProperOrder);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!