Imbedded regression use with GPUs

3 views (last 30 days)
Mel
Mel on 8 Jul 2012
I am trying to speed up a regression model that I have by using a GPU (I have a Tesla C2075). Does anyone have examples of ways to do this they are willing to share. The regression model (shown below) provides great results, but is very slow.
Thanks for any help you can provide,
Mel
%%Create a matrix of every possible combination of predictors
parfor r=n:n1
xind{r}=nchoosek(1:h,r);% Establishes the xindex for unique subsamples n-n1
end
parfor g=n:n1
xind2=xind{g}; % Opens X data sets for 'g' iterations from new sets
z=xind2(:,1); % Establishes one column of interation 'g' values
ind3=size(z); % Establises the index
ind3=ind3(:,1); % Calculates the number of rows in interation 'g'
for Z=1:ind3
x1=xind2(Z,:); % Starts the regression by selecting columns of 'X'
% by interations 1 through Z of choosen values
x2=X(:,x1); % Stores selected columns
p = g + 1; % Number of possible X variables plus 1 intercept
x = [ones(l,1) x2]; % Add ones for intercept to column
% Turn of the warning that individual regressions may be singular
warning off
beta = inv(x'*x)*x'*y; % Creates hat matrix for the coefficients
pred = x*beta; % Creates predicted value
ybar = mean(y)*ones(l,1); % Creates a column of the mean Y
ssreg = (pred-ybar)'*(pred-ybar); % Calculates the Regression Sum of Squares
sstot = (y-ybar)'*(y-ybar); % Calculates the Total Sum of Squares
sse = (pred-y)'*(pred-y); % Calculates thes the Sum of Squares Error
r2 = ssreg/sstot; % Calculates the R square
adjr2 = 1 - ((1-r2)*((l-1)/(l-p-1)));% Calculates the Adjusted R squares
aic = 2*g + h*[log(sse/h)]; % Calculates Akaike's information criterion for each run.
R(g).size=g; % Stores the size (number) of predictors for each
% regression in cell array R
R(g).adjr2(Z,1)=adjr2; % Stores the calculated adjr2 for each
% regression in cell array R
end
end

Answers (2)

Edric Ellis
Edric Ellis on 9 Jul 2012
Whether or not you will get much benefit from using GPUArrays depends quite a bit on where the majority of the time is spent in your program, and the size of your data. For example, MATLAB's \ operator runs well on the GPU, see for example this demo.

bym
bym on 8 Jul 2012
Pre-allocation of variables in for loop will speed things up. Also, use
beta = x\y;
instead of
beta = inv(x'*x)*x'*y;
  2 Comments
Walter Roberson
Walter Roberson on 8 Jul 2012
Does that work out the same? Isn't x'*x a correlation matrix?
Mel
Mel on 8 Jul 2012
Thanks, I'll give those a try. Still hoping to get some information on GPU use.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!