optimization problem with 'fminunc' solver for varying size variables?

3 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2016-7-1
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 个评论
Walter Roberson
Walter Roberson 2016-7-1
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);
Wenwu
Wenwu 2016-7-5
Mr. Walter,
That works great as planned. Thanks very much for your great explanation as source code.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver-Based Nonlinear Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by