Mercurial > hg > aimc
diff src/Modules/Features/ModuleGaussians.cc @ 8:fcbf85ce59fb
- Lots of changes to make cpplint happy. It still complains about header guards, but that's pretty much it now.
author | tomwalters |
---|---|
date | Thu, 18 Feb 2010 21:12:41 +0000 |
parents | 8c859ef1fb75 |
children | fff25824d1d1 |
line wrap: on
line diff
--- a/src/Modules/Features/ModuleGaussians.cc Thu Feb 18 20:04:04 2010 +0000 +++ b/src/Modules/Features/ModuleGaussians.cc Thu Feb 18 21:12:41 2010 +0000 @@ -96,15 +96,15 @@ ++iSample) { m_pSpectralProfile[iChannel] += input[iChannel][iSample]; } - m_pSpectralProfile[iChannel] /= static_cast<double>(input.buffer_length()); + m_pSpectralProfile[iChannel] /= static_cast<float>(input.buffer_length()); } - double spectral_profile_sum = 0.0f; + float spectral_profile_sum = 0.0f; for (int i = 0; i < input.channel_count(); ++i) { spectral_profile_sum += m_pSpectralProfile[i]; } - double logsum = log(spectral_profile_sum); + float logsum = log(spectral_profile_sum); if (!isinf(logsum)) { output_.set_sample(m_iParamNComp - 1, 0, logsum); } else { @@ -119,33 +119,34 @@ RubberGMMCore(2, true); - double fMean1 = m_pMu[0]; - double fMean2 = m_pMu[1]; - //LOG_INFO(_T("Orig. mean 0 = %f"), m_pMu[0]); - //LOG_INFO(_T("Orig. mean 1 = %f"), m_pMu[1]); - //LOG_INFO(_T("Orig. prob 0 = %f"), m_pA[0]); - //LOG_INFO(_T("Orig. prob 1 = %f"), m_pA[1]); + float fMean1 = m_pMu[0]; + float fMean2 = m_pMu[1]; + // LOG_INFO(_T("Orig. mean 0 = %f"), m_pMu[0]); + // LOG_INFO(_T("Orig. mean 1 = %f"), m_pMu[1]); + // LOG_INFO(_T("Orig. prob 0 = %f"), m_pA[0]); + // LOG_INFO(_T("Orig. prob 1 = %f"), m_pA[1]); - double fA1 = 0.05 * m_pA[0]; - double fA2 = 1.0 - 0.25 * m_pA[1]; + float fA1 = 0.05 * m_pA[0]; + float fA2 = 1.0 - 0.25 * m_pA[1]; - //LOG_INFO(_T("fA1 = %f"), fA1); - //LOG_INFO(_T("fA2 = %f"), fA2); + // LOG_INFO(_T("fA1 = %f"), fA1); + // LOG_INFO(_T("fA2 = %f"), fA2); - double fGradient = (fMean2 - fMean1) / (fA2 - fA1); - double fIntercept = fMean2 - fGradient * fA2; + float fGradient = (fMean2 - fMean1) / (fA2 - fA1); + float fIntercept = fMean2 - fGradient * fA2; - //LOG_INFO(_T("fGradient = %f"), fGradient); - //LOG_INFO(_T("fIntercept = %f"), fIntercept); + // LOG_INFO(_T("fGradient = %f"), fGradient); + // LOG_INFO(_T("fIntercept = %f"), fIntercept); for (int i = 0; i < m_iParamNComp; ++i) { - m_pMu[i] = ((double)i / ((double)m_iParamNComp - 1.0f)) - * fGradient + fIntercept; - //LOG_INFO(_T("mean %d = %f"), i, m_pMu[i]); + m_pMu[i] = (static_cast<float>(i) + / (static_cast<float>(m_iParamNComp) - 1.0f)) + * fGradient + fIntercept; + // LOG_INFO(_T("mean %d = %f"), i, m_pMu[i]); } for (int i = 0; i < m_iParamNComp; ++i) { - m_pA[i] = 1.0f / (double)m_iParamNComp; + m_pA[i] = 1.0f / static_cast<float>(m_iParamNComp); } RubberGMMCore(m_iParamNComp, false); @@ -165,7 +166,7 @@ int iSizeX = m_iNumChannels; // Normalise the spectral profile - double fSpectralProfileTotal = 0.0f; + float fSpectralProfileTotal = 0.0f; for (int iCount = 0; iCount < iSizeX; iCount++) { fSpectralProfileTotal += m_pSpectralProfile[iCount]; } @@ -175,18 +176,18 @@ if (bDoInit) { // Uniformly spaced components - double dd = (iSizeX - 1.0f) / iNComponents; + float dd = (iSizeX - 1.0f) / iNComponents; for (int i = 0; i < iNComponents; i++) { m_pMu[i] = dd / 2.0f + (i * dd); m_pA[i] = 1.0f / iNComponents; } } - vector<double> pA_old; + vector<float> pA_old; pA_old.resize(iNComponents); - vector<double> pP_mod_X; + vector<float> pP_mod_X; pP_mod_X.resize(iSizeX); - vector<double> pP_comp; + vector<float> pP_comp; pP_comp.resize(iSizeX * iNComponents); for (int iIteration = 0; iIteration < m_iParamMaxIt; iIteration++) { @@ -199,8 +200,9 @@ for (int i = 0; i < iNComponents; i++) { for (int iCount = 0; iCount < iSizeX; iCount++) { pP_mod_X[iCount] += 1.0f / sqrt(2.0f * M_PI * m_fParamVar) - * exp((-0.5f) * pow(((double)(iCount + 1)-m_pMu[i]), 2) - / m_fParamVar) * m_pA[i]; + * exp((-0.5f) + * pow(static_cast<float>(iCount+1) - m_pMu[i], 2) + / m_fParamVar) * m_pA[i]; } } @@ -212,17 +214,18 @@ for (int iCount = 0; iCount < iSizeX; iCount++) { pP_comp[iCount + i * iSizeX] = 1.0f / sqrt(2.0f * M_PI * m_fParamVar) - * exp((-0.5f) * pow(((double)(iCount + 1) - m_pMu[i]), 2) / m_fParamVar); + * exp((-0.5f) * pow((static_cast<float>(iCount + 1) - m_pMu[i]), 2) + / m_fParamVar); pP_comp[iCount + i * iSizeX] = pP_comp[iCount + i * iSizeX] * m_pA[i] / pP_mod_X[iCount]; } } for (int iCount = 0; iCount < iSizeX; ++iCount) { - double fSum = 0.0f; + float fSum = 0.0f; for (int i = 0; i < iNComponents; ++i) { pP_comp[iCount+i*iSizeX] = pow(pP_comp[iCount + i * iSizeX], - m_fParamPosteriorExp); // expansion + m_fParamPosteriorExp); // expansion fSum += pP_comp[iCount+i*iSizeX]; } for (int i = 0; i < iNComponents; ++i) @@ -239,27 +242,28 @@ } // finish when already converged - double fPrdist = 0.0f; + float fPrdist = 0.0f; for (int i = 0; i < iNComponents; ++i) { fPrdist += pow((m_pA[i] - pA_old[i]), 2); } fPrdist /= iNComponents; if (fPrdist < m_fParamPriorsConverged) { - //LOG_INFO("Converged!"); + // LOG_INFO("Converged!"); break; } - //LOG_INFO("Didn't converge!"); + // LOG_INFO("Didn't converge!"); // update means (positions) for (int i = 0 ; i < iNComponents; ++i) { - double mu_old = m_pMu[i]; + float mu_old = m_pMu[i]; if (m_pA[i] > 0.0f) { m_pMu[i] = 0.0f; for (int iCount = 0; iCount < iSizeX; ++iCount) { m_pMu[i] += m_pSpectralProfile[iCount] - * pP_comp[iCount + i * iSizeX] * (double)(iCount + 1); + * pP_comp[iCount + i * iSizeX] + * static_cast<float>(iCount + 1); } m_pMu[i] /= m_pA[i]; if (isnan(m_pMu[i])) { @@ -267,7 +271,7 @@ } } } - } // loop over iterations + } // loop over iterations // Ensure they are sorted, using a really simple bubblesort bool bSorted = false; @@ -275,7 +279,7 @@ bSorted = true; for (int i = 0; i < iNComponents - 1; ++i) { if (m_pMu[i] > m_pMu[i + 1]) { - double fTemp = m_pMu[i]; + float fTemp = m_pMu[i]; m_pMu[i] = m_pMu[i + 1]; m_pMu[i + 1] = fTemp; fTemp = m_pA[i]; @@ -287,5 +291,5 @@ } return true; } -} //namespace aimc +} // namespace aimc