Logo ROOT   6.14/05
Reference Guide
Dropout.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 
13 #include "TRandom.h"
14 
15 /////////////////////////////////////////////////////////////////////
16 // Implementation of Dropout for multi-threaded CPU architectures. //
17 /////////////////////////////////////////////////////////////////////
18 
19 namespace TMVA {
20 namespace DNN {
21 
22 //____________________________________________________________________________
23 template<typename AFloat>
25  AFloat dropoutProbability)
26 {
27  AFloat *data = A.GetRawDataPointer();
28 
29  auto f = [&data, dropoutProbability](UInt_t workerID)
30  {
31  TRandom rand(time(nullptr) + workerID);
32  AFloat r = rand.Uniform();
33  data[workerID] = (r > dropoutProbability) ? 0.0 : data[workerID] / dropoutProbability;
34  return 0;
35  };
36 
38 }
39 
40 } // namespace DNN
41 } // namespace TMVA
The TCpuMatrix class.
Definition: CpuMatrix.h:72
#define f(i)
Definition: RSha256.hxx:104
static double A[]
size_t GetNElements() const
Definition: CpuMatrix.h:128
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
static void Dropout(TCpuMatrix< Scalar_t > &A, Scalar_t p)
Apply dropout with activation probability p to the given matrix A and scale the result by reciprocal ...
Definition: Dropout.cxx:24
ROOT::R::TRInterface & r
Definition: Object.C:4
unsigned int UInt_t
Definition: RtypesCore.h:42
static ROOT::TThreadExecutor & GetThreadExecutor()
Definition: CpuMatrix.h:139
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
Definition: CpuMatrix.h:136
A pseudo container class which is a generator of indices.
Definition: TSeq.hxx:66
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:627
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.