Repository: systemml
Updated Branches:
  refs/heads/master 07e65189e -> eb182010b


[SYSTEMML-2468] Improved MNC sketch propagation (probabilistic rounding)

Closes #807


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/eb182010
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/eb182010
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/eb182010

Branch: refs/heads/master
Commit: eb182010ba69a645b11f9a8bc18f2722dc7e64d6
Parents: 07e6518
Author: Johanna Sommer <[email protected]>
Authored: Wed Jul 25 20:38:55 2018 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Wed Jul 25 20:38:56 2018 -0700

----------------------------------------------------------------------
 .../sysml/hops/estim/EstimatorMatrixHistogram.java     | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/eb182010/src/main/java/org/apache/sysml/hops/estim/EstimatorMatrixHistogram.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/estim/EstimatorMatrixHistogram.java 
b/src/main/java/org/apache/sysml/hops/estim/EstimatorMatrixHistogram.java
index f78d94e..e00c005 100644
--- a/src/main/java/org/apache/sysml/hops/estim/EstimatorMatrixHistogram.java
+++ b/src/main/java/org/apache/sysml/hops/estim/EstimatorMatrixHistogram.java
@@ -20,6 +20,7 @@
 package org.apache.sysml.hops.estim;
 
 import java.util.Arrays;
+import java.util.Random;
 
 import org.apache.sysml.hops.OptimizerUtils;
 import org.apache.sysml.runtime.matrix.MatrixCharacteristics;
@@ -258,18 +259,26 @@ public class EstimatorMatrixHistogram extends 
SparsityEstimator
                        //(this implies 0s propagate and distribution is 
preserved)
                        int rMaxNnz = 0, cMaxNnz = 0;
                        int[] rNnz = new int[h1.getRows()];
+                       Random rn = new Random();
                        for( int i=0; i<h1.getRows(); i++ ) {
-                               rNnz[i] = (int) Math.round(nnzOut/nnz1 * 
h1.rNnz[i]);
+                               rNnz[i] = probRound(nnzOut/nnz1 * h1.rNnz[i], 
rn);
                                rMaxNnz = Math.max(rMaxNnz, rNnz[i]);
                        }
                        int[] cNnz = new int[h2.getCols()];
                        for( int i=0; i<h2.getCols(); i++ ) {
-                               cNnz[i] = (int) Math.round(nnzOut/nnz2 * 
h2.cNnz[i]);
+                               cNnz[i] = probRound(nnzOut/nnz2 * h2.cNnz[i], 
rn);
                                cMaxNnz = Math.max(cMaxNnz, cNnz[i]);
                        }
                        
                        //construct new histogram object
                        return new MatrixHistogram(rNnz, null, cNnz, null, 
rMaxNnz, cMaxNnz);
                }
+               
+               private static int probRound(double inNnz, Random rand) {
+                       double temp = Math.floor(inNnz);
+                       double f = inNnz - temp; //non-int fraction [0,1)
+                       double randf = rand.nextDouble(); //uniform [0,1)
+                       return (int)((f > randf) ? temp+1 : temp);
+               }
        }
 }

Reply via email to