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_shortn_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);
Best Answer