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!