15 static std::default_random_engine generator;
16 std::normal_distribution<double> distribution (mean, sigma);
17 return distribution (generator);
23 static std::default_random_engine generator;
24 std::uniform_real_distribution<double> distribution(minValue, maxValue);
25 return distribution(generator);
32 static std::default_random_engine generator;
33 std::uniform_int_distribution<int> distribution(0,maxValue-1);
34 return distribution(generator);
40 static std::default_random_engine generator;
41 std::student_t_distribution<double> distribution (distributionParameter);
42 return distribution (generator);
47 : m_hasDropOut (false)
48 , m_isInputLayer (true)
49 , m_hasWeights (false)
50 , m_hasGradients (false)
68 m_size = std::distance (itInputBegin, itInputEnd);
78 std::shared_ptr<std::function<
double(
double)>> _activationFunction,
79 std::shared_ptr<std::function<
double(
double)>> _inverseActivationFunction,
101 std::shared_ptr<std::function<
double(
double)>> _activationFunction,
123 std::transform (begin (
m_values), end (
m_values), std::back_inserter (probabilitiesContainer), (*
Sigmoid.get ()));
129 std::for_each (begin (probabilitiesContainer), end (probabilitiesContainer), [&sum](
double& p){ p =
std::exp (p); sum += p; });
131 std::for_each (begin (probabilitiesContainer), end (probabilitiesContainer), [sum ](
double& p){ p /=
sum; });
137 return probabilitiesContainer;
145 : m_numNodes (_numNodes)
146 , m_eModeOutputValues (eModeOutputValues)
147 , m_activationFunctionType (_activationFunction)
149 for (
size_t iNode = 0; iNode < _numNodes; ++iNode)
153 switch (_activationFunction)
211 size_t _convergenceSteps,
size_t _batchSize,
size_t _testRepetitions,
214 double _momentum,
int _repetitions,
bool _useMultithreading)
215 : m_timer (100, name)
217 , m_maxProgress (100)
218 , m_convergenceSteps (_convergenceSteps)
219 , m_batchSize (_batchSize)
220 , m_testRepetitions (_testRepetitions)
221 , m_factorWeightDecay (_factorWeightDecay)
226 , m_regularization (eRegularization)
227 , fLearningRate (_learningRate)
228 , fMomentum (_momentum)
229 , fRepetitions (_repetitions)
230 , fMinimizerType (_eMinimizerType)
231 , m_convergenceCount (0)
232 , m_maxConvergenceCount (0)
234 , m_useMultithreading (_useMultithreading)
263 create (
"ROC", 100, 0, 1, 100, 0, 1);
264 create (
"Significance", 100, 0, 1, 100, 0, 3);
265 create (
"OutputSig", 100, 0, 1);
266 create (
"OutputBkg", 100, 0, 1);
285 m_output.push_back (output);
286 m_targets.push_back (target);
287 m_weights.push_back (weight);
306 if (m_output.empty ())
308 double minVal = *std::min_element (begin (m_output), end (m_output));
309 double maxVal = *std::max_element (begin (m_output), end (m_output));
310 const size_t numBinsROC = 1000;
311 const size_t numBinsData = 100;
313 std::vector<double> truePositives (numBinsROC+1, 0);
314 std::vector<double> falsePositives (numBinsROC+1, 0);
315 std::vector<double> trueNegatives (numBinsROC+1, 0);
316 std::vector<double> falseNegatives (numBinsROC+1, 0);
318 std::vector<double>
x (numBinsData, 0);
319 std::vector<double> datSig (numBinsData+1, 0);
320 std::vector<double> datBkg (numBinsData+1, 0);
322 double binSizeROC = (maxVal - minVal)/(
double)numBinsROC;
323 double binSizeData = (maxVal - minVal)/(
double)numBinsData;
325 double sumWeightsSig = 0.0;
326 double sumWeightsBkg = 0.0;
328 for (
size_t b = 0;
b < numBinsData; ++
b)
330 double binData = minVal +
b*binSizeData;
334 if (
fabs(binSizeROC) < 0.0001)
337 for (
size_t i = 0, iEnd = m_output.size (); i < iEnd; ++i)
339 double val = m_output.at (i);
340 double truth = m_targets.at (i);
341 double weight = m_weights.at (i);
343 bool isSignal = (truth > 0.5 ? true :
false);
345 if (m_sumOfSigWeights != 0 && m_sumOfBkgWeights != 0)
348 weight *= m_sumOfSigWeights;
350 weight *= m_sumOfBkgWeights;
353 size_t binROC = (val-minVal)/binSizeROC;
354 size_t binData = (val-minVal)/binSizeData;
358 for (
size_t n = 0;
n <= binROC; ++
n)
360 truePositives.at (
n) += weight;
362 for (
size_t n = binROC+1;
n < numBinsROC; ++
n)
364 falseNegatives.at (
n) += weight;
367 datSig.at (binData) += weight;
368 sumWeightsSig += weight;
372 for (
size_t n = 0;
n <= binROC; ++
n)
374 falsePositives.at (
n) += weight;
376 for (
size_t n = binROC+1;
n < numBinsROC; ++
n)
378 trueNegatives.at (
n) += weight;
381 datBkg.at (binData) += weight;
382 sumWeightsBkg += weight;
386 std::vector<double> sigEff;
387 std::vector<double> backRej;
389 double bestSignificance = 0;
390 double bestCutSignificance = 0;
392 double numEventsScaleFactor = 1.0;
393 if (m_scaleToNumEvents > 0)
395 size_t numEvents = m_output.size ();
396 numEventsScaleFactor = double (m_scaleToNumEvents)/double (numEvents);
400 clear (
"Significance");
402 for (
size_t i = 0; i < numBinsROC; ++i)
404 double tp = truePositives.at (i) * numEventsScaleFactor;
405 double fp = falsePositives.at (i) * numEventsScaleFactor;
406 double tn = trueNegatives.at (i) * numEventsScaleFactor;
407 double fn = falseNegatives.at (i) * numEventsScaleFactor;
409 double seff = (tp+fn == 0.0 ? 1.0 : (tp / (tp+fn)));
410 double brej = (tn+fp == 0.0 ? 0.0 : (tn / (tn+fp)));
412 sigEff.push_back (seff);
413 backRej.push_back (brej);
419 double currentCut = (i * binSizeROC)+minVal;
423 double significance = sig /
sqrt (sig + bkg);
424 if (significance > bestSignificance)
426 bestSignificance = significance;
427 bestCutSignificance = currentCut;
430 addPoint (
"Significance", currentCut, significance);
434 m_significances.push_back (bestSignificance);
435 static size_t testCycle = 0;
439 for (
size_t i = 0; i < numBinsData; ++i)
441 addPoint (
"OutputSig", x.at (i), datSig.at (i)/sumWeightsSig);
442 addPoint (
"OutputBkg", x.at (i), datBkg.at (i)/sumWeightsBkg);
459 m_cutValue = bestCutSignificance;
495 m_sumOfSigWeights = sumOfSigWeights; m_sumOfBkgWeights = sumOfBkgWeights;
502 std::string _fileNameNetConfig,
503 std::string _fileNameResult,
504 std::vector<Pattern>* _resultPatternContainer)
506 m_pResultPatternContainer = _resultPatternContainer;
507 m_fileNameResult = _fileNameResult;
508 m_fileNameNetConfig = _fileNameNetConfig;
525 size_t prevNodes (inputSize ());
526 for (
auto& layer : m_layers)
528 if (index >= trainingStartLayer)
529 num += layer.numWeights (prevNodes);
530 prevNodes = layer.numNodes ();
541 for (
auto& layer : m_layers)
543 if (index >= trainingStartLayer)
544 num += layer.numNodes ();
555 size_t numDrops = dropFraction * _numNodes;
556 if (numDrops >= _numNodes)
557 numDrops = _numNodes - 1;
558 dropContainer.insert (end (dropContainer), _numNodes-numDrops,
true);
559 dropContainer.insert (end (dropContainer), numDrops,
false);
561 std::random_shuffle (end (dropContainer)-_numNodes, end (dropContainer));
void addPoint(std::string histoName, double x)
for monitoring
void setWeightSums(double sumOfSigWeights, double sumOfBkgWeights)
set the weight sums to be scaled to (preparations for monitoring output)
static std::shared_ptr< std::function< double(double)> > InvGauss
static long int sum(long int i)
MinimizerType
< list all the minimizer types
static std::shared_ptr< std::function< double(double)> > Tanh
std::vector< char > DropContainer
static std::shared_ptr< std::function< double(double)> > InvReLU
std::shared_ptr< std::function< double(double)> > m_inverseActivationFunction
stores the inverse activation function
bool isFlagSet(T flag, T value)
static std::shared_ptr< std::function< double(double)> > InvTanh
size_t convergenceSteps() const
how many steps until training is deemed to have converged
std::shared_ptr< Monitoring > fMonitoring
void plot(std::string histoName, std::string options, int pad, EColor color)
for monitoring
iterator_type m_itGradientBegin
iterator to the first gradient of this layer in the gradient vector
bool m_hasGradients
does this layer have gradients (only if in training mode)
ModeOutputValues m_eModeOutput
stores the output mode (DIRECT, SIGMOID, SOFTMAX)
static std::shared_ptr< std::function< double(double)> > InvSoftSign
bool m_isInputLayer
is this layer an input layer
static std::shared_ptr< std::function< double(double)> > TanhShift
Settings(TString name, size_t _convergenceSteps=15, size_t _batchSize=10, size_t _testRepetitions=7, double _factorWeightDecay=1e-5, TMVA::DNN::EnumRegularization _regularization=TMVA::DNN::EnumRegularization::NONE, MinimizerType _eMinimizerType=MinimizerType::fSteepest, double _learningRate=1e-5, double _momentum=0.3, int _repetitions=3, bool _multithreading=true)
c'tor
std::vector< double > m_valueGradients
stores the gradients of the values (nodes)
static std::shared_ptr< std::function< double(double)> > Sigmoid
container_type::const_iterator const_iterator_type
const_iterator_type m_itConstWeightBegin
const iterator to the first weight of this layer in the weight vector
const_iterator_type m_itInputBegin
iterator to the first of the nodes in the input node vector
bool m_hasDropOut
dropOut is turned on?
static std::shared_ptr< std::function< double(double)> > SymmReLU
void startTrainCycle()
action to be done when the training cycle is started (e.g.
void create(std::string histoName, int bins, double min, double max)
for monitoring
double studenttDouble(double distributionParameter)
LayerData(const_iterator_type itInputBegin, const_iterator_type itInputEnd, ModeOutputValues eModeOutput=ModeOutputValues::DIRECT)
c'tor of LayerData
virtual ~Settings()
d'tor
std::vector< double > m_deltas
stores the deltas for the DNN training
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
Layer(size_t numNodes, EnumFunction activationFunction, ModeOutputValues eModeOutputValues=ModeOutputValues::DIRECT)
c'tor for defining a Layer
container_type::iterator iterator_type
container_type computeProbabilities() const
compute the probabilities from the node values
size_t m_convergenceCount
std::vector< double > container_type
void endTrainCycle(double)
action to be done when the training cycle is ended (e.g.
void fillDropContainer(DropContainer &dropContainer, double dropFraction, size_t numNodes) const
prepare the drop-out-container (select the nodes which are to be dropped out)
virtual void endTestCycle()
action to be done when the training cycle is ended (e.g.
static std::shared_ptr< std::function< double(double)> > SoftSign
static std::shared_ptr< std::function< double(double)> > ReLU
static std::shared_ptr< std::function< double(double)> > InvSigmoid
size_t numWeights(size_t trainingStartLayer=0) const
returns the number of weights in this net
bool m_hasWeights
does this layer have weights (it does not if it is the input layer)
static std::shared_ptr< std::function< double(double)> > GaussComplement
double gaussDouble(double mean, double sigma)
static std::shared_ptr< std::function< double(double)> > Gauss
size_t numNodes(size_t trainingStartLayer=0) const
returns the number of nodes in this net
double uniformDouble(double minValue, double maxValue)
std::vector< double > m_values
stores the values of the nodes in this layer
void setResultComputation(std::string _fileNameNetConfig, std::string _fileNameResult, std::vector< Pattern > *_resultPatternContainer)
preparation for monitoring output
size_t m_maxConvergenceCount
static std::shared_ptr< std::function< double(double)> > Linear
Abstract ClassifierFactory template that handles arbitrary types.
static std::shared_ptr< std::function< double(double)> > InvGaussComplement
const_iterator_type m_itInputEnd
iterator to the end of the nodes in the input node vector
std::shared_ptr< std::function< double(double)> > m_activationFunction
activation function for this layer
static std::shared_ptr< std::function< double(double)> > InvLinear
std::shared_ptr< std::function< double(double)> > m_inverseActivationFunction
inverse activation function for this layer
void testSample(double error, double output, double target, double weight)
action to be done after the computation of a test sample (e.g.
virtual void startTestCycle()
action to be done when the test cycle is started (e.g.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
static std::shared_ptr< std::function< double(double)> > InvTanhShift
void clear(std::string histoName)
for monitoring
static std::shared_ptr< std::function< double(double)> > ZeroFnc
virtual bool hasConverged(double testError)
has this training converged already?
int randomInt(int maxValue)
std::shared_ptr< std::function< double(double)> > m_activationFunction
stores the activation function
static std::shared_ptr< std::function< double(double)> > InvSymmReLU