[mlpack-git] master: Add binary classification layer. (5e2b58d)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:13:14 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

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

commit 5e2b58d20d0909113dd9e131b4494cb1af9781e5
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Mon Jan 19 21:42:16 2015 +0100

    Add binary classification layer.


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

5e2b58d20d0909113dd9e131b4494cb1af9781e5
 ...n_layer.hpp => binary_classification_layer.hpp} | 52 +++++++++++-----------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp
similarity index 53%
copy from src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp
copy to src/mlpack/methods/ann/layer/binary_classification_layer.hpp
index 797954a..0710ffd 100644
--- a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp
+++ b/src/mlpack/methods/ann/layer/binary_classification_layer.hpp
@@ -1,12 +1,12 @@
 /**
- * @file multiclass_classification_layer.hpp
+ * @file binary_classification_layer.hpp
  * @author Marcus Edel
  *
- * Definition of the MulticlassClassificationLayer class, which implements a
- * multiclass classification layer that can be used as output layer.
+ * Definition of the BinaryClassificationLayer class, which implements a
+ * binary class classification layer that can be used as output layer.
  */
-#ifndef __MLPACK_METHOS_ANN_LAYER_MULTICLASS_CLASSIFICATION_LAYER_HPP
-#define __MLPACK_METHOS_ANN_LAYER_MULTICLASS_CLASSIFICATION_LAYER_HPP
+#ifndef __MLPACK_METHOS_ANN_LAYER_BINARY_CLASSIFICATION_LAYER_HPP
+#define __MLPACK_METHOS_ANN_LAYER_BINARY_CLASSIFICATION_LAYER_HPP
 
 #include <mlpack/core.hpp>
 #include <mlpack/methods/ann/layer/layer_traits.hpp>
@@ -15,13 +15,9 @@ namespace mlpack {
 namespace ann /** Artificial Neural Network. */ {
 
 /**
- * An implementation of a multiclass classification layer that can be used as
+ * An implementation of a binary classification layer that can be used as
  * output layer.
  *
- * * A convenience typedef is given:
- *
- *  - ClassificationLayer
- *
  * @tparam MatType Type of data (arma::mat or arma::sp_mat).
  * @tparam VecType Type of data (arma::colvec, arma::mat or arma::sp_mat).
  */
@@ -29,13 +25,13 @@ template <
     typename MatType = arma::mat,
     typename VecType = arma::colvec
 >
-class MulticlassClassificationLayer
+class BinaryClassificationLayer
 {
  public:
   /**
-   * Create the MulticlassClassificationLayer object.
+   * Create the BinaryClassificationLayer object.
    */
-  MulticlassClassificationLayer()
+  BinaryClassificationLayer()
   {
     // Nothing to do here.
   }
@@ -55,31 +51,33 @@ class MulticlassClassificationLayer
   {
     error = -(target - inputActivations);
   }
-}; // class MulticlassClassificationLayer
 
-//! Layer traits for the multiclass classification layer.
+  /*
+   * Calculate the output class using the specified input activation.
+   *
+   * @param inputActivations Input data used to calculate the output class.
+   * @param output Output class of the input activation.
+   */
+  void outputClass(const VecType& inputActivations, VecType& output)
+  {
+    output = inputActivations;
+    output.transform( [](double value) { return (value > 0.5 ? 1 : 0); } );
+  }
+}; // class BinaryClassificationLayer
+
+//! Layer traits for the binary class classification layer.
 template <
     typename MatType,
     typename VecType
 >
-class LayerTraits<MulticlassClassificationLayer<MatType, VecType> >
+class LayerTraits<BinaryClassificationLayer<MatType, VecType> >
 {
  public:
-  static const bool IsBinary = false;
+  static const bool IsBinary = true;
   static const bool IsOutputLayer = true;
   static const bool IsBiasLayer = false;
 };
 
-/***
- * Standard Input-Layer using the tanh activation function and the
- * Nguyen-Widrow method to initialize the weights.
- */
-template <
-    typename MatType = arma::mat,
-    typename VecType = arma::colvec
->
-using ClassificationLayer = MulticlassClassificationLayer<MatType, VecType>;
-
 }; // namespace ann
 }; // namespace mlpack
 



More information about the mlpack-git mailing list