Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
OutputFunctions.hxx
Go to the documentation of this file.
1 // @(#)root/tmva/tmva/dnn:$Id$
2 // Author: Simon Pfreundschuh 11/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 // Explicit instantiation of the TReference architecture class //
14 // template for Double_t scalar types. //
15 ////////////////////////////////////////////////////////////////
16 
18 
19 namespace TMVA {
20 namespace DNN {
21 
22 template<typename AReal>
23 void TReference<AReal>::Sigmoid(TMatrixT<AReal> & B,
24  const TMatrixT<AReal> & A)
25 {
26  size_t m,n;
27  m = A.GetNrows();
28  n = A.GetNcols();
29 
30  for (size_t i = 0; i < m; i++) {
31  for (size_t j = 0; j < n; j++) {
32  AReal sig = 1.0 / (1.0 + std::exp(-A(i,j)));
33  B(i,j) = sig;
34  }
35  }
36 }
37 
38 template<typename AReal>
39 void TReference<AReal>::Softmax(TMatrixT<AReal> & B,
40  const TMatrixT<AReal> & A)
41 {
42  size_t m,n;
43  m = A.GetNrows();
44  n = A.GetNcols();
45 
46  for (size_t i = 0; i < m; i++) {
47  AReal sum = 0.0;
48  for (size_t j = 0; j < n; j++) {
49  sum += exp(A(i,j));
50  }
51  for (size_t j = 0; j < n; j++) {
52  B(i,j) = exp(A(i,j)) / sum;
53  }
54  }
55 }
56 
57 } // namespace TMVA
58 } // namespace DNN