Imbedded regression use with GPUs

조회 수: 13 (최근 30일)
Mel
Mel 2012년 7월 8일
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

답변 (2개)

Edric Ellis
Edric Ellis 2012년 7월 9일
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 2012년 7월 8일
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
Walter Roberson
Walter Roberson 2012년 7월 8일
Does that work out the same? Isn't x'*x a correlation matrix?
Mel
Mel 2012년 7월 8일
Thanks, I'll give those a try. Still hoping to get some information on GPU use.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by