summaryrefslogtreecommitdiff
path: root/src/CuTNetLib/cuSharedLinearity.h
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
committerJoe Zhao <ztuowen@gmail.com>2014-04-14 08:14:45 +0800
commitcccccbf6cca94a3eaf813b4468453160e91c332b (patch)
tree23418cb73a10ae3b0688681a7f0ba9b06424583e /src/CuTNetLib/cuSharedLinearity.h
downloadtnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.gz
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.tar.bz2
tnet-cccccbf6cca94a3eaf813b4468453160e91c332b.zip
First commit
Diffstat (limited to 'src/CuTNetLib/cuSharedLinearity.h')
-rw-r--r--src/CuTNetLib/cuSharedLinearity.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/CuTNetLib/cuSharedLinearity.h b/src/CuTNetLib/cuSharedLinearity.h
new file mode 100644
index 0000000..76133eb
--- /dev/null
+++ b/src/CuTNetLib/cuSharedLinearity.h
@@ -0,0 +1,94 @@
+#ifndef _CUSHARED_LINEARITY_H_
+#define _CUSHARED_LINEARITY_H_
+
+
+#include "cuComponent.h"
+#include "cumatrix.h"
+
+
+#include "Matrix.h"
+#include "Vector.h"
+
+
+namespace TNet {
+
+ /**
+ * \brief CuSharedLinearity summation function
+ *
+ * \ingroup CuNNUpdatable
+ * Weights and bias are shared between output,
+ * which means the interconnections are segmented.
+ * every time the outputs (blocks) are generated individually, and bias is expanded to speed up?
+ * \sa CuBiasedLinearity
+ */
+ class CuSharedLinearity : public CuUpdatableComponent
+ {
+ public:
+
+ CuSharedLinearity(size_t nInputs, size_t nOutputs, CuComponent *pPred);
+ ~CuSharedLinearity();
+
+ ComponentType GetType() const;
+ const char* GetName() const;
+
+ void PropagateFnc(const CuMatrix<BaseFloat>& X, CuMatrix<BaseFloat>& Y);
+ void BackpropagateFnc(const CuMatrix<BaseFloat>& X, CuMatrix<BaseFloat>& Y);
+
+ void Update();
+
+ void ReadFromStream(std::istream& rIn);
+ void WriteToStream(std::ostream& rOut);
+
+ protected:
+ CuMatrix<BaseFloat> mLinearity; ///< Matrix with neuron weights
+ CuVector<BaseFloat> mBias; ///< Vector with biases
+
+ CuMatrix<BaseFloat> mLinearityCorrection; ///< Matrix for linearity updates
+ CuVector<BaseFloat> mBiasCorrection; ///< Vector for bias updates
+
+ int mNInstances; ///< Number of times the bias and weights are shared
+ CuVector<BaseFloat> mBiasExpand; ///< Bias expanded by mNInstances times
+ CuVector<BaseFloat> mBiasCorrectionExpand;///< Bias correction for the expanded bias vector
+
+ };
+
+
+
+
+ ////////////////////////////////////////////////////////////////////////////
+ // INLINE FUNCTIONS
+ // CuSharedLinearity::
+ inline
+ CuSharedLinearity::
+ CuSharedLinearity(size_t nInputs, size_t nOutputs, CuComponent *pPred)
+ : CuUpdatableComponent(nInputs, nOutputs, pPred),
+ mNInstances(0)
+ { }
+
+
+ inline
+ CuSharedLinearity::
+ ~CuSharedLinearity()
+ { }
+
+ inline CuComponent::ComponentType
+ CuSharedLinearity::
+ GetType() const
+ {
+ return CuComponent::SHARED_LINEARITY;
+ }
+
+ inline const char*
+ CuSharedLinearity::
+ GetName() const
+ {
+ return "<sharedlinearity>";
+ }
+
+
+
+} //namespace
+
+
+
+#endif