|
Hello everyone;
I have a for loop which performs the following portion of code:
%% a0 a1 and a2 are auxilary variables.
M=1e6;
colInner=sparse([1 a1/a0 a2/a0 zeros(1,M-2)]);
rowInner=sparse([1 zeros(1,M)]);
A=sptoeplitz(colInner,rowInner);
A=[sparse([1 0 a2/a0 zeros(1,M-1)]') [sparse(zeros(1,M+1)); A]];
x=[0; 0; x];
nApproximate=A\x;
L=A\sparse([eye(2);zeros(M,2)]);
nUnobservable=-(L'*L/a0^2)\(L'*nApproximate/a0^2);
loglikelihood= -(M/2) * log(2*pi) -((M+2)/2) * log(a0^2) -0.5*log(det(L'*L/a0^2)) ...
- 0.5*(nApproximate+L*nUnobservable)' * (nApproximate+L*nUnobservable)/a0^2;
A matrix has a certain structure which is as =[row1; [column1 innerToeplitz]];
A is also a sparse matrix. I use the sptoeplitz function for the construction of A: Link for that function is:
http://www.mathworks.com/matlabcentral/fileexchange/13353-sparse-toeplitz-matrix-construction
However, my code is too slow compared to my needs. Above code is processed in 1 minute approximately for one iteration. How can I speed up my operation? Is there any alternative function for sparse Toeplitz matrix construction which is the part taking the most.
|