How can I make patternsearch optimize using additional values?

조회 수: 1 (최근 30일)
Kei Manabe
Kei Manabe 2020년 6월 4일
댓글: Kei Manabe 2020년 7월 3일
I am trying to optimize the Page test parameters. In the last two lines, as the cost function of patternsearch, "RSS" is calculated. Basically, I would like to find the parameters to minimize RSS. However, I would like to make patternsearch optimize considering other values: n_1, n_19, n_27, n_29, n_47. These values should be larger than 30. Is there any way or idea to have additional constraints for patternsearch? Thank you so much in advance.
rand1 = rand(1)*1000; rand2 = rand(1)*1000; rand3 = rand(1); rand4 = rand(1)/100;
param0 = [round(max(rand1,rand2)), round(min(rand1,rand2)), round(rand3, 2), round(rand4, 5)];
options = optimoptions('patternsearch', 'PlotFcn', 'psplotbestx', 'MeshTolerance', 1, 'ScaleMesh', false, 'InitialMeshSize',10);
A = [];
b = [];
Aeq = [];
beq = [];
nlcon = [];
lb = [1 1 0.1 1/500000];
ub = [100000 100000 10 1/25000];
fun = @do;
[param, RSS, exitflag, ~] = patternsearch(fun, param0, A, b, Aeq, beq, lb, ub, nlcon, options);
function RSS = do(param)
load y_highpass_TK_short y_highpass_TK_short
n_1_groundtruth = 46;
n_19_groundtruth = 43;
n_27_groundtruth = 38;
n_29_groundtruth = 35;
n_47_groundtruth = 40;
T0 = param(1);
T1 = param(2);
T2 = param(3);
alpha = param(4);
[Vn_1, ~, loc_maxima_1, N_1] = doPagetest_loop(y_highpass_TK_short{1}, T0, T1, T2, alpha);
n_1 = length(Vn_1(loc_maxima_1==1));
[Vn_19, ~, loc_maxima_19, N_19] = doPagetest_loop(y_highpass_TK_short{2}, T0, T1, T2, alpha);
n_19 = length(Vn_19(loc_maxima_19==1));
[Vn_27, ~, loc_maxima_27, N_27] = doPagetest_loop(y_highpass_TK_short{3}, T0, T1, T2, alpha);
n_27 = length(Vn_27(loc_maxima_27==1));
[Vn_29, ~, loc_maxima_29, N_29] = doPagetest_loop(y_highpass_TK_short{4}, T0, T1, T2, alpha);
n_29 = length(Vn_29(loc_maxima_29==1));
[Vn_47, ~, loc_maxima_47, N_47] = doPagetest_loop(y_highpass_TK_short{5}, T0, T1, T2, alpha);
n_47 = length(Vn_47(loc_maxima_47==1));
RSS = sqrt((n_1-n_1_groundtruth)^2 + (n_19-n_19_groundtruth)^2 + (n_27-n_27_groundtruth)^2 ...
+ (n_29-n_29_groundtruth)^2 + (n_47-n_47_groundtruth)^2);

채택된 답변

Alan Weiss
Alan Weiss 2020년 6월 5일
Before I get to your specific question, allow me an observation: it is very inefficient to call a load statement in an objective function. I think that you will have much better luck passing in fixed data using a parameterization technique.
Now for your specific question. If you also want to optimize over the variables n_1, n_19, n_27, n_29, and n_47, then I suggest that you make these variables part of your optimization. Append them to your params vector as follows:
function RSS = do(params,extradata) % extradata are the values in y_highpass_TK_short y_highpass_TK_short
T0 = params(1);
T1 = params(2);
T2 = params(3);
alpha = params(4);
n_1 = params(5);
n_19 = params(6);
n_27 = params(7);
n_29 = params(8);
n_47 = params(9);
% Your code here
end
To keep params(5:9) above 30 during the optimization, set lower bounds:
lb = 30*ones(1,9);
lb(1:4) = [1 1 0.1 1/500000];
Extend the ub vector to be of length 9 as well.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 8
Alan Weiss
Alan Weiss 2020년 7월 2일
Your understanding is not quite right. Solvers attempt to find a feasible solution, not first a solution and then feasibility. In fact, you might want to check whether any feasible solution exists. Try the suggestions in Converged to an Infeasible Point.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
Kei Manabe
Kei Manabe 2020년 7월 3일
Thank you so much.
I am relieved to know the MATLAB optimization doesn't apply the nonlinear constraint after optimal answer is found.
I will try to understand more with the linked document.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by