Skip to main content
4 of 4
added 34 characters in body
Michael Hardy
  • 1
  • 12
  • 85
  • 126

First compute a Cholesky factorization of the covariance matrix. Now your tentative new covariance matrix is a rank-2 update of the old, $$ M_\text{new}=M_\text{old}+\frac{1}{n} x_\text{new} x_\text{new}^T-\frac{1}{n} x_\text{old} x_\text{old}^T. $$ You can use Sylvester's formula here to compute the determinant of the update; for this you'll only need to solve a linear system, which is $O(n^2)$ using your Cholesky factorization.

Then when your "replacement" take place for real you just have to update the Cholesky factorization, and there are algorithms to do that (low-rank updates of Cholesky factorization) in $O(n^2)$ as well. Check Matlab's cholupdate for instance.

So you pay $O(n^3)$ at the first step and then $O(n^2)$ per step.

EDIT: better and clearer algorithm

Federico Poloni
  • 20.2k
  • 2
  • 82
  • 120