Clear Filters
Clear Filters

How can I speed up spliting a matrix into submatricies?

1 view (last 30 days)
I am working on a back propagation assignment and am running into high epoch times for large training samples. I think that how I am storing and accessing the weight and bias matricies is one of the leading causes.
For storing the overall weights during training, I have two matricies of doubles whose size is dependent on the network specs. For the current configuration, the weight matrix is 400x1184 entries and the bias matrix is 400x2 entries. These matricies consist, each, of two smaller matricies, [w1,w2], [b1,b2], with the unused space filled with zeros (since size(w1) ~= size(w2)).
During training, I extract the individual weight matricies from the newly calculated wC and wB matricies via
w = wC(1:rows,offset+1:cols+offset);
b = bC(1:rows,i);
where wC,wB are the composite matricies and rows, cols, offset are variables that define the current size and position of the submatricies within wC and bC. This operation occurs twice per training sample for this network, once for w1 and once for w2. Each time an output matrix is calculated from w and b, but w and b is not directly calculated upon. The operation above takes just about 0.0009s to complete.
My problem is what happens to the execution time when I have 60,000 training samples, when the time component of that operation swells to over 54 seconds. I drastically need to reduce this.
Is there a more time efficent way to split or index these matricies so as to reduce cycle time?
Note that I cannot use existing machine learning libraries on this assignment.
Thanks
  5 Comments
J Krause
J Krause on 28 Oct 2020
Is there a fast function that can split a matrix according to an array of indices? Split a 4,6 and a 2,2 matrix from a 4,8 matrix, for example.
If not, then I would need to extract the matricies in a loop with repeated calls to the composite matrix, or essentially the same thing as I am doing now.
Which brings me to a followup question: Would a cell array of matricies be faster from an indexing perspective than splitting arrays?
Walter Roberson
Walter Roberson on 28 Oct 2020
No there is no routine to do fast splitting. mat2cell and num2cell just loop.

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!