This is an automated email from the ASF dual-hosted git repository.

mboehm7 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemds.git


The following commit(s) were added to refs/heads/master by this push:
     new 527e47d  [MINOR] Fix multiLogRegPredict (sanity check matching dims, 
cleanup)
527e47d is described below

commit 527e47d7ac4d594020c0ac508a2ceae03048429a
Author: Matthias Boehm <[email protected]>
AuthorDate: Fri Jan 29 13:55:41 2021 +0100

    [MINOR] Fix multiLogRegPredict (sanity check matching dims, cleanup)
---
 scripts/builtin/multiLogRegPredict.dml | 33 ++++++++++++---------------------
 1 file changed, 12 insertions(+), 21 deletions(-)

diff --git a/scripts/builtin/multiLogRegPredict.dml 
b/scripts/builtin/multiLogRegPredict.dml
index 213f7dd..3756420 100644
--- a/scripts/builtin/multiLogRegPredict.dml
+++ b/scripts/builtin/multiLogRegPredict.dml
@@ -40,39 +40,32 @@
 # accuracy           Double  ---     scalar value of accuracy
 # 
---------------------------------------------------------------------------------------------
 
-
 m_multiLogRegPredict = function(Matrix[Double] X, Matrix[Double] B, 
Matrix[Double] Y, Boolean verbose = FALSE)
-return(Matrix[Double] M, Matrix[Double] predicted_Y, Double accuracy)
-{  
+  return(Matrix[Double] M, Matrix[Double] predicted_Y, Double accuracy)
+{
   if(min(Y) <= 0)
-    stop("class labels should be greater than zero")
-    
-  num_records = nrow(X);
-  num_features = ncol(X);
-  beta = B[1:ncol(X), ];
-  intercept = B[nrow(B), ];
-
-  if (nrow(B) == ncol(X))
-    intercept = 0.0 * intercept; 
-  else
-    num_features = num_features + 1;
+    stop("multiLogRegPredict: class labels should be greater than zero")
+  if(ncol(X) < nrow(B)-1)
+    stop("multiLogRegPredict: mismatching ncol(X) and nrow(B): "+ncol(X)+" 
"+nrow(B));
 
-  ones_rec = matrix(1, rows = num_records, cols = 1);
-  linear_terms = X %*% beta + ones_rec %*% intercept;
+  beta = B[1:ncol(X), ];
+  intercept = ifelse(ncol(X)==nrow(B), matrix(0,1,ncol(B)), B[nrow(B),]);
+  linear_terms = X %*% beta + matrix(1,nrow(X),1) %*% intercept;
 
   M = probabilities(linear_terms); # compute the probablitites on unknown data
   predicted_Y = rowIndexMax(M); # extract the class labels
 
   if(nrow(Y) != 0)
-    accuracy = sum((predicted_Y - Y) == 0) / num_records * 100;
+    accuracy = sum((predicted_Y - Y) == 0) / nrow(Y) * 100;
   
   if(verbose)
     print("Accuracy (%): " + accuracy);
 }
 
 probabilities = function (Matrix[double] linear_terms)
-  return (Matrix[double] means) {
-   # PROBABLITIES FOR MULTINOMIAL LOGIT DISTRIBUTION
+  return (Matrix[double] means)
+{
+  # PROBABLITIES FOR MULTINOMIAL LOGIT DISTRIBUTION
   num_points = nrow (linear_terms);
   elt = exp (linear_terms);
   ones_pts = matrix (1, rows = num_points, cols = 1);
@@ -80,5 +73,3 @@ probabilities = function (Matrix[double] linear_terms)
   ones_ctg = matrix (1, rows = ncol (elt), cols = 1);
   means = elt / (rowSums (elt) %*% t(ones_ctg));
 }
-
-

Reply via email to