Vectorize Bayesian linear regression function.

I am trying to vectorize the estimate function in MATLAB to speed up my code. I have tried with cellfun and arrayfun, but I get errors in both of them mainly because I am not sure how to use them. This is my code:
clear
vocab_length = 36915;
totalsize = 100;
matrix1 = rand ( vocab_length , totalsize );
num_iterations = 10;
filename= _path_here_;
raw_matrix=dlmread(filename, ' ');
PriorMdl = bayeslm(totalsize,'ModelType','conjugate','Intercept',false);
est_vector = rand ( totalsize , vocab_length );
counter = 1:length(raw_matrix);
for iterations = 1:num_iterations %numberof iterations for the model
[~, est_vector(:, raw_matrix(counter,2) + 1)] = estimate ( PriorMdl , matrix1(raw_matrix(counter,1) + 1,:) , log ( raw_matrix ( counter , 3 ) + 1 ), 'Display', false);
end
The value counter can have more than 200 million records, and I want to speed up my code by using vectorization. The problem with the above code is that I am getting the following error:
Assignment has fewer non-singleton rhs dimensions than non-singleton subscripts
The 200 million record file looks like this:
1 2 50
2 3 12
5 7 1
I am using MATLAB 2017a. The idea of the above code is to run the estimate function 200 million times, for instance, and store the vector values beta of co-efficients in a matrix est_vector for each run.

Answers (0)

Asked:

on 9 Apr 2018

Edited:

on 9 Apr 2018

Community Treasure Hunt

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

Start Hunting!