opened
luyuechao
username_0
Hi, Thank you for your code

I made some improvement in calculating the Hessian matrix.
It will be much faster than forming the diagonal matrix.

Reference:
https://www.mathworks.com/matlabcentral/answers/87629-efficiently-multiplying-diagonal-and-general-matrices
performance improvement for Hessian matrix calculating
issue
created
luyuechao
username_0
Hi, I close this pull request because I  committed again and it may be confusing.

For forming Hessian: the following script compares execution time. Hope it may be helpful!

m = 65535;
n = 100;
M = rand(m,n);
J = zeros(n,n,m); % Preallocate J for n*n*m elements of storage
for k = 1:m
    J(:,:,k) = M(k,:)'*M(k,:);
end
J = reshape(J,n^2,m);

d = rand(m,1); %Generate a new d (only the diagonal entries)
tic; D = sparse(1:m,1:m,d); A = M'*D*M; toc; % Method 1, direct multiplication
tic; B = bsxfun(@times,M,sqrt(d)); B = B.'*B; toc; % Method 2, using BSXFUN
tic; C = reshape(J*d,n,n); toc; % <-- Method 3, precalculating matrices.
tic; B = bsxfun(@times, M,d); B = M.' * B; toc;
comment