patternsea​rchにおいて、①メ​ッシュサイズを各パラ​メーター毎に設定する​方法、②コスト関数だ​けではなく途中の値も​用いて評価する方法

2 visualizaciones (últimos 30 días)
Kei Manabe
Kei Manabe el 2 de Jun. de 2020
pattersearchを使って、Page Testのパラメーター(4つ)を最適化しようとしています。
①メッシュサイズを各パラメーター毎に設定する方法
下記のparam0が初期値なのですが、桁が異なっている為、それぞれのパラメーター毎にメッシュサイズを指定したいです。
具体的には、一つ目は10、二つ目も10、三つ目は0.1、四つ目は0.001のメッシュサイズにしたいのですが、そういう指定は出来ますか?
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);
②コスト関数だけではなく途中の値も用いて評価する方法
下記の最終行でコスト関数としてRSSを計算していますが、これが最小になる四つのパラメーターの組合せを見つけるのが、patternsearchでやりたい事です。
ただし、n_1も、n_19も、n_27も、n_29も、n_47も30以上である必要があります。
しかし、Patternsearchでは、コスト関数を一つしか設定できない為、困っております。
何か良いアイディアございますでしょうか?
よろしくお願い致します。
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);
(参考)Page Testのアルゴリズム
function [Vn, ddd, loc_maxima, N] = doPagetest_loop(y, T0, T1, T2, alpha)
en = abs(hilbert(y));
Tx = T2;
Nn = mean(en.^2);
dd = 0*en;
Vn = 0*en;
for ii = 1 : length(dd)
Vn(ii) = en(ii)^2 / Nn;
if Vn(ii) > T0
Tx = T1;
dd(ii) = 1; % signal -> dd = 1
end
if Vn(ii) < Tx
Tx = T2;
Nn = Nn*(1-alpha) + en(ii)^2*alpha;
dd(ii) = -1; % noise -> dd = -1 (temporary)
end
% Nn_vector(ii) = Nn;
end
% For undecided data, if next data is signal, then current data is also signal.
for ii = length(dd)-1 : -1 : 1
if dd(ii) == 0 && dd(ii+1) > 0, dd(ii) = dd(ii+1); end
end
% For undecided data, if previous data is signal, then current data is also signal.
for ii = 2 : length(dd)
if dd(ii) == 0 && dd(ii-1) > 0, dd(ii) = dd(ii-1); end
end
% For all detected noise, dd is changed from -1 to 0.
for ii = 1 : length(dd)
if dd(ii) < 0, dd(ii) = 0; end
end
loc_maxima = 0*dd;
iiii = 1;
while iiii <= length(dd)
if dd(iiii) == 1
sig_start = iiii;
iii = iiii : length(dd);
sig_end = min(iii(dd(iii) == 0))-1;
iiii = sig_end+1;
[~, loc_maximum] = max(Vn(sig_start : sig_end));
loc_maxima(sig_start+loc_maximum-1) = 1;
end
iiii = iiii + 1;
end
ddd = loc_maxima .* Vn;
end

Respuestas (0)

Categorías

Más información sobre Direct Search en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!