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
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 CenterFile Exchange 中查找有关 Polynomials 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by