You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2017/11/22 01:44:19 UTC

[GitHub] javelinjs closed pull request #8297: [scala] Make accuracy idependant of output size (fix #8226)

javelinjs closed pull request #8297: [scala] Make accuracy idependant of output size (fix #8226)
URL: https://github.com/apache/incubator-mxnet/pull/8297
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/scala-package/core/src/main/scala/ml/dmlc/mxnet/EvalMetric.scala b/scala-package/core/src/main/scala/ml/dmlc/mxnet/EvalMetric.scala
index 6b993d7665..98a09d2250 100644
--- a/scala-package/core/src/main/scala/ml/dmlc/mxnet/EvalMetric.scala
+++ b/scala-package/core/src/main/scala/ml/dmlc/mxnet/EvalMetric.scala
@@ -26,7 +26,7 @@ import scala.collection.mutable.ArrayBuffer
 abstract class EvalMetric(protected val name: String) {
 
   protected var numInst: Int = 0
-  protected var sumMetric: Float = 0.0f
+  protected var sumMetric: Double = 0.0d
 
   /**
    * Update the internal evaluation.
@@ -41,7 +41,7 @@ abstract class EvalMetric(protected val name: String) {
    */
   def reset(): Unit = {
     this.numInst = 0
-    this.sumMetric = 0.0f
+    this.sumMetric = 0.0d
   }
 
   /**
@@ -50,7 +50,7 @@ abstract class EvalMetric(protected val name: String) {
    *         value, Value of the evaluation
    */
   def get: (Array[String], Array[Float]) = {
-    (Array(this.name), Array(this.sumMetric / this.numInst))
+    (Array(this.name), Array((this.sumMetric / this.numInst).toFloat))
   }
 }
 
@@ -111,11 +111,10 @@ class Accuracy extends EvalMetric("accuracy") {
       require(label.shape == predLabel.shape,
         s"label ${label.shape} and prediction ${predLabel.shape}" +
         s"should have the same length.")
-      for ((labelElem, predElem) <- label.toArray zip predLabel.toArray) {
-        if (labelElem == predElem) {
-          this.sumMetric += 1
-        }
-      }
+
+      this.sumMetric += label.toArray.zip(predLabel.toArray)
+        .filter{ case (labelElem: Float, predElem: Float) => labelElem == predElem }
+        .size
       this.numInst += predLabel.shape(0)
       predLabel.dispose()
     }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services