I'm trying to implement an EM algorithm for the following factor analysis model;
$$W_j = \mu+B a_j+e_j \quad\text{for}\quad j=1,\ldots,n$$
where $W_j$ is p-dimensional random vector, $a_j$ is a q-dimensional vector of latent variables and $B$ is a pxq matrix of parameters.
As a result of other assumptions used for the model, I know that $W_j\sim N(\mu, BB'+D)$ where $D$ is the variance covariance matrix of error terms $e_j$, $D$ = diag($\sigma_1^2$,$\sigma_2^2$,...,$\sigma_p^2$).
For the EM algorithm to work, I'm doing dome iterations involving estimation of $B$ and $D$ matrices and during these iterations I'm computing the inverse of $BB'+D$ at each iteration using new estimates of $B$ and $D$. Unfortunately during the course of iterations, $BB'+D$ loses its positive definiteness (but it shouldn't because it is a variance-covariance matrix) and this situation ruins the convergence of the algorithm. My questions are:
Does this situation show that there is something wrong with my algorithm since the likelihood should increase at every step of EM?
What are the practical ways to make a matrix positive definite?
Edit: I'm computing the inverse by using a matrix inversion lemma which states that:
$$(BB'+D)^{-1}=D^{-1}-D^{-1}B (I_q+B'D^{-1}B)^{-1} B'D^{-1}$$
where the right side involves only the inverses of $q\times q$ matrices.