[mlpack-git] master: Add confidence parameter to enable custom class transformation. (f4b3464)

gitdub at mlpack.org gitdub at mlpack.org
Sat Apr 9 07:31:20 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/ba826b1959a3f83532e91765b2bba0705e588d39...f4b3464fce6bdc7c61d94f6b22bc71fe61276328

>---------------------------------------------------------------

commit f4b3464fce6bdc7c61d94f6b22bc71fe61276328
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Sat Apr 9 13:31:02 2016 +0200

    Add confidence parameter to enable custom class transformation.


>---------------------------------------------------------------

f4b3464fce6bdc7c61d94f6b22bc71fe61276328
 .../ann/layer/binary_classification_layer.hpp        | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp
index 368c1ec..eb9f7a2 100644
--- a/src/mlpack/methods/ann/layer/binary_classification_layer.hpp
+++ b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp
@@ -23,8 +23,11 @@ class BinaryClassificationLayer
  public:
   /**
    * Create the BinaryClassificationLayer object.
+   *
+   * @param confidence The confidence used for the output class transformation.
    */
-  BinaryClassificationLayer()
+  BinaryClassificationLayer(const double confidence = 0.5) :
+      confidence(confidence)
   {
     // Nothing to do here.
   }
@@ -58,17 +61,26 @@ class BinaryClassificationLayer
     output = inputActivations;
 
     for (size_t i = 0; i < output.n_elem; i++)
-      output(i) = output(i) > 0.5 ? 1 : 0;
+      output(i) = output(i) > confidence ? 1 : 0;
   }
 
+  //! Get the confidence parameter.
+  double const& Confidence() const { return confidence; }
+  //! Modify the confidence parameter.
+  double& Confidence() { return confidence; }
+  
   /**
    * Serialize the layer.
    */
   template<typename Archive>
-  void Serialize(Archive& /* ar */, const unsigned int /* version */)
+  void Serialize(Archive& ar, const unsigned int /* version */)
   {
-    /* Nothing to do here */
+    ar & data::CreateNVP(confidence, "confidence");
   }
+
+ private:
+   double confidence;
+
 }; // class BinaryClassificationLayer
 
 //! Layer traits for the binary class classification layer.




More information about the mlpack-git mailing list