[mlpack-git] master: Add implementation of the cross-entropy error performance function. (3e5387d)

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


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

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

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

commit 3e5387d949e20a43cf54f51b2d6b55c48975b0c1
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date:   Sat Jan 3 14:12:48 2015 +0100

    Add implementation of the cross-entropy error performance function.


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

3e5387d949e20a43cf54f51b2d6b55c48975b0c1
 .../ann/performance_functions/cee_function.hpp     | 55 ++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/src/mlpack/methods/ann/performance_functions/cee_function.hpp b/src/mlpack/methods/ann/performance_functions/cee_function.hpp
new file mode 100644
index 0000000..0113694
--- /dev/null
+++ b/src/mlpack/methods/ann/performance_functions/cee_function.hpp
@@ -0,0 +1,55 @@
+/**
+ * @file cee_function.hpp
+ * @author Marcus Edel
+ *
+ * Definition and implementation of the cross-entropy error performance
+ * function.
+ */
+#ifndef __MLPACK_METHODS_ANN_PERFORMANCE_FUNCTIONS_CEE_FUNCTION_HPP
+#define __MLPACK_METHODS_ANN_PERFORMANCE_FUNCTIONS_CEE_FUNCTION_HPP
+
+#include <mlpack/core.hpp>
+
+#include <mlpack/methods/ann/layer/layer_traits.hpp>
+#include <mlpack/methods/ann/layer/neuron_layer.hpp>
+
+namespace mlpack {
+namespace ann /** Artificial Neural Network. */ {
+
+/**
+ * The cross-entropy error performance function measures the network's
+ * performance according to the cross entropy errors. The log in the cross-
+ * entropy take sinto account the closeness of a prediction and is a more
+ * granular way to calculate the error.
+ *
+ * @tparam Layer The layer that is connected with the output layer.
+ * @tparam VecType Type of data (arma::colvec, arma::mat or arma::sp_mat).
+ */
+template<
+    class Layer = NeuronLayer< >,
+    typename VecType = arma::colvec
+>
+class CrossEntropyErrorFunction
+{
+  public:
+  /**
+   * Computes the cross-entropy error function.
+   *
+   * @param input Input data.
+   * @param target Target data.
+   * @return cross-entropy error.
+   */
+  static double error(const VecType& input, const VecType& target)
+  {
+    if (LayerTraits<Layer>::IsBinary)
+      return -arma::dot(arma::trunc_log(arma::abs(target - input)), target);
+
+    return -arma::dot(arma::trunc_log(input), target);
+  }
+
+}; // class CrossEntropyErrorFunction
+
+}; // namespace ann
+}; // namespace mlpack
+
+#endif



More information about the mlpack-git mailing list