27 #ifndef TMVA_DNN_DENSELAYER 28 #define TMVA_DNN_DENSELAYER 54 template <
typename Architecture_t>
57 using Scalar_t =
typename Architecture_t::Scalar_t;
58 using Matrix_t =
typename Architecture_t::Matrix_t;
88 void Forward(std::vector<Matrix_t> &input,
bool applyDropout =
false);
94 void Backward(std::vector<Matrix_t> &gradients_backward,
const std::vector<Matrix_t> &activations_backward,
95 std::vector<Matrix_t> &inp1, std::vector<Matrix_t> &inp2);
125 template <
typename Architecture_t>
129 :
VGeneralLayer<Architecture_t>(batchSize, 1, 1, inputWidth, 1, 1, width, 1, width, inputWidth, 1, width, 1, 1,
130 batchSize, width, init),
137 template <
typename Architecture_t>
146 template <
typename Architecture_t>
155 template <
typename Architecture_t>
162 template <
typename Architecture_t>
175 template <
typename Architecture_t>
177 const std::vector<Matrix_t> &activations_backward,
178 std::vector<Matrix_t> & , std::vector<Matrix_t> &
181 if (gradients_backward.size() == 0) {
185 activations_backward[0]);
190 activations_backward[0]);
198 template <
typename Architecture_t>
201 std::cout <<
" DENSE Layer: \t ";
202 std::cout <<
" ( Input = " << this->
GetWeightsAt(0).GetNcols();
203 std::cout <<
" , Width = " << this->
GetWeightsAt(0).GetNrows() <<
" ) ";
205 std::cout <<
"\tOutput = ( " << this->
GetOutput().size() <<
" , " << this->
GetOutput()[0].GetNrows() <<
" , " << this->
GetOutput()[0].GetNcols() <<
" ) ";
207 std::vector<std::string> activationNames = {
"Identity",
"Relu",
"Sigmoid",
"Tanh",
"SymmRelu",
"SoftSign",
"Gauss" };
208 std::cout <<
"\t Activation Function = ";
209 std::cout << activationNames[ static_cast<int>(
fF) ] << std::endl;
214 template <
typename Architecture_t>
232 template <
typename Architecture_t>
Generic General Layer class.
Matrix_t & GetDerivativesAt(size_t i)
static TString Itoa(Int_t value, Int_t base)
Converts an Int_t to a TString with respect to the base specified (2-36).
virtual void AddWeightsXMLTo(void *parent)
Writes the information and the weights about the layer in an XML node.
size_t fWidth
The width of this layer.
void ReadMatrixXML(void *node, const char *name, Matrix_t &matrix)
typename Architecture_t::Scalar_t Scalar_t
typename Architecture_t::Matrix_t Matrix_t
const Matrix_t & GetBiasesAt(size_t i) const
EActivationFunction GetActivationFunction() const
virtual void ReadWeightsFromXML(void *parent)
Read the information and the weights about the layer from XML node.
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
EActivationFunction fF
Activation function of the layer.
void Forward(std::vector< Matrix_t > &input, bool applyDropout=false)
Compute activation of the layer for the given input.
Scalar_t GetDropoutProbability() const
Getters.
Matrix_t & GetOutputAt(size_t i)
~TDenseLayer()
Destructor.
ERegularization GetRegularization() const
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
size_t GetBatchSize() const
Getters.
ERegularization fReg
The regularization method.
std::vector< Matrix_t > fDerivatives
First fDerivatives of the activations of this layer.
const Matrix_t & GetBiasGradientsAt(size_t i) const
std::vector< Matrix_t > & GetDerivatives()
void Print() const
Printing the layer info.
const Matrix_t & GetWeightsAt(size_t i) const
Matrix_t & GetActivationGradientsAt(size_t i)
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
size_t fBatchSize
Batch size used for training and evaluation.
static RooMathCoreReg dummy
Scalar_t GetWeightDecay() const
void Backward(std::vector< Matrix_t > &gradients_backward, const std::vector< Matrix_t > &activations_backward, std::vector< Matrix_t > &inp1, std::vector< Matrix_t > &inp2)
Compute weight, bias and activation gradients.
const Matrix_t & GetDerivativesAt(size_t i) const
Abstract ClassifierFactory template that handles arbitrary types.
const Matrix_t & GetWeightGradientsAt(size_t i) const
Scalar_t fWeightDecay
The weight decay.
Scalar_t fDropoutProbability
Probability that an input is active.
TDenseLayer(size_t BatchSize, size_t InputWidth, size_t Width, EInitialization init, Scalar_t DropoutProbability, EActivationFunction f, ERegularization reg, Scalar_t weightDecay)
Constructor.
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
const std::vector< Matrix_t > & GetDerivatives() const
ERegularization
Enum representing the regularization type applied for a given layer.
void WriteMatrixToXML(void *node, const char *name, const Matrix_t &matrix)
EActivationFunction
Enum that represents layer activation functions.
const std::vector< Matrix_t > & GetOutput() const