2017-01-21 8 views
0

は、私たちは私たちがBIC基準を使用して最良のARIMAモデルを選択したコードを、次のようしていると仮定しましょう最適化コード、それはすぐに実行されるように

function [AR_order,MA_order]= complete_arima(Y) 
%% if not specific input from user, use default time series 
if nargin<1 
    Y=xlsread('ARIMA','ARIMA','d6:d468'); 
end 
% Y is the observed time series 
%% graphical representation of time series 
subplot(3,1,1); 
plot(Y); 
title('original time series'); 
%%autocorrelation/partial autocorrelation of given signal 
subplot(3,1,2); 
autocorr(Y); 
subplot(3,1,3); 
parcorr(Y); 
hold off 
%% entering necessary parameters for Arima Testing 
d=input('enter necessary order of differencing  : '); 
M=input('maximum order of lag for ARMA simulation : '); 
%% simulate ARIMA model on the base of given input 
LOGL = zeros(M,M); %Initialize 
PQ = zeros(M,M); 
for p = 1:M 
    for q = 1:M 
     mod = arima(p,d,q);% for each pair generate new ARIMA model 
     [~,~,logL] = estimate(mod,Y,'print',false); 
     LOGL(p,q) = logL; 
     PQ(p,q) = p+q; 
    end 
end 
%% calculate BIC 
LOGL = reshape(LOGL,M*M,1); 
PQ = reshape(PQ,M*M,1); 
[~,bic] = aicbic(LOGL,PQ+1,100); 
bic=reshape(bic,M,M); 
%% determine order of ARIMA by finding minimum element from matrix bic and corresponding indeces 
[AR_order,MA_order]=find(bic==min(min(bic))); 
end 

その実行時間は私がスピードアップすることができますどのように

>> tic 
>> [AR_order,MA_order]=complete_arima(); 
enter necessary order of differencing  : 1 
maximum order of lag for ARMA simulation : 4 
>> toc 
Elapsed time is 36.499133 seconds. 

です与えられたコード?私はparforを使って1つのループを実行する必要がありますか?

並列実行のための最初の私が作成したパラレルプール

parpool('local',4) 
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers. 

ans = 

Pool with properties: 

      Connected: true 
      NumWorkers: 4 
       Cluster: local 
     AttachedFiles: {} 
      IdleTimeout: 30 minute(s) (30 minutes remaining) 
      SpmdEnabled: true 
>> [AR_order,MA_order]=complete_arima(); 
enter necessary order of differencing  : 1 
maximum order of lag for ARMA simulation : 4 
>> toc 
Elapsed time is 24.983676 seconds. 

、私は

function [AR_order,MA_order]= complete_arima(Y) 
%% if not specific input from user, use default time series 
if nargin<1 
    Y=xlsread('ARIMA','ARIMA','d6:d468'); 
end 
% Y is the observed time series 
%% graphical representation of time series 
subplot(3,1,1); 
plot(Y); 
title('original time series'); 
%%autocorrelation/partial autocorrelation of given signal 
subplot(3,1,2); 
autocorr(Y); 
subplot(3,1,3); 
parcorr(Y); 
hold off 
%% entering necessary parameters for Arima Testing 
d=input('enter necessary order of differencing  : '); 
M=input('maximum order of lag for ARMA simulation : '); 
%% simulate ARIMA model on the base of given input 
LOGL = zeros(M,M); %Initialize 
PQ = zeros(M,M); 
parfor p = 1:M 
    for q = 1:M 
     mod = arima(p,d,q);% for each pair generate new ARIMA model 
     [~,~,logL] = estimate(mod,Y,'print',false); 
     LOGL(p,q) = logL; 
     PQ(p,q) = p+q; 
    end 
end 
%% calculate BIC 
LOGL = reshape(LOGL,M*M,1); 
PQ = reshape(PQ,M*M,1); 
[~,bic] = aicbic(LOGL,PQ+1,100); 
bic=reshape(bic,M,M); 
%% determine order of ARIMA by finding minimum element from matrix bic and corresponding indeces 
[AR_order,MA_order]=find(bic==min(min(bic))); 
end 

がどのように私はより多くをスピードアップすることができます次のコードを使用?私はベクトル化することができ、コード内の任意の行がありますか?ありがとうございます。

答えて

0

ここに私は120秒間続く別の解決策を投稿します

function [AR_order,MA_order]= complete_arima(Y) 
%% created parallel loop 
parpool('local',4); 
tic; 
%% if not specific input from user, use default time series 

if nargin<1 
    Y=xlsread('ARIMA','ARIMA','d6:d468'); 
end 
% Y is the observed time series 
%% graphical representation of time series 
subplot(3,1,1); 
plot(Y); 
title('original time series'); 
%%autocorrelation/partial autocorrelation of given signal 
subplot(3,1,2); 
autocorr(Y); 
subplot(3,1,3); 
parcorr(Y); 
hold off 
%% entering necessary parameters for Arima Testing 
d=input('enter necessary order of differencing  : '); 
M=input('maximum order of lag for ARMA simulation : '); 
%% simulate ARIMA model on the base of given input 
LOGL = zeros(M,M); %Initialize 
PQ = zeros(M,M); 
parfor p = 1:M 
    for q = 1:M 
     mod = arima(p,d,q);% for each pair generate new ARIMA model 
     [~,~,logL] = estimate(mod,Y,'print',false); 
     LOGL(p,q) = logL; 
     PQ(p,q) = p+q; 
    end 
end 
%% calculate BIC 
LOGL = reshape(LOGL,M*M,1); 
PQ = reshape(PQ,M*M,1); 
[~,bic] = aicbic(LOGL,PQ+1,100); 
bic=reshape(bic,M,M); 
%% determine order of ARIMA by finding minimum element from matrix bic and corresponding indeces 
[AR_order,MA_order]=find(bic==min(min(bic))); 
toc 
delete(gcp('nocreate')); 
end 

>> [AR_order,MA_order]=complete_arima(); 
Starting parallel pool (parpool) using the 'local' profile ... connected to 4 workers. 
enter necessary order of differencing  : 1 
maximum order of lag for ARMA simulation : 10 
Elapsed time is 120.370494 seconds. 
Parallel pool using the 'local' profile is shutting down. 
>> 

この問題を解決するにはどうすればよいですか?

関連する問題