Logo ROOT   6.12/07
Reference Guide
Initialization.cxx
Go to the documentation of this file.
1 // @(#)root/tmva/tmva/dnn:$Id$
2 // Author: Simon Pfreundschuh 21/07/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  // Implementation of the DNN initialization methods for the //
14  // multi-threaded CPU backend. //
15  //////////////////////////////////////////////////////////////
16 
17 #include "TRandom.h"
19 
20 namespace TMVA
21 {
22 namespace DNN
23 {
24 
25 //______________________________________________________________________________
26 template<typename AFloat>
28 {
29  size_t m,n;
30  m = A.GetNrows();
31  n = A.GetNcols();
32 
33  TRandom rand(time(nullptr));
34 
35  AFloat sigma = sqrt(2.0 / ((AFloat) n));
36 
37  for (size_t i = 0; i < m; i++) {
38  for (size_t j = 0; j < n; j++) {
39  A(i,j) = rand.Gaus(0.0, sigma);
40  }
41  }
42 }
43 
44 //______________________________________________________________________________
45 template<typename AFloat>
47 {
48  size_t m,n;
49  m = A.GetNrows();
50  n = A.GetNcols();
51 
52  TRandom rand(time(nullptr));
53 
54  AFloat range = sqrt(2.0 / ((AFloat) n));
55 
56  for (size_t i = 0; i < m; i++) {
57  for (size_t j = 0; j < n; j++) {
58  A(i,j) = rand.Uniform(-range, range);
59  }
60  }
61 }
62 
63 //______________________________________________________________________________
64 template<typename AFloat>
66 {
67  size_t m,n;
68  m = A.GetNrows();
69  n = A.GetNcols();
70 
71  for (size_t i = 0; i < m; i++) {
72  for (size_t j = 0; j < n ; j++) {
73  A(i,j) = 0.0;
74  }
75 
76  if (i < n) {
77  A(i,i) = 1.0;
78  }
79  }
80 }
81 
82 //______________________________________________________________________________
83 template<typename AFloat>
85 {
86  size_t m,n;
87  m = A.GetNrows();
88  n = A.GetNcols();
89 
90  for (size_t i = 0; i < m; i++) {
91  for (size_t j = 0; j < n ; j++) {
92  A(i,j) = 0.0;
93  }
94  }
95 }
96 
97 } // namespace DNN
98 } // namespace TMVA
The TCpuMatrix class.
Definition: CpuMatrix.h:46
auto * m
Definition: textangle.C:8
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:256
size_t GetNcols() const
Definition: CpuMatrix.h:93
static void InitializeIdentity(TCpuMatrix< Scalar_t > &A)
static void InitializeUniform(TCpuMatrix< Scalar_t > &A)
static double A[]
double sqrt(double)
static void InitializeGauss(TCpuMatrix< Scalar_t > &A)
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
const Double_t sigma
static void InitializeZero(TCpuMatrix< Scalar_t > &A)
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
Abstract ClassifierFactory template that handles arbitrary types.
size_t GetNrows() const
Definition: CpuMatrix.h:92
const Int_t n
Definition: legend1.C:16