Augmented Dickey-Fuller test for GPU computing

2 views (last 30 days)
I am new to matlab and I tried to re-program the following code to run fast on a GPU. Technically the codes runs on a GPU but it is app. 100x slower than the Augmented Dickey-Fuller test given in the matlab Toolbox (the Toolbox code only runs on a CPU, the 100x is assuming that both Hardware powers are equal).
Question: Is there a specific trick which I am not Aware of to make the code faster?
if true
% code
dx = randn(100000,2);
a = cumsum(dx);
y = a(:,1);
x = a(:,2);
p = 0
l = 0
y = gpuArray(double(y));
x = gpuArray(double(x));
tic;
for lp = 1:1000 % Loop 1000 times to test Speed of calcullation
% error checking
if (p < -1);
error('p cannot be < -1 in cadf');
end;
nobs = rows(x);
if (nobs - (2*l) + 1 < 1);
error('nlags is too large in cadf; negative degrees of freedom');
end;
classUnderlying(x);
classUnderlying(y);
y = detrend(y,p);
x = detrend(x,p);
b = inv(x'*x)*x'*y;
r = y - x*b;
%gpuArray(r)
dep = tdiff(r,1);
dep = trimr(dep,1,0);
k = 0;
z = trimr(lag(r,1),1,0) ;
k = k + 1 ;
while (k <= l)
z = [z lag(dep,k)];
k = k + 1 ;
end;
z = trimr(z,l,0) ;
dep = trimr(dep,l,0) ;
beta = detrend(z,0)\detrend(dep,0) ;
% res = dep - z*beta ;
% BUG fix suggested by
% Nick Firoozye
% Sanford C. Bernstein, Inc
% 767 Fifth Avenue, #21-49
% New York, NY 10153
res = detrend(dep,0)- detrend(z,0)*beta;
so = (res'*res)/(rows(dep)-cols(z));
var_cov = so*inv(z'*z) ;
% results.alpha = beta(1,1);
results.adf = beta(1,1)/sqrt(var_cov(1,1));
results.crit = rztcrit(nobs,cols(x),p);
results.nlag = l;
results.nvar = cols(x);
% results.meth = 'cadf';
results.final = (results.crit(1) > results.adf)
end
toc
% References: Said and Dickey (1984) 'Testing for Unit Roots in
% Autoregressive Moving Average Models of Unknown Order',
% Biometrika, Volume 71, pp. 599-607.
% written by:
% James P. LeSage, Dept of Economics
% University of Toledo
end

Answers (0)

Categories

Find more on Chemistry in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!