// @(#)root/tmva $Id$
// Author: Matt Jachowski 

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : TActivationRadial                                                     *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Radial basis activation function for TNeuron                              *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Matt Jachowski  <jachowski@stanford.edu> - Stanford University, USA       *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/
  
//_______________________________________________________________________
//                                                                      
//  Radial basis  activation function for ANN. This really simple implementation
//  uses TFormulas and should probably be replaced with something more
//  efficient later.
//_______________________________________________________________________

#include <iostream>

#include "TFormula.h"
#include "TString.h"
#include "TMath.h"

#ifndef ROOT_TMVA_TActivationRadial
#include "TMVA/TActivationRadial.h"
#endif

static const Int_t  UNINITIALIZED = -1;

ClassImp(TMVA::TActivationRadial)

//______________________________________________________________________________
TMVA::TActivationRadial::TActivationRadial()
{
   // constructor for gaussian with center 0, width 1

   fEqn           = new TFormula("Gaussian",   "TMath::Exp(-x^2/2.0)");
   fEqnDerivative = new TFormula("derivative", "-x*TMath::Exp(-x^2/2.0)");
}

//______________________________________________________________________________
TMVA::TActivationRadial::~TActivationRadial()
{
   // destructor

   if (fEqn != NULL) delete fEqn;
   if (fEqnDerivative != NULL) delete fEqnDerivative;
}

//______________________________________________________________________________
Double_t TMVA::TActivationRadial::Eval(Double_t arg)
{
   // evaluate gaussian

   if (fEqn == NULL) return UNINITIALIZED;
   return fEqn->Eval(arg);
}

//______________________________________________________________________________
Double_t TMVA::TActivationRadial::EvalDerivative(Double_t arg)
{
   // evaluate derivative

   if (fEqnDerivative == NULL) return UNINITIALIZED;
   return fEqnDerivative->Eval(arg);
}

//______________________________________________________________________________
TString TMVA::TActivationRadial::GetExpression()
{
   // get expressions for the gaussian and its derivatives

   TString expr = "";

   if (fEqn == NULL) expr += "<null>";
   else              expr += fEqn->GetExpFormula();

   expr += "\t\t";

   if (fEqnDerivative == NULL) expr += "<null>";
   else                        expr += fEqnDerivative->GetExpFormula();

   return expr;
}

//______________________________________________________________________________
void TMVA::TActivationRadial::MakeFunction( std::ostream& fout, const TString& fncName ) 
{
   // writes the sigmoid activation function source code
   fout << "double " << fncName << "(double x) const {" << std::endl;
   fout << "   // radial" << std::endl;
   fout << "   return exp(-x*x/2.0);" << std::endl;
   fout << "}" << std::endl;
}
 TActivationRadial.cxx:1
 TActivationRadial.cxx:2
 TActivationRadial.cxx:3
 TActivationRadial.cxx:4
 TActivationRadial.cxx:5
 TActivationRadial.cxx:6
 TActivationRadial.cxx:7
 TActivationRadial.cxx:8
 TActivationRadial.cxx:9
 TActivationRadial.cxx:10
 TActivationRadial.cxx:11
 TActivationRadial.cxx:12
 TActivationRadial.cxx:13
 TActivationRadial.cxx:14
 TActivationRadial.cxx:15
 TActivationRadial.cxx:16
 TActivationRadial.cxx:17
 TActivationRadial.cxx:18
 TActivationRadial.cxx:19
 TActivationRadial.cxx:20
 TActivationRadial.cxx:21
 TActivationRadial.cxx:22
 TActivationRadial.cxx:23
 TActivationRadial.cxx:24
 TActivationRadial.cxx:25
 TActivationRadial.cxx:26
 TActivationRadial.cxx:27
 TActivationRadial.cxx:28
 TActivationRadial.cxx:29
 TActivationRadial.cxx:30
 TActivationRadial.cxx:31
 TActivationRadial.cxx:32
 TActivationRadial.cxx:33
 TActivationRadial.cxx:34
 TActivationRadial.cxx:35
 TActivationRadial.cxx:36
 TActivationRadial.cxx:37
 TActivationRadial.cxx:38
 TActivationRadial.cxx:39
 TActivationRadial.cxx:40
 TActivationRadial.cxx:41
 TActivationRadial.cxx:42
 TActivationRadial.cxx:43
 TActivationRadial.cxx:44
 TActivationRadial.cxx:45
 TActivationRadial.cxx:46
 TActivationRadial.cxx:47
 TActivationRadial.cxx:48
 TActivationRadial.cxx:49
 TActivationRadial.cxx:50
 TActivationRadial.cxx:51
 TActivationRadial.cxx:52
 TActivationRadial.cxx:53
 TActivationRadial.cxx:54
 TActivationRadial.cxx:55
 TActivationRadial.cxx:56
 TActivationRadial.cxx:57
 TActivationRadial.cxx:58
 TActivationRadial.cxx:59
 TActivationRadial.cxx:60
 TActivationRadial.cxx:61
 TActivationRadial.cxx:62
 TActivationRadial.cxx:63
 TActivationRadial.cxx:64
 TActivationRadial.cxx:65
 TActivationRadial.cxx:66
 TActivationRadial.cxx:67
 TActivationRadial.cxx:68
 TActivationRadial.cxx:69
 TActivationRadial.cxx:70
 TActivationRadial.cxx:71
 TActivationRadial.cxx:72
 TActivationRadial.cxx:73
 TActivationRadial.cxx:74
 TActivationRadial.cxx:75
 TActivationRadial.cxx:76
 TActivationRadial.cxx:77
 TActivationRadial.cxx:78
 TActivationRadial.cxx:79
 TActivationRadial.cxx:80
 TActivationRadial.cxx:81
 TActivationRadial.cxx:82
 TActivationRadial.cxx:83
 TActivationRadial.cxx:84
 TActivationRadial.cxx:85
 TActivationRadial.cxx:86
 TActivationRadial.cxx:87
 TActivationRadial.cxx:88
 TActivationRadial.cxx:89
 TActivationRadial.cxx:90
 TActivationRadial.cxx:91
 TActivationRadial.cxx:92
 TActivationRadial.cxx:93
 TActivationRadial.cxx:94
 TActivationRadial.cxx:95
 TActivationRadial.cxx:96
 TActivationRadial.cxx:97
 TActivationRadial.cxx:98
 TActivationRadial.cxx:99
 TActivationRadial.cxx:100
 TActivationRadial.cxx:101
 TActivationRadial.cxx:102
 TActivationRadial.cxx:103
 TActivationRadial.cxx:104
 TActivationRadial.cxx:105
 TActivationRadial.cxx:106
 TActivationRadial.cxx:107