I am looking to accelerate the computation of Input-Output Polynomial Models by using parfor.
조회 수: 48 (최근 30일)
이전 댓글 표시
I have a function that uses a for loop, but it takes a lot of time to complete the model identification.
function [Idt_OE] = ident_oe(tt,nk)
Idt_OE=[];
count = 4^6;
for k = 1:count
[nb1, nb2, nb3, nf1, nf2, nf3] = ind2sub([4, 4, 4, 4, 4, 4], k);
Model_OE = oe(tt, [[nb1 nb2 nb3] [nf1 nf2 nf3] [nk nk nk]]);
[a,b] = compare(tt,Model_OE);
Idt_OE = [Idt_OE; b, nb1, nb2, nb3, nf1, nf2, nf3];
end
Idt_OE = sortrows(Idt_OE, 1);
end
And I tried using the code below, but something is wrong because the fit is not calculated very well.
function [Idt_OE] = ident_oe(tt, nk)
Idt_OE = [];
count = 4^6;
Idt_OE_par = cell(count, 1);
parfor k = 1:count
[nb1, nb2, nb3, nf1, nf2, nf3] = ind2sub([2, 2, 2, 2, 2, 2], k);
try
Model_OE = oe(tt, [[nb1 nb2 nb3] [nf1 nf2 nf3] [nk nk nk]]);
[~, fit] = compare(tt, Model_OE);
Idt_OE_par = [fit, nb1, nb2, nb3, nf1, nf2, nf3];
catch
Idt_OE_par{k} = [-Inf, nb1, nb2, nb3, nf1, nf2, nf3];
end
end
Idt_OE = cell2mat(Idt_OE_par);
Idt_OE = sortrows(Idt_OE, 1, 'descend');
end
Many thanks,
댓글 수: 12
Walter Roberson
2024년 11월 19일 18:23
It is a mystery to me how parfor could be returning different values in that situation.
Hmmm... as an experiment try
Idt_OE_nonpar = cell(2,1);
k = 1;
[nb1, nb2, nb3, nf1, nf2, nf3] = ind2sub([2, 2, 2, 2, 2, 2], k);
try
rng(655321);
Model_OE = oe(tt, [[nb1 nb2 nb3] [nf1 nf2 nf3] [nk nk nk]]);
[~, fit] = compare(tt, Model_OE);
Idt_OE_nonpar{k} = [fit, nb1, nb2, nb3, nf1, nf2, nf3];
catch
Idt_OE_nonpar{k} = [-Inf, nb1, nb2, nb3, nf1, nf2, nf3];
end
try
rng(655321);
Model_OE = oe(tt, [[nb1 nb2 nb3] [nf1 nf2 nf3] [nk nk nk]]);
[~, fit] = compare(tt, Model_OE);
Idt_OE_nonpar{k+1} = [fit, nb1, nb2, nb3, nf1, nf2, nf3];
catch
Idt_OE_nonpar{k+1} = [-Inf, nb1, nb2, nb3, nf1, nf2, nf3];
end
This should return identical results.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!