[mlpack-git] master: Add implementation of the MulticlassClassificationLayer class. (2806bcd)

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


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

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

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

commit 2806bcd38b1e657751bb03561ae329daed7fcf92
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Fri Jan 2 17:15:12 2015 +0100

    Add implementation of the MulticlassClassificationLayer class.


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

2806bcd38b1e657751bb03561ae329daed7fcf92
 .../ann/layer/multiclass_classification_layer.hpp  | 87 ++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp
new file mode 100644
index 0000000..797954a
--- /dev/null
+++ b/src/mlpack/methods/ann/layer/multiclass_classification_layer.hpp
@@ -0,0 +1,87 @@
+/**
+ * @file multiclass_classification_layer.hpp
+ * @author Marcus Edel
+ *
+ * Definition of the MulticlassClassificationLayer class, which implements a
+ * multiclass 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
+
+#include <mlpack/core.hpp>
+#include <mlpack/methods/ann/layer/layer_traits.hpp>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+/**
+ * An implementation of a multiclass 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).
+ */
+template <
+    typename MatType = arma::mat,
+    typename VecType = arma::colvec
+>
+class MulticlassClassificationLayer
+{
+ public:
+  /**
+   * Create the MulticlassClassificationLayer object.
+   */
+  MulticlassClassificationLayer()
+  {
+    // Nothing to do here.
+  }
+
+  /*
+   * Calculate the error using the specified input activation and the target.
+   * The error is stored into the given error parameter.
+   *
+   * @param inputActivations Input data used for evaluating the network.
+   * @param target Target data used for evaluating the network.
+   * @param error The calculated error with respect to the input activation and
+   * the given target.
+   */
+  void calculateError(const VecType& inputActivations,
+                      const VecType& target,
+                      VecType& error)
+  {
+    error = -(target - inputActivations);
+  }
+}; // class MulticlassClassificationLayer
+
+//! Layer traits for the multiclass classification layer.
+template <
+    typename MatType,
+    typename VecType
+>
+class LayerTraits<MulticlassClassificationLayer<MatType, VecType> >
+{
+ public:
+  static const bool IsBinary = false;
+  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
+
+
+#endif



More information about the mlpack-git mailing list