Imbedded regression use with GPUs

2 次查看(过去 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 中查找有关 Electrophysiology 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by