00001 // @(#)root/tmva $Id: TActivationRadial.cxx 29122 2009-06-22 06:51:30Z brun $ 00002 // Author: Matt Jachowski 00003 00004 /********************************************************************************** 00005 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis * 00006 * Package: TMVA * 00007 * Class : TActivationRadial * 00008 * Web : http://tmva.sourceforge.net * 00009 * * 00010 * Description: * 00011 * Radial basis activation function for TNeuron * 00012 * * 00013 * Authors (alphabetical): * 00014 * Matt Jachowski <jachowski@stanford.edu> - Stanford University, USA * 00015 * * 00016 * Copyright (c) 2005: * 00017 * CERN, Switzerland * 00018 * * 00019 * Redistribution and use in source and binary forms, with or without * 00020 * modification, are permitted according to the terms listed in LICENSE * 00021 * (http://tmva.sourceforge.net/LICENSE) * 00022 **********************************************************************************/ 00023 00024 //_______________________________________________________________________ 00025 // 00026 // Radial basis activation function for ANN. This really simple implementation 00027 // uses TFormulas and should probably be replaced with something more 00028 // efficient later. 00029 //_______________________________________________________________________ 00030 00031 #include <iostream> 00032 00033 #include "TFormula.h" 00034 #include "TString.h" 00035 #include "TMath.h" 00036 00037 #ifndef ROOT_TMVA_TActivationRadial 00038 #include "TMVA/TActivationRadial.h" 00039 #endif 00040 00041 static const Int_t UNINITIALIZED = -1; 00042 00043 ClassImp(TMVA::TActivationRadial) 00044 00045 //______________________________________________________________________________ 00046 TMVA::TActivationRadial::TActivationRadial() 00047 { 00048 // constructor for gaussian with center 0, width 1 00049 00050 fEqn = new TFormula("Gaussian", "TMath::Exp(-x^2/2.0)"); 00051 fEqnDerivative = new TFormula("derivative", "-x*TMath::Exp(-x^2/2.0)"); 00052 } 00053 00054 //______________________________________________________________________________ 00055 TMVA::TActivationRadial::~TActivationRadial() 00056 { 00057 // destructor 00058 00059 if (fEqn != NULL) delete fEqn; 00060 if (fEqnDerivative != NULL) delete fEqnDerivative; 00061 } 00062 00063 //______________________________________________________________________________ 00064 Double_t TMVA::TActivationRadial::Eval(Double_t arg) 00065 { 00066 // evaluate gaussian 00067 00068 if (fEqn == NULL) return UNINITIALIZED; 00069 return fEqn->Eval(arg); 00070 } 00071 00072 //______________________________________________________________________________ 00073 Double_t TMVA::TActivationRadial::EvalDerivative(Double_t arg) 00074 { 00075 // evaluate derivative 00076 00077 if (fEqnDerivative == NULL) return UNINITIALIZED; 00078 return fEqnDerivative->Eval(arg); 00079 } 00080 00081 //______________________________________________________________________________ 00082 TString TMVA::TActivationRadial::GetExpression() 00083 { 00084 // get expressions for the gaussian and its derivatives 00085 00086 TString expr = ""; 00087 00088 if (fEqn == NULL) expr += "<null>"; 00089 else expr += fEqn->GetExpFormula(); 00090 00091 expr += "\t\t"; 00092 00093 if (fEqnDerivative == NULL) expr += "<null>"; 00094 else expr += fEqnDerivative->GetExpFormula(); 00095 00096 return expr; 00097 } 00098 00099 //______________________________________________________________________________ 00100 void TMVA::TActivationRadial::MakeFunction( std::ostream& fout, const TString& fncName ) 00101 { 00102 // writes the sigmoid activation function source code 00103 fout << "double " << fncName << "(double x) const {" << std::endl; 00104 fout << " // radial" << std::endl; 00105 fout << " return exp(-x*x/2.0);" << std::endl; 00106 fout << "}" << std::endl; 00107 }