Reputation: 331
I am running a speech enhancement algorithm based on Gaussian Mixture Model. The problem is that the estimation algorithm underflows during the training processing.
I am trying to calculate the PDF of a log spectrum frame X
given a Gaussian cluster which is a product of the PDF of each frequnecy component X_k
(fft is done for k=1..256)
what i get is a product of 256 exp(-v(k))
such that v(k)>=0
Here is a snippet of the MATLAB calculation:
N
- number of frames; M
- number of mixtures; c_i
weight for each mixture;
gamma(n,i) = c_i*f(X_n|I = i)
for i=1 : N
rep_DataMat(:,:,i) = repmat(DataMat(:,i),1,M);
gamma_exp(:,:) = (1./sqrt((2*pi*sigmaSqr_curr))).*exp(((-1)*((rep_DataMat(:,:,i) - mue_curr).^2)./(2*sigmaSqr_curr)));
gamma_curr(i,:) = c_curr.*(prod(10*gamma_exp(:,:),1));
alpha_curr(i,:) = gamma_curr(i,:)./sum(gamma_curr(i,:));
end
The product goes quickly to zero due to K = 256 since the numbers being smaller then one. Is there a way I can calculate this with causing an underflow (like logsum or similar)?
Upvotes: 2
Views: 496
Reputation: 14579
You can perform the computations in the log domain.
The conversion of products into sums is straightforward. Sums on the other hand can be converted with something such as logsumexp. This works using the formula:
log(a + b) = log(exp(log(a)) + exp(log(b)))
= log(exp(loga) + exp(logb))
Where loga
and logb
are the respective representation of a
and b
in the log domain.
The basic idea is then to factorize the exponent with the largest argument (eg. loga
for sake of illustration):
log(exp(loga)+exp(logb)) = log(exp(loga)*(1+exp(logb-loga)))
= loga + log(1+exp(logb-loga))
Note that the same idea applies if you have more than 2 terms to add.
Upvotes: 1