diff src/EM.cpp @ 97:840c0d703bbb timing

Use single-precision floats throughout EM code
author Chris Cannam
date Tue, 06 May 2014 14:45:16 +0100
parents a6e136aaa202
children
line wrap: on
line diff
--- a/src/EM.cpp	Tue May 06 13:05:43 2014 +0100
+++ b/src/EM.cpp	Tue May 06 14:45:16 2014 +0100
@@ -28,7 +28,7 @@
 using std::cerr;
 using std::endl;
 
-static double epsilon = 1e-16;
+static float epsilon = 1e-8;
 
 EM::EM() :
     m_noteCount(SILVET_TEMPLATE_NOTE_COUNT),
@@ -87,7 +87,7 @@
 void
 EM::normaliseColumn(V &column)
 {
-    double sum = 0.0;
+    float sum = 0.0;
     for (int i = 0; i < (int)column.size(); ++i) {
         sum += column[i];
     }
@@ -115,14 +115,15 @@
 }
 
 void
-EM::iterate(V column)
+EM::iterate(const vector<double> &column)
 {
-    normaliseColumn(column);
-    expectation(column);
-    maximisation(column);
+    V norm(column.begin(), column.end());
+    normaliseColumn(norm);
+    expectation(norm);
+    maximisation(norm);
 }
 
-const double *
+const float *
 EM::templateFor(int instrument, int note, int shift)
 {
     return silvet_templates[instrument].data[note] + shift;
@@ -139,12 +140,12 @@
 
     for (int i = 0; i < m_instrumentCount; ++i) {
         for (int n = 0; n < m_noteCount; ++n) {
-            const double pitch = m_pitches[n];
-            const double source = m_sources[i][n];
+            const float pitch = m_pitches[n];
+            const float source = m_sources[i][n];
             for (int f = 0; f < m_shiftCount; ++f) {
-                const double *w = templateFor(i, n, f);
-                const double shift = m_shifts[f][n];
-                const double factor = pitch * source * shift;
+                const float *w = templateFor(i, n, f);
+                const float shift = m_shifts[f][n];
+                const float factor = pitch * source * shift;
                 for (int j = 0; j < m_binCount; ++j) {
                     m_estimate[j] += w[j] * factor;
                 }
@@ -166,17 +167,17 @@
 
     for (int n = 0; n < m_noteCount; ++n) {
 
-        const double pitch = m_pitches[n];
+        const float pitch = m_pitches[n];
 
         for (int f = 0; f < m_shiftCount; ++f) {
 
-            const double shift = m_shifts[f][n];
+            const float shift = m_shifts[f][n];
 
             for (int i = 0; i < m_instrumentCount; ++i) {
 
-                const double source = m_sources[i][n];
-                const double factor = pitch * source * shift;
-                const double *w = templateFor(i, n, f);
+                const float source = m_sources[i][n];
+                const float factor = pitch * source * shift;
+                const float *w = templateFor(i, n, f);
 
                 if (n >= m_lowestPitch && n <= m_highestPitch) {