필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
Wenwu
Wenwu 2016년 7월 1일
댓글: Wenwu 2016년 7월 5일
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