mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r930227 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
Date Fri, 02 Apr 2010 10:11:32 GMT
Author: srowen
Date: Fri Apr  2 10:11:31 2010
New Revision: 930227

URL: http://svn.apache.org/viewvc?rev=930227&view=rev
Log:
MAHOUT-360: better rounding

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java?rev=930227&r1=930226&r2=930227&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/RecommendedItemsWritable.java
Fri Apr  2 10:11:31 2010
@@ -21,6 +21,8 @@ import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.EOFException;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.MathContext;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -34,6 +36,8 @@ import org.apache.mahout.cf.taste.recomm
  * highest.
  */
 public final class RecommendedItemsWritable implements Writable {
+
+  private static final MathContext ROUNDING = new MathContext(5);
   
   private List<RecommendedItem> recommended;
   
@@ -96,14 +100,8 @@ public final class RecommendedItemsWrita
       }
       result.append(item.getItemID());
       result.append(':');
-      String valueString = String.valueOf(item.getValue());
-      // Is this rounding too crude?
-      if (valueString.indexOf('E') >= 0) {
-        valueString = "0.0";
-      } else if (valueString.length() > 6) {
-        valueString = valueString.substring(0, 6);
-      }
-      result.append(valueString);
+      BigDecimal bd = new BigDecimal(item.getValue()).round(ROUNDING);
+      result.append(bd.toPlainString());
     }
     result.append(']');
     return result.toString();



Mime
View raw message