Logo ROOT   6.08/07
Reference Guide
TestActivationFunctionsCpu.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Simon Pfreundschuh
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 // Concrete instantiation of the generic activation function test //
14 // for the multi-threaded CPU implementation. //
15 //////////////////////////////////////////////////////////////////////
16 
17 #include <iostream>
19 #include "Utility.h"
21 
22 using namespace TMVA::DNN;
23 
24 int main()
25 {
26  using Scalar_t = Double_t;
27 
28  std::cout << "Testing Activation Functions:" << std::endl;
29 
30  double error;
31 
32  // Identity.
33 
34  error = testIdentity<TCpu<Scalar_t>>(10);
35  std::cout << "Testing identity activation: ";
36  std::cout << "maximum relative error = " << error << std::endl;
37  if (error > 1e-10)
38  return 1;
39 
40  error = testIdentityDerivative<TCpu<Scalar_t>>(10);
41  std::cout << "Testing identity activation derivative: ";
42  std::cout << "maximum relative error = " << error << std::endl;
43  if (error > 1e-10)
44  return 1;
45 
46  // ReLU.
47 
48  error = testRelu<TCpu<Scalar_t>>(10);
49  std::cout << "Testing ReLU activation: ";
50  std::cout << "maximum relative error = " << error << std::endl;
51  if (error > 1e-10)
52  return 1;
53 
54  error = testReluDerivative<TCpu<Scalar_t>>(10);
55  std::cout << "Testing ReLU activation derivative: ";
56  std::cout << "maximum relative error = " << error << std::endl;
57  if (error > 1e-10)
58  return 1;
59 
60  // Sigmoid.
61 
62  error = testSigmoid<TCpu<Scalar_t>>(10);
63  std::cout << "Testing Sigmoid activation: ";
64  std::cout << "maximum relative error = " << error << std::endl;
65  if (error > 1e-10)
66  return 1;
67 
68  error = testSigmoidDerivative<TCpu<Scalar_t>>(10);
69  std::cout << "Testing Sigmoid activation derivative: ";
70  std::cout << "maximum relative error = " << error << std::endl;
71  if (error > 1e-10)
72  return 1;
73 
74  // TanH.
75 
76  error = testTanh<TCpu<Scalar_t>>(10);
77  std::cout << "Testing TanH activation: ";
78  std::cout << "maximum relative error = " << print_error(error) << std::endl;
79  if (error > 1e-10)
80  return 1;
81 
82  error = testTanhDerivative<TCpu<Scalar_t>>(10);
83  std::cout << "Testing TanH activation derivative: ";
84  std::cout << "maximum relative error = " << print_error(error) << std::endl;
85  if (error > 1e-10)
86  return 1;
87 
88  // Symmetric ReLU.
89 
90  error = testSymmetricRelu<TCpu<Scalar_t>>(10);
91  std::cout << "Testing Symm. ReLU activation: ";
92  std::cout << "maximum relative error = " << print_error(error) << std::endl;
93  if (error > 1e-10)
94  return 1;
95 
96  error = testSymmetricReluDerivative<TCpu<Scalar_t>>(10);
97  std::cout << "Testing Symm. ReLU activation derivative: ";
98  std::cout << "maximum relative error = " << print_error(error) << std::endl;
99  if (error > 1e-10)
100  return 1;
101 
102  // Soft Sign.
103 
104  error = testSoftSign<TCpu<Scalar_t>>(10);
105  std::cout << "Testing Soft Sign activation: ";
106  std::cout << "maximum relative error = " << print_error(error) << std::endl;
107  if (error > 1e-10)
108  return 1;
109 
110  error = testSoftSignDerivative<TCpu<Scalar_t>>(10);
111  std::cout << "Testing Soft Sign activation derivative: ";
112  std::cout << "maximum relative error = " << print_error(error) << std::endl;
113  if (error > 1e-10)
114  return 1;
115 
116  // Gauss.
117 
118  error = testGauss<TCpu<Scalar_t>>(10);
119  std::cout << "Testing Gauss activation: ";
120  std::cout << "maximum relative error = " << print_error(error) << std::endl;
121  if (error > 1e-10)
122  return 1;
123 
124  error = testGaussDerivative<TCpu<Scalar_t>>(10);
125  std::cout << "Testing Gauss activation derivative: ";
126  std::cout << "maximum relative error = " << print_error(error) << std::endl;
127  if (error > 1e-10)
128  return 1;
129 
130  return 0;
131 }
Definition: Blas.h:58
std::string print_error(AFloat &e)
Color code error.
Definition: Utility.h:232
double Double_t
Definition: RtypesCore.h:55
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630