ROOT
master
Reference Guide
OutputFunctions.hxx
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 output functions for multi-threaded CPU //
14
// architectures. //
15
///////////////////////////////////////////////////////////////
16
17
#include "
TMVA/DNN/Architectures/Cpu.h
"
18
19
namespace
TMVA
20
{
21
namespace
DNN
22
{
23
24
template
<
typename
AFloat>
25
void
TCpu<AFloat>::Sigmoid
(TCpuMatrix<AFloat> &
B
,
26
const
TCpuMatrix<AFloat> &
A
)
27
{
28
auto
f
= [](AFloat
x
) {
return
1.0 / (1.0 +
exp
(-
x
));};
29
B
.MapFrom(
f
,
A
);
30
}
31
32
template
<
typename
AFloat>
33
void
TCpu<AFloat>::Softmax
(
TCpuMatrix<AFloat>
&
B
,
34
const
TCpuMatrix<AFloat>
&
A
)
35
{
36
const
AFloat *dataA =
A
.GetRawDataPointer();
37
AFloat *dataB =
B
.GetRawDataPointer();
38
size_t
n
=
A
.GetNcols();
39
size_t
m
=
A
.GetNrows();
40
41
auto
f
= [&dataA, &dataB,
n
,
m
](
UInt_t
workerID)
42
{
43
AFloat
sum
= 0.0;
44
for
(
size_t
i = 0; i <
n
; i++) {
45
sum
+=
exp
(dataA[workerID + i *
m
]);
46
}
47
for
(
size_t
i = 0; i <
n
; i++) {
48
dataB[workerID + i *
m
] =
exp
(dataA[workerID + i *
m
]) /
sum
;
49
}
50
return
0;
51
};
52
53
B
.GetThreadExecutor().Map(
f
,
ROOT::TSeqI
(
A
.GetNrows()));
54
}
55
56
}
// namespace DNN
57
}
// namespace TMVA
Cpu.h
m
auto * m
Definition:
textangle.C:8
n
const Int_t n
Definition:
legend1.C:16
f
#define f(i)
Definition:
RSha256.hxx:104
TMVA::DNN::TCpuMatrix
The TCpuMatrix class.
Definition:
CpuMatrix.h:86
sum
static uint64_t sum(uint64_t i)
Definition:
Factory.cxx:2345
exp
double exp(double)
x
Double_t x[n]
Definition:
legend1.C:17
ROOT::Math::Cephes::A
static double A[]
Definition:
SpecFuncCephes.cxx:170
TMVA::DNN::TCpu::Sigmoid
static void Sigmoid(Tensor_t &B)
unsigned int
TMVA::DNN::TCpu::Softmax
static void Softmax(Matrix_t &YHat, const Matrix_t &)
Definition:
OutputFunctions.hxx:33
ROOT::TSeq
A pseudo container class which is a generator of indices.
Definition:
TSeq.hxx:66
ROOT::Math::Cephes::B
static double B[]
Definition:
SpecFuncCephes.cxx:178
TMVA
create variable transformations
Definition:
GeneticMinimizer.h:22
tmva
tmva
src
DNN
Architectures
Cpu
OutputFunctions.hxx
ROOT master - Reference Guide Generated on Wed Apr 14 2021 11:15:01 (GVA Time) using Doxygen 1.9.0