#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& X, CuMatrix& Y); void BackpropagateFnc(const CuMatrix& X, CuMatrix& Y); void Update(); void ReadFromStream(std::istream& rIn); void WriteToStream(std::ostream& rOut); protected: CuMatrix mLinearity; ///< Matrix with neuron weights CuVector mBias; ///< Vector with biases CuMatrix mLinearityCorrection; ///< Matrix for linearity updates CuVector mBiasCorrection; ///< Vector for bias updates int mNInstances; ///< Number of times the bias and weights are shared CuVector mBiasExpand; ///< Bias expanded by mNInstances times CuVector 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 ""; } } //namespace #endif