Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TActivationSigmoid.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Matt Jachowski
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TActivationSigmoid *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Sigmoid activation function for TNeuron *
12  * *
13  * Authors (alphabetical): *
14  * Matt Jachowski <jachowski@stanford.edu> - Stanford University, USA *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * *
19  * Redistribution and use in source and binary forms, with or without *
20  * modification, are permitted according to the terms listed in LICENSE *
21  * (http://tmva.sourceforge.net/LICENSE) *
22  **********************************************************************************/
23 
24 /*! \class TMVA::TActivationSigmoid
25 \ingroup TMVA
26 Sigmoid activation function for TNeuron.
27 */
28 
30 
31 #include "TMVA/TActivation.h"
32 
33 #include "TMath.h"
34 #include "TString.h"
35 
36 #include <iostream>
37 
38 
39 ClassImp(TMVA::TActivationSigmoid);
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// evaluate the sigmoid
43 
44 Double_t TMVA::TActivationSigmoid::Eval(Double_t arg)
45 {
46  return 1.0 / (1.0 + TMath::Exp(-arg));
47 }
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// evaluate the derivative of the sigmoid
51 
52 Double_t TMVA::TActivationSigmoid::EvalDerivative(Double_t arg)
53 {
54  Double_t tmp = (1.0 + TMath::Exp(-arg));
55  return TMath::Exp(-arg) / (tmp * tmp);
56 }
57 
58 ////////////////////////////////////////////////////////////////////////////////
59 /// get expressions for the sigmoid and its derivatives
60 
61 TString TMVA::TActivationSigmoid::GetExpression()
62 {
63  TString expr = "1.0/(1.0+TMath::Exp(-x))\t\tTMath::Exp(-x)/(1.0+TMath::Exp(-x))^2";
64  return expr;
65 }
66 
67 ////////////////////////////////////////////////////////////////////////////////
68 /// writes the sigmoid activation function source code
69 
70 void TMVA::TActivationSigmoid::MakeFunction( std::ostream& fout, const TString& fncName )
71 {
72  fout << "double " << fncName << "(double x) const {" << std::endl;
73  fout << " // sigmoid" << std::endl;
74  fout << " return 1.0/(1.0+exp(-x));" << std::endl;
75  fout << "}" << std::endl;
76 }