I am looking to accelerate the computation of Input-Output Polynomial Models by using parfor.

48 visualizzazioni (ultimi 30 giorni)
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 Commenti
Walter Roberson
Walter Roberson il 19 Nov 2024 alle 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.

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Polynomials in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by