[mlpack-svn] master: Add implementation of the self connection class. (8c13d5c)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 31 15:59:10 EST 2014
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/c935252ea3134025d7d0df05afa4a1501dad4d59...8c13d5c6d16fadd1fe4dfb2230adfaa0268e95dd
>---------------------------------------------------------------
commit 8c13d5c6d16fadd1fe4dfb2230adfaa0268e95dd
Author: Marcus Edel <marcus.edel at fu-berlin.de>
Date: Wed Dec 31 21:58:57 2014 +0100
Add implementation of the self connection class.
>---------------------------------------------------------------
8c13d5c6d16fadd1fe4dfb2230adfaa0268e95dd
.../{full_connection.hpp => self_connection.hpp} | 57 ++++++++++++++--------
1 file changed, 38 insertions(+), 19 deletions(-)
diff --git a/src/mlpack/methods/ann/connections/full_connection.hpp b/src/mlpack/methods/ann/connections/self_connection.hpp
similarity index 67%
copy from src/mlpack/methods/ann/connections/full_connection.hpp
copy to src/mlpack/methods/ann/connections/self_connection.hpp
index 82efd49..2f404ba 100644
--- a/src/mlpack/methods/ann/connections/full_connection.hpp
+++ b/src/mlpack/methods/ann/connections/self_connection.hpp
@@ -1,22 +1,24 @@
/**
- * @file full_connection.hpp
+ * @file self_connection.hpp
* @author Marcus Edel
*
- * Implementation of the full connection class.
+ * Implementation of the self connection class. This connection is mainly used
+ * as recurrent connection.
*/
-#ifndef __MLPACK_METHOS_ANN_CONNECTIONS_FULL_CONNECTION_HPP
-#define __MLPACK_METHOS_ANN_CONNECTIONS_FULL_CONNECTION_HPP
+#ifndef __MLPACK_METHOS_ANN_CONNECTIONS_SELF_CONNECTION_HPP
+#define __MLPACK_METHOS_ANN_CONNECTIONS_SELF_CONNECTION_HPP
#include <mlpack/core.hpp>
#include <mlpack/methods/ann/init_rules/nguyen_widrow_init.hpp>
+#include <mlpack/methods/ann/connections/connection_traits.hpp>
namespace mlpack {
namespace ann /** Artificial Neural Network. */ {
/**
- * Implementation of the full connection class. The full connection connects
- * every neuron from the input layer with the output layer in a matrix
- * multiplicative way.
+ * Implementation of the self connection class. The self connection connects
+ * every neuron from the input layer with the output layer in a multiplicative
+ * way.
*
* @tparam InputLayerType Type of the connected input layer.
* @tparam OutputLayerType Type of the connected output layer.
@@ -33,24 +35,23 @@ template<
typename MatType = arma::mat,
typename VecType = arma::colvec
>
-class FullConnection
+class SelfConnection
{
public:
/**
- * Create the FullConnection object using the specified input layer, output
+ * Create the SelfConnection object using the specified input layer, output
* layer, optimizer and weight initialize rule.
*
* @param lowerBound The number used as lower bound.
* @param upperBound The number used as upper bound.
*/
- FullConnection(InputLayerType& inputLayer,
+ SelfConnection(InputLayerType& inputLayer,
OutputLayerType& outputLayer,
OptimizerType& optimizer,
WeightInitRule weightInitRule = WeightInitRule()) :
inputLayer(inputLayer), outputLayer(outputLayer), optimizer(optimizer)
{
- weightInitRule.Initialize(weights, outputLayer.InputSize(),
- inputLayer.OutputSize());
+ weightInitRule.Initialize(weights, outputLayer.OutputSize(), 1);
}
/**
@@ -61,7 +62,7 @@ class FullConnection
*/
void FeedForward(const VecType& input)
{
- outputLayer.InputActivation() += (weights * input);
+ outputLayer.InputActivation() += (weights % input);
}
/**
@@ -79,27 +80,27 @@ class FullConnection
}
//! Get the weights.
- MatType& Weights() const { return weights; }
+ const MatType& Weights() const { return weights; }
//! Modify the weights.
MatType& Weights() { return weights; }
//! Get the input layer.
- InputLayerType& InputLayer() const { return inputLayer; }
+ const InputLayerType& InputLayer() const { return inputLayer; }
//! Modify the input layer.
InputLayerType& InputLayer() { return inputLayer; }
//! Get the output layer.
- OutputLayerType& OutputLayer() const { return outputLayer; }
+ const OutputLayerType& OutputLayer() const { return outputLayer; }
//! Modify the output layer.
OutputLayerType& OutputLayer() { return outputLayer; }
//! Get the optimzer.
- OptimizerType& Optimzer() const { return optimizer; }
+ const OptimizerType& Optimzer() const { return optimizer; }
//! Modify the optimzer.
OptimizerType& Optimzer() { return optimizer; }
//! Get the detla.
- VecType& Delta() const { return delta; }
+ const VecType& Delta() const { return delta; }
// //! Modify the delta.
VecType& Delta() { return delta; }
@@ -118,7 +119,25 @@ class FullConnection
//! Locally-stored detla object that holds the calculated delta.
VecType delta;
-}; // class FullConnection
+}; // class SelfConnection
+
+//! Connection traits for the self connection.
+template<
+ typename InputLayerType,
+ typename OutputLayerType,
+ typename OptimizerType,
+ class WeightInitRule,
+ typename MatType,
+ typename VecType
+>
+class ConnectionTraits<
+ SelfConnection<InputLayerType, OutputLayerType, OptimizerType,
+ WeightInitRule, MatType, VecType> >
+{
+ public:
+ static const bool IsSelfConnection = true;
+ static const bool IsFullselfConnection = false;
+};
}; // namespace ann
}; // namespace mlpack
More information about the mlpack-svn
mailing list