Logo ROOT   6.10/09
Reference Guide
OutputFunctions.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 output functions for multi-threaded CPU //
14 // architectures. //
15 ///////////////////////////////////////////////////////////////
16 
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>
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 
54 }
55 
56 } // namespace DNN
57 } // namespace TMVA
static double B[]
static void Sigmoid(TCpuMatrix< Scalar_t > &B)
static long int sum(long int i)
Definition: Factory.cxx:2162
The TCpuMatrix class.
Definition: CpuMatrix.h:46
size_t GetNcols() const
Definition: CpuMatrix.h:94
static double A[]
Double_t x[n]
Definition: legend1.C:17
unsigned int UInt_t
Definition: RtypesCore.h:42
TMarker * m
Definition: textangle.C:8
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
Definition: CpuMatrix.h:103
double f(double x)
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
ROOT::TThreadExecutor & GetThreadExecutor() const
Definition: CpuMatrix.h:106
Abstract ClassifierFactory template that handles arbitrary types.
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute func (with no arguments) nTimes in parallel.
size_t GetNrows() const
Definition: CpuMatrix.h:93
static void Softmax(TCpuMatrix< Scalar_t > &YHat, const TCpuMatrix< Scalar_t > &)
double exp(double)
const Int_t n
Definition: legend1.C:16