필터 지우기
필터 지우기

Sparse Matrices and Machine Precision

조회 수: 4 (최근 30일)
Superfish
Superfish 2012년 1월 6일
I have a large sparse matrix, K. My problem is that over time some values in K that where once non-zero will change to zero through some matrix calculations. However, due to floating point precision inaccuracies the values don't reach exactly zero. Thus Matlab allows these near zero values to be represented as non-zero values.
Currently my solution is
K(abs(K)<threshold) = 0;
where threshold is some small value. This does help, however this operation is slow and as K is changed by matrix operations often, it needs to be re-run often.
Is there a way to force sparse matrices to see values smaller than a certain threshold as zero? Or is there another solution?
Thanks

채택된 답변

John D'Errico
John D'Errico 2012년 1월 6일
There is no way to do so in the existing sparse form, and you would not want that behavior to exist in many linear algebra operations. As linear algebra goes, it is a rather nonlinear thing.
You can always just store the non-zero elements separately, implicitly building your own sparse form.

추가 답변 (1개)

James Tursa
James Tursa 2012년 1월 6일
If you are really desperate for speed one could write a mex routine to do this operation in-place. My guess is it probably wouldn't take too much time ... but that is just a guess. You would have to manually call this function, however. As John noted, you cannot make MATLAB automatically do this for all of your linear algebra calculations.
  댓글 수: 2
Superfish
Superfish 2012년 1월 6일
Do you mean write a C or fortran file to do the matrix adjusting calculations, and perform a zero threshold check when writing the value?
I think it would be slow as I doubt i'd be able to beat MATLABs optimizations on matrix multiplication.
James Tursa
James Tursa 2012년 1월 7일
No. I mean have MATLAB do the matrix multiplication, but after the fact have a mex routine clean it of small values in-place.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by