[mlpack-svn] master: Add implementation of the MulticlassClassificationLayer class. (a8a3649)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Fri Jan 2 11:15:23 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/5104bd4c07135b5dab3136c64e113dfb8de5d417...a8a364989de349eca52d51ee29f2a030759321a7
>---------------------------------------------------------------
commit a8a364989de349eca52d51ee29f2a030759321a7
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Fri Jan 2 17:15:12 2015 +0100
Add implementation of the MulticlassClassificationLayer class.
>---------------------------------------------------------------
a8a364989de349eca52d51ee29f2a030759321a7
.../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