I have this complicated MATLAB expression that I would like to simplify, so that I can actually understand it.
g = repmat(log(p), [size(x, 1), 1])
for i = 1:size(mu, 1)
g(:, i) = g(:, i) - sum(log(sigma(i, :)));
g(:, i) = g(:, i) - sum(bsxfun(@rdivide, bsxfun(@minus, x, mu(i, :)).^2, 2*sigma(i, :).^2), 2);
end
p=1x2
sigma=2x2
mu=2x2
x=30x2
Basically these bsxfun
functions confuse me a lot. I would like to express it in the form of simple for
loops.
I tried something like this:
[m,n] = size(x)
for i=1:m
for j=1:n
g(i,j)= log(p(j)) - sum(log(sigma(j))) - sum(data(i,j))... ;
end
end
Not quite sure how to continue from this point, mostly errors and wrong results!