vectorize mldivide
16 次查看(过去 30 天)
显示 更早的评论
Currently I'm using mldivide in the following way: A data vector and a number of model vectors which are added up to approximate the data. I want to determine the scaling factors (coefficients) of the model vectors to approximate the data (least squares...).
example: data [1024,1]; %1 data vector with 1024 elements models [1024,4]; %4 model vectors
coeff = models\data;
Now I want to run hundreds/thousands of those linear optimizations concurrently (even using an identical data vector but thats not so much the point). As mldivide doesn't support this I'm forced to run this in a loop. To use parfor doesn't get me any speedup (even takes 2x longer).
3 个评论
David Provencher
2011-12-9
Are the optimization problems completely different from one another (i.e. the data and model vectors change every time)? Or is the data vector the same?
回答(1 个)
Titus Edelhofer
2011-12-9
Hi,
there is probably not too much you can do (as long as the models differ from run to run). On the other hand:
x = rand(1024,4);
y = ones(1024, 1);
results = zeros(1000, 4);
tic,
for i=1:1000
results(i,:) = (x\y)';
end
time=toc
%
time =
0.1164
The loop shouldn't be all that bad for the size of your problem...?
Titus
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!