Error using parfor: cannot use parfor because of the way Theta/nk is used

1 view (last 30 days)
Hello everyone, I am using a very old version of Xeon PC to run a gaussian mixture model using Dirichlet process and Gibb's sampling on a Big Data. I hoped I could speed it up using parfor commands but was unable to do it becuase of the error!!
n = size(X,2);
Theta = {};
nk = [];
label = zeros(1,n);
llh = 0;
for i = randperm(n)
x = X(:,i);
Pk = log(nk)+cellfun(@(t) t.logPredPdf(x), Theta);
P0 = log(alpha)+theta.logPredPdf(x);
p = [Pk,P0];
llh = llh+sum(p-log(n));
k = discreteRnd(exp(p-logsumexp(p)));
if k == numel(Theta)+1
Theta{k} = theta.clone().addSample(x);
nk = [nk,1];
else
Theta{k} = Theta{k}.addSample(x);
nk(k) = nk(k)+1;
end
label(i) = k;
end
w = nk/n;
Please note that the first function I used above provided faster results so, I am not worried about it very much.
Thanks and Regards in advance.

Answers (0)

Categories

Find more on Startup and Shutdown 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!