I am looking to accelerate the computation of Input-Output Polynomial Models by using parfor.
48 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gabriel
el 18 de Nov. de 2024 a las 17:54
Comentada: Walter Roberson
el 19 de Nov. de 2024 a las 18:23
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 comentarios
Walter Roberson
el 19 de Nov. de 2024 a las 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.
Respuestas (0)
Ver también
Categorías
Más información sobre Polynomials en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!