22 #define TANH_IMPL_X vdt::fast_tanhf(x)
24 #define TANH_IMPL_X tanh(x)
34 template<
typename AFloat>
35 void TCpu<AFloat>::ActivationFunctionForward(Tensor_t & X, EActivationFunction activFunct,
36 const ActivationDescriptor_t ,
37 const double ,
const AFloat ,
const AFloat )
40 TMVA::DNN::evaluate<TCpu<AFloat>>( X, activFunct);
43 template<
typename AFloat>
44 void TCpu<AFloat>::ActivationFunctionBackward(Tensor_t & dX,
const Tensor_t & ,
45 const Tensor_t & dY,
const Tensor_t & X,
46 EActivationFunction activFunct,
47 const ActivationDescriptor_t ,
48 const AFloat ,
const AFloat )
53 TMVA::DNN::evaluateDerivative<TCpu<AFloat>>(dX, activFunct, X);
58 template<
typename AFloat>
59 void TCpu<AFloat>::IdentityDerivative(TCpuTensor<AFloat> & B,
60 const TCpuTensor<AFloat> &)
62 auto f = [](AFloat) {
return 1.0;};
67 template<
typename AFloat>
68 void TCpu<AFloat>::Relu(TCpuTensor<AFloat> & B)
70 auto f = [](AFloat x) {
return (x < 0.0) ? 0.0 : x;};
75 template<
typename AFloat>
76 void TCpu<AFloat>::ReluDerivative(TCpuTensor<AFloat> & B,
77 const TCpuTensor<AFloat> &A)
79 auto f = [](AFloat x) {
return (x < 0.0) ? 0.0 : 1.0;};
84 template<
typename AFloat>
85 void TCpu<AFloat>::Sigmoid(TCpuTensor<AFloat> & B)
87 auto f = [](AFloat x) {
return 1.0 / (1.0 + exp(-x));};
92 template<
typename AFloat>
93 void TCpu<AFloat>::SigmoidDerivative(TCpuTensor<AFloat> & B,
94 const TCpuTensor<AFloat> &A)
96 auto f = [](AFloat x) {
97 AFloat sig = 1.0 / (1.0 + exp(-x));
98 return sig * (1.0 - sig);
104 template<
typename AFloat>
105 void TCpu<AFloat>::Tanh(TCpuTensor<AFloat> & B)
107 auto f = [](AFloat x) {
return TANH_IMPL_X;};
112 template<
typename AFloat>
113 void TCpu<AFloat>::TanhDerivative(TCpuTensor<AFloat> & B,
114 const TCpuTensor<AFloat> &A)
116 auto f = [](AFloat x) {
117 AFloat t = TANH_IMPL_X;
124 template<
typename AFloat>
125 void TCpu<AFloat>::SymmetricRelu(TCpuTensor<AFloat> & B)
127 auto f = [](AFloat x) {
return fabs(x);};
132 template<
typename AFloat>
133 void TCpu<AFloat>::SymmetricReluDerivative(TCpuTensor<AFloat> & B,
134 const TCpuTensor<AFloat> &A)
136 auto f = [](AFloat x) {
137 return (x < 0.0) ? -1.0 : 1.0;
143 template<
typename AFloat>
144 void TCpu<AFloat>::SoftSign(TCpuTensor<AFloat> & B)
146 auto f = [](AFloat x) {
return x / (1 + fabs(x));};
151 template<
typename AFloat>
152 void TCpu<AFloat>::SoftSignDerivative(TCpuTensor<AFloat> & B,
153 const TCpuTensor<AFloat> &A)
155 auto f = [](AFloat x) {
164 template<
typename AFloat>
165 void TCpu<AFloat>::Gauss(TCpuTensor<AFloat> & B)
167 auto f = [](AFloat x) {
return exp(- x * x);};
172 template<
typename AFloat>
173 void TCpu<AFloat>::GaussDerivative(TCpuTensor<AFloat> & B,
174 const TCpuTensor<AFloat> &A)
176 auto f = [](AFloat x) {
return - 2.0 * x * exp(- x * x);};