changeset 53:331a17753663 refactors

If the distance metric is a float, the total path cost should be a double (otherwise discriminatory precision is lost as the overall total accumulates)
author Chris Cannam
date Fri, 14 Nov 2014 10:09:10 +0000
parents 8cbc15519d2c
children 30567d4fb83a 506f0d9880db
files src/Finder.cpp src/Finder.h src/Matcher.cpp src/Matcher.h
diffstat 4 files changed, 27 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/Finder.cpp	Fri Nov 14 09:45:56 2014 +0000
+++ b/src/Finder.cpp	Fri Nov 14 10:09:10 2014 +0000
@@ -72,14 +72,14 @@
 Matcher::Advance
 Finder::getExpandDirection(int row, int col, bool check)
 {
-    float min = getPathCost(row, col);
+    double min = getPathCost(row, col);
     bestRow = row;
     bestCol = col;
     getRowRange(col, rowRange);
     if (rowRange[1] > row+1)
         rowRange[1] = row+1;	// don't cheat by looking at future :)
     for (int index = rowRange[0]; index < rowRange[1]; index++) {
-        float tmp = getPathCost(index, col);
+        double tmp = getPathCost(index, col);
         if (tmp < min) {
             min = tmp;
             bestRow = index;
@@ -89,7 +89,7 @@
     if (colRange[1] > col+1)
         colRange[1] = col+1;	// don't cheat by looking at future :)
     for (int index = colRange[0]; index < colRange[1]; index++) {
-        float tmp = getPathCost(row, index);
+        double tmp = getPathCost(row, index);
         if (tmp < min) {
             min = tmp;
             bestCol = index;
@@ -142,7 +142,7 @@
     throw "setDistance index out of bounds";
 } // setDistance()
 
-float
+double
 Finder::getPathCost(int row, int col)
 {
     if (find(row, col)) // "1" avoids div by 0 below
@@ -151,7 +151,7 @@
     throw "getPathCost index out of bounds";
 } // getPathCost()
 	
-float
+double
 Finder::getRawPathCost(int row, int col)
 {
     if (find(row, col))
@@ -161,7 +161,7 @@
 } // getRawPathCost()
 
 void
-Finder::setPathCost(int row, int col, float cost)
+Finder::setPathCost(int row, int col, double cost)
 {
     if (find(row, col)) {
          pm1->m_bestPathCost[row][col - pm1->m_first[row]] = cost;
@@ -195,14 +195,14 @@
     pm1->m_distance[index1][index2] = b;
 } // setDistance()
 
-float
+double
 Finder::getPathCost()
 {
     return pm1->m_bestPathCost[index1][index2];
 } // getPathCost()
 
 void
-Finder::setPathCost(float cost)
+Finder::setPathCost(double cost)
 {
     pm1->m_bestPathCost[index1][index2] = cost;
 } // setPathCost()
@@ -226,7 +226,7 @@
                 float newCost = pm1->m_distance[r][i2];
                 Matcher::Advance dir = Matcher::AdvanceNone;
                 if (r > r1) {	// not first row
-                    float min = -1;
+                    double min = -1;
                     if ((c > prevRowStart) && (c <= prevRowStop)) {
                         // diagonal from (r-1,c-1)
                         min = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]-1] +
@@ -235,7 +235,7 @@
                     }
                     if ((c >= prevRowStart) && (c < prevRowStop)) {
                         // vertical from (r-1,c)
-                        float cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] +
+                        double cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] +
                             newCost;
                         if ((min == -1) || (cost < min)) {
                             min = cost;
@@ -244,7 +244,7 @@
                     }
                     if (c > thisRowStart) {
                         // horizontal from (r,c-1)
-                        float cost =pm1->m_bestPathCost[r][i2-1]+newCost;
+                        double cost =pm1->m_bestPathCost[r][i2-1]+newCost;
                         if ((min == -1) || (cost < min)) {
                             min = cost;
                             dir = Matcher::AdvanceOther;
--- a/src/Finder.h	Fri Nov 14 09:45:56 2014 +0000
+++ b/src/Finder.h	Fri Nov 14 10:09:10 2014 +0000
@@ -63,9 +63,9 @@
     float getDistance(int row, int col);
     void setDistance(int row, int col, float b);
 
-    float getPathCost(int row, int col);
-    float getRawPathCost(int row, int col); //!!!???
-    void setPathCost(int row, int col, float i);
+    double getPathCost(int row, int col);
+    double getRawPathCost(int row, int col); //!!!???
+    void setPathCost(int row, int col, double i);
 
     Matcher::Advance getAdvance();
     void setAdvance(Matcher::Advance a);
@@ -73,8 +73,8 @@
     float getDistance();
     void setDistance(float b);
 
-    float getPathCost();
-    void setPathCost(float i);
+    double getPathCost();
+    void setPathCost(double i);
 
     /** Calculates a rectangle of the path cost matrix so that the
      *  minimum cost path between the bottom left and top right
--- a/src/Matcher.cpp	Fri Nov 14 09:45:56 2014 +0000
+++ b/src/Matcher.cpp	Fri Nov 14 10:09:10 2014 +0000
@@ -102,7 +102,7 @@
 Matcher::size()
 {
     int distSize = (m_params.maxRunCount + 1) * m_blockSize;
-    m_bestPathCost.resize(m_distXSize, vector<float>(distSize, 0));
+    m_bestPathCost.resize(m_distXSize, vector<double>(distSize, 0));
     m_distance.resize(m_distXSize, vector<float>(distSize, 0));
     m_advance.resize(m_distXSize, vector<Advance>(distSize, AdvanceNone));
     m_distYSizes.resize(m_distXSize, distSize);
@@ -205,22 +205,22 @@
             // missing value(s) due to cutoff
             //  - no previous value in current row (resp. column)
             //  - no diagonal value if prev. dir. == curr. dirn
-            float min2 = getValue(m_frameCount - 1, index, true);
+            double min2 = getValue(m_frameCount - 1, index, true);
             //	if ((m_firstPM && (first[m_frameCount - 1] == index)) ||
             //			(!m_firstPM && (m_last[index-1] < m_frameCount)))
             if (m_first[m_frameCount - 1] == index)
                 setValue(m_frameCount, index, AdvanceThis, min2, dMN);
             else {
-                float min1 = getValue(m_frameCount - 1, index - 1, true);
+                double min1 = getValue(m_frameCount - 1, index - 1, true);
                 if (min1 + dMN <= min2)
                     setValue(m_frameCount, index, AdvanceBoth, min1,dMN);
                 else
                     setValue(m_frameCount, index, AdvanceThis, min2,dMN);
             }
         } else {
-            float min1 = getValue(m_frameCount, index-1, true);
-            float min2 = getValue(m_frameCount - 1, index, true);
-            float min3 = getValue(m_frameCount - 1, index-1, true);
+            double min1 = getValue(m_frameCount, index-1, true);
+            double min2 = getValue(m_frameCount - 1, index, true);
+            double min3 = getValue(m_frameCount - 1, index-1, true);
             if (min1 <= min2) {
                 if (min3 + dMN <= min1)
                     setValue(m_frameCount, index, AdvanceBoth, min3,dMN);
@@ -242,7 +242,7 @@
     m_otherMatcher->m_runCount = 0;
 }
 
-float
+double
 Matcher::getValue(int i, int j, bool firstAttempt)
 {
     if (m_firstPM)
@@ -252,7 +252,7 @@
 } // getValue()
 
 void
-Matcher::setValue(int i, int j, Advance dir, float value, float dMN)
+Matcher::setValue(int i, int j, Advance dir, double value, float dMN)
 {
     if (m_firstPM) {
 
--- a/src/Matcher.h	Fri Nov 14 09:45:56 2014 +0000
+++ b/src/Matcher.h	Fri Nov 14 10:09:10 2014 +0000
@@ -168,7 +168,7 @@
      *  @param j the frame number of the other Matcher
      *  @return the cost of the minimum cost path to this location
      */
-    float getValue(int i, int j, bool firstAttempt);
+    double getValue(int i, int j, bool firstAttempt);
 
     /** Stores entries in the distance matrix and the optimal path matrix.
      *
@@ -179,7 +179,7 @@
      *  @param value the cost of the minimum path except the current step
      *  @param dMN the distance cost between the two frames
      */
-    void setValue(int i, int j, Advance dir, float value, float dMN);
+    void setValue(int i, int j, Advance dir, double value, float dMN);
 
     void calcAdvance();
 
@@ -221,7 +221,7 @@
     vector<vector<double> > m_frames;
 
     /** The best path cost matrix. */
-    vector<vector<float> > m_bestPathCost;
+    vector<vector<double> > m_bestPathCost;
 
     /** The distance matrix. */
     vector<vector<float> > m_distance;