vectorize mldivide
6 views (last 30 days)
Show older comments
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 Comments
David Provencher
on 9 Dec 2011
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?
Answers (1)
Titus Edelhofer
on 9 Dec 2011
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
See Also
Categories
Find more on Multicore Processor Targets 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!