Logo ROOT   6.14/05
Reference Guide
Reference.h
Go to the documentation of this file.
1 // @(#)root/tmva/tmva/dnn:$Id$
2 // Author: Simon Pfreundschuh 20/06/16
3 
4 /*************************************************************************
5  * Copyright (C) 2016, Simon Pfreundschuh *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 ///////////////////////////////////////////////////////////////////////
13 // Declaration of the TReference architecture, which provides a //
14 // reference implementation of the low-level interface for the DNN //
15 // implementation based on ROOT's TMatrixT matrix type. //
16 ///////////////////////////////////////////////////////////////////////
17 
18 #ifndef TMVA_DNN_ARCHITECTURES_REFERENCE
19 #define TMVA_DNN_ARCHITECTURES_REFERENCE
20 
21 #include "TMatrix.h"
22 #include "TMVA/DNN/Functions.h"
25 #include <vector>
26 
27 class TRandom;
28 
29 namespace TMVA
30 {
31 namespace DNN
32 {
33 
34 /*! The reference architecture class.
35 *
36 * Class template that contains the reference implementation of the low-level
37 * interface for the DNN implementation. The reference implementation uses the
38 * TMatrixT class template to represent matrices.
39 *
40 * \tparam AReal The floating point type used to represent scalars.
41 */
42 template<typename AReal>
43 class TReference
44 {
45 private:
46  static TRandom * fgRandomGen;
47 public:
48 
49  using Scalar_t = AReal;
51 
52  //____________________________________________________________________________
53  //
54  // Propagation
55  //____________________________________________________________________________
56 
57  /** @name Forward Propagation
58  * Low-level functions required for the forward propagation of activations
59  * through the network.
60  */
61  ///@{
62  /** Matrix-multiply \p input with the transpose of \pweights and
63  * write the results into \p output. */
65  const TMatrixT<Scalar_t> &input,
66  const TMatrixT<Scalar_t> &weights);
67  /** Add the vectors biases row-wise to the matrix output */
69  const TMatrixT<Scalar_t> &biases);
70  ///@}
71 
72  /** @name Backward Propagation
73  * Low-level functions required for the forward propagation of activations
74  * through the network.
75  */
76  ///@{
77  /** Perform the complete backward propagation step. If the provided
78  * \p activationGradientsBackward matrix is not empty, compute the
79  * gradients of the objective function with respect to the activations
80  * of the previous layer (backward direction).
81  * Also compute the weight and the bias gradients. Modifies the values
82  * in \p df and thus produces only a valid result, if it is applied the
83  * first time after the corresponding forward propagation has been per-
84  * formed. */
85  static void Backward(TMatrixT<Scalar_t> & activationGradientsBackward,
86  TMatrixT<Scalar_t> & weightGradients,
87  TMatrixT<Scalar_t> & biasGradients,
88  TMatrixT<Scalar_t> & df,
89  const TMatrixT<Scalar_t> & activationGradients,
90  const TMatrixT<Scalar_t> & weights,
91  const TMatrixT<Scalar_t> & activationBackward);
92  /** Backpropagation step for a Recurrent Neural Network */
93  static Matrix_t & RecurrentLayerBackward(TMatrixT<Scalar_t> & state_gradients_backward, // BxH
94  TMatrixT<Scalar_t> & input_weight_gradients,
95  TMatrixT<Scalar_t> & state_weight_gradients,
96  TMatrixT<Scalar_t> & bias_gradients,
97  TMatrixT<Scalar_t> & df, //DxH
98  const TMatrixT<Scalar_t> & state, // BxH
99  const TMatrixT<Scalar_t> & weights_input, // HxD
100  const TMatrixT<Scalar_t> & weights_state, // HxH
101  const TMatrixT<Scalar_t> & input, // BxD
102  TMatrixT<Scalar_t> & input_gradient);
103  /** Adds a the elements in matrix B scaled by c to the elements in
104  * the matrix A. This is required for the weight update in the gradient
105  * descent step.*/
106  static void ScaleAdd(TMatrixT<Scalar_t> & A,
107  const TMatrixT<Scalar_t> & B,
108  Scalar_t beta = 1.0);
109 
110  static void Copy(TMatrixT<Scalar_t> & A,
111  const TMatrixT<Scalar_t> & B);
112 
113  // copy from another type of matrix
114  template<typename AMatrix_t>
115  static void CopyDiffArch(TMatrixT<Scalar_t> & A, const AMatrix_t & B);
116 
117 
118  /** Above functions extended to vectors */
119  static void ScaleAdd(std::vector<TMatrixT<Scalar_t>> & A,
120  const std::vector<TMatrixT<Scalar_t>> & B,
121  Scalar_t beta = 1.0);
122 
123  static void Copy(std::vector<TMatrixT<Scalar_t>> & A, const std::vector<TMatrixT<Scalar_t>> & B);
124 
125  // copy from another architecture
126  template<typename AMatrix_t>
127  static void CopyDiffArch(std::vector<TMatrixT<Scalar_t> > & A, const std::vector<AMatrix_t> & B);
128 
129 
130  ///@}
131 
132  //____________________________________________________________________________
133  //
134  // Activation Functions
135  //____________________________________________________________________________
136 
137  /** @name Activation Functions
138  * For each activation function, the low-level interface contains two routines.
139  * One that applies the acitvation function to a matrix and one that evaluate
140  * the derivatives of the activation function at the elements of a given matrix
141  * and writes the results into the result matrix.
142  */
143  ///@{
144  static void Identity(TMatrixT<AReal> & B);
145  static void IdentityDerivative(TMatrixT<AReal> & B,
146  const TMatrixT<AReal> & A);
147 
148  static void Relu(TMatrixT<AReal> & B);
149  static void ReluDerivative(TMatrixT<AReal> & B,
150  const TMatrixT<AReal> & A);
151 
152  static void Sigmoid(TMatrixT<AReal> & B);
153  static void SigmoidDerivative(TMatrixT<AReal> & B,
154  const TMatrixT<AReal> & A);
155 
156  static void Tanh(TMatrixT<AReal> & B);
157  static void TanhDerivative(TMatrixT<AReal> & B,
158  const TMatrixT<AReal> & A);
159 
160  static void SymmetricRelu(TMatrixT<AReal> & B);
162  const TMatrixT<AReal> & A);
163 
164  static void SoftSign(TMatrixT<AReal> & B);
165  static void SoftSignDerivative(TMatrixT<AReal> & B,
166  const TMatrixT<AReal> & A);
167 
168  static void Gauss(TMatrixT<AReal> & B);
169  static void GaussDerivative(TMatrixT<AReal> & B,
170  const TMatrixT<AReal> & A);
171 
172  ///@}
173 
174  //____________________________________________________________________________
175  //
176  // Loss Functions
177  //____________________________________________________________________________
178 
179  /** @name Loss Functions
180  * Loss functions compute a scalar value given the \p output of the network
181  * for a given training input and the expected network prediction \p Y that
182  * quantifies the quality of the prediction. For each function also a routing
183  * that computes the gradients (suffixed by Gradients) must be provided for
184  * the starting of the backpropagation algorithm.
185  */
186  ///@{
187 
188  static AReal MeanSquaredError(const TMatrixT<AReal> &Y, const TMatrixT<AReal> &output,
189  const TMatrixT<AReal> &weights);
191  const TMatrixT<AReal> &weights);
192 
193  /** Sigmoid transformation is implicitly applied, thus \p output should
194  * hold the linear activations of the last layer in the net. */
195  static AReal CrossEntropy(const TMatrixT<AReal> &Y, const TMatrixT<AReal> &output, const TMatrixT<AReal> &weights);
196 
198  const TMatrixT<AReal> &weights);
199 
200  /** Softmax transformation is implicitly applied, thus \p output should
201  * hold the linear activations of the last layer in the net. */
202  static AReal SoftmaxCrossEntropy(const TMatrixT<AReal> &Y, const TMatrixT<AReal> &output,
203  const TMatrixT<AReal> &weights);
205  const TMatrixT<AReal> &output, const TMatrixT<AReal> &weights);
206  ///@}
207 
208  //____________________________________________________________________________
209  //
210  // Output Functions
211  //____________________________________________________________________________
212 
213  /** @name Output Functions
214  * Output functions transform the activations \p output of the
215  * output layer in the network to a valid prediction \p YHat for
216  * the desired usage of the network, e.g. the identity function
217  * for regression or the sigmoid transformation for two-class
218  * classification.
219  */
220  ///@{
221  static void Sigmoid(TMatrixT<AReal> &YHat,
222  const TMatrixT<AReal> & );
223  static void Softmax(TMatrixT<AReal> &YHat,
224  const TMatrixT<AReal> & );
225  ///@}
226 
227  //____________________________________________________________________________
228  //
229  // Regularization
230  //____________________________________________________________________________
231 
232  /** @name Regularization
233  * For each regularization type two functions are required, one named
234  * <tt><Type>Regularization</tt> that evaluates the corresponding
235  * regularization functional for a given weight matrix and the
236  * <tt>Add<Type>RegularizationGradients</tt>, that adds the regularization
237  * component in the gradients to the provided matrix.
238  */
239  ///@{
240 
241  static AReal L1Regularization(const TMatrixT<AReal> & W);
243  const TMatrixT<AReal> & W,
244  AReal weightDecay);
245 
246  static AReal L2Regularization(const TMatrixT<AReal> & W);
248  const TMatrixT<AReal> & W,
249  AReal weightDecay);
250  ///@}
251 
252  //____________________________________________________________________________
253  //
254  // Initialization
255  //____________________________________________________________________________
256 
257  /** @name Initialization
258  * For each initialization method, one function in the low-level interface
259  * is provided. The naming scheme is <p>Initialize<Type></p> for a given
260  * initialization method Type.
261  */
262  ///@{
263 
264  static void InitializeGauss(TMatrixT<AReal> & A);
265 
266  static void InitializeUniform(TMatrixT<AReal> & A);
267 
268  static void InitializeIdentity(TMatrixT<AReal> & A);
269 
270  static void InitializeZero(TMatrixT<AReal> & A);
271 
273 
275 
276  // return static instance of random generator used for initialization
277  // if generator does not exist it is created the first time with a random seed (e.g. seed = 0)
278  static TRandom & GetRandomGenerator();
279  // set random seed for the static geenrator
280  // if the static geneerator does not exists it is created
281  static void SetRandomSeed(size_t seed);
282 
283 
284  ///@}
285 
286  //____________________________________________________________________________
287  //
288  // Dropout
289  //____________________________________________________________________________
290 
291  /** @name Dropout
292  */
293  ///@{
294 
295  /** Apply dropout with activation probability \p p to the given
296  * matrix \p A and scale the result by reciprocal of \p p. */
297  static void Dropout(TMatrixT<AReal> & A, AReal dropoutProbability);
298 
299  ///@}
300 
301 
302  //____________________________________________________________________________
303  //
304  // Convolutional Layer Propagation
305  //____________________________________________________________________________
306 
307  /** @name Forward Propagation in Convolutional Layer
308  */
309  ///@{
310 
311  /** Transform the matrix \p B in local view format, suitable for
312  * convolution, and store it in matrix \p A. */
313  static void Im2col(TMatrixT<AReal> &A, TMatrixT<AReal> &B, size_t imgHeight, size_t imgWidth, size_t fltHeight,
314  size_t fltWidth, size_t strideRows, size_t strideCols, size_t zeroPaddingHeight,
315  size_t zeroPaddingWidth);
316  static void Im2colIndices(std::vector<int> &, const TMatrixT<AReal> &, size_t, size_t, size_t, size_t ,
317  size_t , size_t , size_t , size_t ,size_t ) {
318  Fatal("Im2ColIndices","This function is not implemented for ref architectures");
319  }
320  static void Im2colFast(TMatrixT<AReal> &, const TMatrixT<AReal> &, const std::vector<int> & ) {
321  Fatal("Im2ColFast","This function is not implemented for ref architectures");
322  }
323 
324  /** Rotates the matrix \p B, which is representing a weights,
325  * and stores them in the matrix \p A. */
326  static void RotateWeights(TMatrixT<AReal> &A, const TMatrixT<AReal> &B, size_t filterDepth, size_t filterHeight,
327  size_t filterWidth, size_t numFilters);
328 
329  /** Add the biases in the Convolutional Layer. */
330  static void AddConvBiases(TMatrixT<AReal> &output, const TMatrixT<AReal> &biases);
331  ///@}
332 
333  /** Forward propagation in the Convolutional layer */
334  // static void ConvLayerForward(std::vector<TMatrixT<AReal>> & output, std::vector<TMatrixT<AReal>> & derivatives,
335  // const std::vector<TMatrixT<AReal>> &input,
336  // const TMatrixT<AReal> & weights, const TMatrixT<AReal> & biases,
337  // EActivationFunction func, const std::vector<int> & vIndices,
338  // size_t nlocalViews, size_t nlocalViewPixels,
339  // AReal dropoutProbability, bool applyDropout) {
340  static void ConvLayerForward(std::vector<TMatrixT<AReal>> & , std::vector<TMatrixT<AReal>> &,
341  const std::vector<TMatrixT<AReal>> &,
342  const TMatrixT<AReal> & , const TMatrixT<AReal> & ,
343  EActivationFunction , const std::vector<int> &,
344  size_t , size_t,
345  AReal , bool ) {
346  Fatal("ConvLayerForward","This function is not implemented for ref architectures");
347  }
348 
349 
350  /** @name Backward Propagation in Convolutional Layer
351  */
352  ///@{
353 
354  /** Perform the complete backward propagation step in a Convolutional Layer.
355  * If the provided \p activationGradientsBackward matrix is not empty, compute the
356  * gradients of the objective function with respect to the activations
357  * of the previous layer (backward direction).
358  * Also compute the weight and the bias gradients. Modifies the values
359  * in \p df and thus produces only a valid result, if it is applied the
360  * first time after the corresponding forward propagation has been per-
361  * formed. */
362  // static void ConvLayerBackward(std::vector<TMatrixT<AReal>> &activationGradientsBackward,
363  // TMatrixT<AReal> &weightGradients, TMatrixT<AReal> &biasGradients,
364  // std::vector<TMatrixT<AReal>> &df,
365  // const std::vector<TMatrixT<AReal>> &activationGradients,
366  // const TMatrixT<AReal> &weights, const std::vector<TMatrixT<AReal>> &activationBackward,
367  // size_t batchSize, size_t inputHeight, size_t inputWidth, size_t depth, size_t height,
368  // size_t width, size_t filterDepth, size_t filterHeight, size_t filterWidth,
369  // size_t nLocalViews) {
370  static void ConvLayerBackward(std::vector<TMatrixT<AReal>> &,
372  std::vector<TMatrixT<AReal>> &,
373  const std::vector<TMatrixT<AReal>> &,
374  const TMatrixT<AReal> &, const std::vector<TMatrixT<AReal>> &,
375  size_t , size_t , size_t , size_t , size_t,
376  size_t , size_t , size_t , size_t ,
377  size_t ) {
378  Fatal("ConvLayerBackward","This function is not implemented for ref architectures");
379 
380  }
381 
382 #ifdef HAVE_CNN_REFERENCE
383  /** Utility function for calculating the activation gradients of the layer
384  * before the convolutional layer. */
385  static void CalculateConvActivationGradients(std::vector<TMatrixT<AReal>> &activationGradientsBackward,
386  const std::vector<TMatrixT<AReal>> &df, const TMatrixT<AReal> &weights,
387  size_t batchSize, size_t inputHeight, size_t inputWidth, size_t depth,
388  size_t height, size_t width, size_t filterDepth, size_t filterHeight,
389  size_t filterWidth);
390 
391  /** Utility function for calculating the weight gradients of the convolutional
392  * layer. */
393  static void CalculateConvWeightGradients(TMatrixT<AReal> &weightGradients, const std::vector<TMatrixT<AReal>> &df,
394  const std::vector<TMatrixT<AReal>> &activationBackward, size_t batchSize,
395  size_t inputHeight, size_t inputWidth, size_t depth, size_t height,
396  size_t width, size_t filterDepth, size_t filterHeight, size_t filterWidth,
397  size_t nLocalViews);
398 
399  /** Utility function for calculating the bias gradients of the convolutional
400  * layer. */
401  static void CalculateConvBiasGradients(TMatrixT<AReal> &biasGradients, const std::vector<TMatrixT<AReal>> &df,
402  size_t batchSize, size_t depth, size_t nLocalViews);
403  ///@}
404 
405 #endif
406 
407  //____________________________________________________________________________
408  //
409  // Max Pooling Layer Propagation
410  //____________________________________________________________________________
411  /** @name Forward Propagation in Max Pooling Layer
412  */
413  ///@{
414 
415  /** Downsample the matrix \p C to the matrix \p A, using max
416  * operation, such that the winning indices are stored in matrix
417  * \p B. */
418  static void Downsample(TMatrixT<AReal> &A, TMatrixT<AReal> &B, const TMatrixT<AReal> &C, size_t imgHeight,
419  size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols);
420 
421  ///@}
422 
423  /** @name Backward Propagation in Max Pooling Layer
424  */
425  ///@{
426 
427  /** Perform the complete backward propagation step in a Max Pooling Layer. Based on the
428  * winning idices stored in the index matrix, it just forwards the actiovation
429  * gradients to the previous layer. */
430  static void MaxPoolLayerBackward(std::vector<TMatrixT<AReal>> &activationGradientsBackward,
431  const std::vector<TMatrixT<AReal>> &activationGradients,
432  const std::vector<TMatrixT<AReal>> &indexMatrix, size_t batchSize, size_t depth,
433  size_t nLocalViews);
434  ///@}
435  //____________________________________________________________________________
436  //
437  // Reshape Layer Propagation
438  //____________________________________________________________________________
439  /** @name Forward and Backward Propagation in Reshape Layer
440  */
441  ///@{
442 
443  /** Transform the matrix \p B to a matrix with different dimensions \p A */
444  static void Reshape(TMatrixT<AReal> &A, const TMatrixT<AReal> &B);
445 
446  /** Flattens the tensor \p B, such that each matrix, is stretched in one row, resulting with a matrix \p A. */
447  static void Flatten(TMatrixT<AReal> &A, const std::vector<TMatrixT<AReal>> &B, size_t size, size_t nRows,
448  size_t nCols);
449 
450  /** Transforms each row of \p B to a matrix and stores it in the tensor \p B. */
451  static void Deflatten(std::vector<TMatrixT<AReal>> &A, const TMatrixT<Scalar_t> &B, size_t index, size_t nRows,
452  size_t nCols);
453  /** Rearrage data accoring to time fill B x T x D out with T x B x D matrix in*/
454  static void Rearrange(std::vector<TMatrixT<AReal>> &out, const std::vector<TMatrixT<AReal>> &in);
455 
456  ///@}
457 
458  //____________________________________________________________________________
459  //
460  // Additional Arithmetic Functions
461  //____________________________________________________________________________
462 
463  /** Sum columns of (m x n) matrixx \p A and write the results into the first
464  * m elements in \p A.
465  */
466  static void SumColumns(TMatrixT<AReal> &B, const TMatrixT<AReal> &A);
467 
468  //____________________________________________________________________________
469  //
470  // AutoEncoder Propagation
471  //____________________________________________________________________________
472 
473  // Add Biases to the output
474  static void AddBiases(TMatrixT<AReal> &A,
475  const TMatrixT<AReal> &biases);
476 
477  // Updating parameters after every backward pass. Weights and biases are
478  // updated.
479  static void
481  TMatrixT<AReal> &z, TMatrixT<AReal> &fVBiases,
482  TMatrixT<AReal> &fHBiases, TMatrixT<AReal> &fWeights,
483  TMatrixT<AReal> &VBiasError, TMatrixT<AReal> &HBiasError,
484  AReal learningRate, size_t fBatchSize);
485 
486  // Softmax functions redifined
487  static void SoftmaxAE(TMatrixT<AReal> & A);
488 
489 
490  // Corrupt the input values randomly on corruption Level.
491  //Basically inputs are masked currently.
492  static void CorruptInput(TMatrixT<AReal> & input,
493  TMatrixT<AReal> & corruptedInput,
494  AReal corruptionLevel);
495 
496  //Encodes the input Values in the compressed form.
497  static void EncodeInput(TMatrixT<AReal> &input,
498  TMatrixT<AReal> &compressedInput,
499  TMatrixT<AReal> &Weights);
500 
501  // reconstructs the input. The reconstructed Input has same dimensions as that
502  // of the input.
503  static void ReconstructInput(TMatrixT<AReal> & compressedInput,
504  TMatrixT<AReal> & reconstructedInput,
505  TMatrixT<AReal> &fWeights);
506 
507 
508  static void ForwardLogReg(TMatrixT<AReal> &input,
509  TMatrixT<AReal> &p,
510  TMatrixT<AReal> &fWeights);
511 
512  static void UpdateParamsLogReg(TMatrixT<AReal> &input,
513  TMatrixT<AReal> &output,
514  TMatrixT<AReal> &difference,
515  TMatrixT<AReal> &p,
516  TMatrixT<AReal> &fWeights,
517  TMatrixT<AReal> &fBiases,
518  AReal learningRate,
519  size_t fBatchSize);
520 
521 };
522 
523 
524 // implement the templated member functions
525 template <typename AReal>
526 template <typename AMatrix_t>
528 {
529  TMatrixT<AReal> tmp = B;
530  A = tmp;
531 }
532 
533 template <typename AReal>
534 template <typename AMatrix_t>
535 void TReference<AReal>::CopyDiffArch(std::vector<TMatrixT<AReal>> &A, const std::vector<AMatrix_t> &B)
536 {
537  for (size_t i = 0; i < A.size(); ++i) {
538  CopyDiffArch(A[i], B[i]);
539  }
540 }
541 
542 
543 
544 } // namespace DNN
545 } // namespace TMVA
546 
547 #endif
static double B[]
static void SetRandomSeed(size_t seed)
static void MaxPoolLayerBackward(std::vector< TMatrixT< AReal >> &activationGradientsBackward, const std::vector< TMatrixT< AReal >> &activationGradients, const std::vector< TMatrixT< AReal >> &indexMatrix, size_t batchSize, size_t depth, size_t nLocalViews)
Perform the complete backward propagation step in a Max Pooling Layer.
static void InitializeGlorotUniform(TMatrixT< AReal > &A)
Sample from a uniform distribution in range [ -lim,+lim] where lim = sqrt(6/N_in+N_out).
static void TanhDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static void IdentityDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static void AddConvBiases(TMatrixT< AReal > &output, const TMatrixT< AReal > &biases)
Add the biases in the Convolutional Layer.
static void Im2col(TMatrixT< AReal > &A, TMatrixT< AReal > &B, size_t imgHeight, size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols, size_t zeroPaddingHeight, size_t zeroPaddingWidth)
Transform the matrix B in local view format, suitable for convolution, and store it in matrix A...
static void Tanh(TMatrixT< AReal > &B)
static void ForwardLogReg(TMatrixT< AReal > &input, TMatrixT< AReal > &p, TMatrixT< AReal > &fWeights)
static void ConvLayerForward(std::vector< TMatrixT< AReal >> &, std::vector< TMatrixT< AReal >> &, const std::vector< TMatrixT< AReal >> &, const TMatrixT< AReal > &, const TMatrixT< AReal > &, EActivationFunction, const std::vector< int > &, size_t, size_t, AReal, bool)
Forward propagation in the Convolutional layer.
Definition: Reference.h:340
void Fatal(const char *location, const char *msgfmt,...)
static Matrix_t & RecurrentLayerBackward(TMatrixT< Scalar_t > &state_gradients_backward, TMatrixT< Scalar_t > &input_weight_gradients, TMatrixT< Scalar_t > &state_weight_gradients, TMatrixT< Scalar_t > &bias_gradients, TMatrixT< Scalar_t > &df, const TMatrixT< Scalar_t > &state, const TMatrixT< Scalar_t > &weights_input, const TMatrixT< Scalar_t > &weights_state, const TMatrixT< Scalar_t > &input, TMatrixT< Scalar_t > &input_gradient)
Backpropagation step for a Recurrent Neural Network.
image html pict1_TGaxis_012 png width
Define new text attributes for the label number "labNum".
Definition: TGaxis.cxx:2551
static void Im2colIndices(std::vector< int > &, const TMatrixT< AReal > &, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t)
Definition: Reference.h:316
static AReal SoftmaxCrossEntropy(const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
Softmax transformation is implicitly applied, thus output should hold the linear activations of the l...
static void Sigmoid(TMatrixT< AReal > &B)
static AReal CrossEntropy(const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
Sigmoid transformation is implicitly applied, thus output should hold the linear activations of the l...
static void SigmoidDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static void SoftSign(TMatrixT< AReal > &B)
static void Identity(TMatrixT< AReal > &B)
static void SymmetricReluDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static double A[]
double beta(double x, double y)
Calculates the beta function.
static void Im2colFast(TMatrixT< AReal > &, const TMatrixT< AReal > &, const std::vector< int > &)
Definition: Reference.h:320
static void AddL2RegularizationGradients(TMatrixT< AReal > &A, const TMatrixT< AReal > &W, AReal weightDecay)
Double_t x[n]
Definition: legend1.C:17
double weightDecay(double error, ItWeight itWeight, ItWeight itWeightEnd, double factorWeightDecay, EnumRegularization eRegularization)
compute the weight decay for regularization (L1 or L2)
Definition: NeuralNet.icc:496
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
static void SoftmaxAE(TMatrixT< AReal > &A)
static void Flatten(TMatrixT< AReal > &A, const std::vector< TMatrixT< AReal >> &B, size_t size, size_t nRows, size_t nCols)
Flattens the tensor B, such that each matrix, is stretched in one row, resulting with a matrix A...
static void Copy(TMatrixT< Scalar_t > &A, const TMatrixT< Scalar_t > &B)
Definition: Propagation.cxx:86
static TRandom & GetRandomGenerator()
static void SoftmaxCrossEntropyGradients(TMatrixT< AReal > &dY, const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
static void ReconstructInput(TMatrixT< AReal > &compressedInput, TMatrixT< AReal > &reconstructedInput, TMatrixT< AReal > &fWeights)
static void ConvLayerBackward(std::vector< TMatrixT< AReal >> &, TMatrixT< AReal > &, TMatrixT< AReal > &, std::vector< TMatrixT< AReal >> &, const std::vector< TMatrixT< AReal >> &, const TMatrixT< AReal > &, const std::vector< TMatrixT< AReal >> &, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t, size_t)
Perform the complete backward propagation step in a Convolutional Layer.
Definition: Reference.h:370
static void Reshape(TMatrixT< AReal > &A, const TMatrixT< AReal > &B)
Transform the matrix B to a matrix with different dimensions A.
static void RotateWeights(TMatrixT< AReal > &A, const TMatrixT< AReal > &B, size_t filterDepth, size_t filterHeight, size_t filterWidth, size_t numFilters)
Rotates the matrix B, which is representing a weights, and stores them in the matrix A...
static AReal L1Regularization(const TMatrixT< AReal > &W)
static void InitializeUniform(TMatrixT< AReal > &A)
static void AddL1RegularizationGradients(TMatrixT< AReal > &A, const TMatrixT< AReal > &W, AReal weightDecay)
static void InitializeGlorotNormal(TMatrixT< AReal > &A)
Truncated normal initialization (Glorot, called also Xavier normal) The values are sample with a norm...
static void Backward(TMatrixT< Scalar_t > &activationGradientsBackward, TMatrixT< Scalar_t > &weightGradients, TMatrixT< Scalar_t > &biasGradients, TMatrixT< Scalar_t > &df, const TMatrixT< Scalar_t > &activationGradients, const TMatrixT< Scalar_t > &weights, const TMatrixT< Scalar_t > &activationBackward)
Perform the complete backward propagation step.
Definition: Propagation.cxx:40
static void Relu(TMatrixT< AReal > &B)
static void SymmetricRelu(TMatrixT< AReal > &B)
static double C[]
static void InitializeZero(TMatrixT< AReal > &A)
static void Deflatten(std::vector< TMatrixT< AReal >> &A, const TMatrixT< Scalar_t > &B, size_t index, size_t nRows, size_t nCols)
Transforms each row of B to a matrix and stores it in the tensor B.
static void CorruptInput(TMatrixT< AReal > &input, TMatrixT< AReal > &corruptedInput, AReal corruptionLevel)
static AReal L2Regularization(const TMatrixT< AReal > &W)
static void ReluDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static void AddBiases(TMatrixT< AReal > &A, const TMatrixT< AReal > &biases)
static void SumColumns(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
Sum columns of (m x n) matrixx A and write the results into the first m elements in A...
static void CrossEntropyGradients(TMatrixT< AReal > &dY, const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
static void UpdateParamsLogReg(TMatrixT< AReal > &input, TMatrixT< AReal > &output, TMatrixT< AReal > &difference, TMatrixT< AReal > &p, TMatrixT< AReal > &fWeights, TMatrixT< AReal > &fBiases, AReal learningRate, size_t fBatchSize)
static void GaussDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
static void Softmax(TMatrixT< AReal > &YHat, const TMatrixT< AReal > &)
static TRandom * fgRandomGen
Definition: Reference.h:46
static void Downsample(TMatrixT< AReal > &A, TMatrixT< AReal > &B, const TMatrixT< AReal > &C, size_t imgHeight, size_t imgWidth, size_t fltHeight, size_t fltWidth, size_t strideRows, size_t strideCols)
Downsample the matrix C to the matrix A, using max operation, such that the winning indices are store...
Double_t y[n]
Definition: legend1.C:17
static void ScaleAdd(TMatrixT< Scalar_t > &A, const TMatrixT< Scalar_t > &B, Scalar_t beta=1.0)
Adds a the elements in matrix B scaled by c to the elements in the matrix A.
Definition: Propagation.cxx:76
static void EncodeInput(TMatrixT< AReal > &input, TMatrixT< AReal > &compressedInput, TMatrixT< AReal > &Weights)
static void InitializeIdentity(TMatrixT< AReal > &A)
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
static void SoftSignDerivative(TMatrixT< AReal > &B, const TMatrixT< AReal > &A)
Abstract ClassifierFactory template that handles arbitrary types.
static void InitializeGauss(TMatrixT< AReal > &A)
EActivationFunction
Enum that represents layer activation functions.
Definition: Functions.h:31
static void CopyDiffArch(TMatrixT< Scalar_t > &A, const AMatrix_t &B)
Definition: Reference.h:527
static void Rearrange(std::vector< TMatrixT< AReal >> &out, const std::vector< TMatrixT< AReal >> &in)
Rearrage data accoring to time fill B x T x D out with T x B x D matrix in.
static void MultiplyTranspose(TMatrixT< Scalar_t > &output, const TMatrixT< Scalar_t > &input, const TMatrixT< Scalar_t > &weights)
Matrix-multiply input with the transpose of and write the results into output.
Definition: Propagation.cxx:23
static void MeanSquaredErrorGradients(TMatrixT< AReal > &dY, const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
static void AddRowWise(TMatrixT< Scalar_t > &output, const TMatrixT< Scalar_t > &biases)
Add the vectors biases row-wise to the matrix output.
Definition: Propagation.cxx:30
static void Gauss(TMatrixT< AReal > &B)
static AReal MeanSquaredError(const TMatrixT< AReal > &Y, const TMatrixT< AReal > &output, const TMatrixT< AReal > &weights)
static void Dropout(TMatrixT< AReal > &A, AReal dropoutProbability)
Apply dropout with activation probability p to the given matrix A and scale the result by reciprocal ...
Definition: Dropout.cxx:29
static void UpdateParams(TMatrixT< AReal > &x, TMatrixT< AReal > &tildeX, TMatrixT< AReal > &y, TMatrixT< AReal > &z, TMatrixT< AReal > &fVBiases, TMatrixT< AReal > &fHBiases, TMatrixT< AReal > &fWeights, TMatrixT< AReal > &VBiasError, TMatrixT< AReal > &HBiasError, AReal learningRate, size_t fBatchSize)