#ifndef ROOT_TMVA_TNeuron
#define ROOT_TMVA_TNeuron
#include <iostream>
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif
#ifndef ROOT_TFormula
#include "TFormula.h"
#endif
#ifndef ROOT_TMVA_TSynapse
#include "TMVA/TSynapse.h"
#endif
#ifndef ROOT_TMVA_TActivation
#include "TMVA/TActivation.h"
#endif
#ifndef ROOT_TMVA_Types
#include "TMVA/Types.h"
#endif
namespace TMVA {
class TNeuronInput;
class TNeuron : public TObject {
public:
TNeuron();
virtual ~TNeuron();
void ForceValue(Double_t value);
void CalculateValue();
void CalculateActivationValue();
void CalculateDelta();
void SetActivationEqn(TActivation* activation);
void SetInputCalculator(TNeuronInput* calculator);
void AddPreLink(TSynapse* pre);
void AddPostLink(TSynapse* post);
void DeletePreLinks();
void SetError(Double_t error);
void UpdateSynapsesBatch();
void UpdateSynapsesSequential();
void AdjustSynapseWeights();
void InitSynapseDeltas();
void PrintActivationEqn();
Double_t GetValue() const { return fValue; }
Double_t GetActivationValue() const { return fActivationValue; }
Double_t GetDelta() const { return fDelta; }
Double_t GetDEDw() const { return fDEDw; }
Int_t NumPreLinks() const { return NumLinks(fLinksIn); }
Int_t NumPostLinks() const { return NumLinks(fLinksOut); }
TSynapse* PreLinkAt ( Int_t index ) const { return (TSynapse*)fLinksIn->At(index); }
TSynapse* PostLinkAt( Int_t index ) const { return (TSynapse*)fLinksOut->At(index); }
void SetInputNeuron() { NullifyLinks(fLinksIn); }
void SetOutputNeuron() { NullifyLinks(fLinksOut); }
void SetBiasNeuron() { NullifyLinks(fLinksIn); }
void SetDEDw( Double_t DEDw ) { fDEDw = DEDw; }
Bool_t IsInputNeuron() const { return fLinksIn == NULL; }
Bool_t IsOutputNeuron() const { return fLinksOut == NULL; }
void PrintPreLinks() const { PrintLinks(fLinksIn); return; }
void PrintPostLinks() const { PrintLinks(fLinksOut); return; }
virtual void Print(Option_t* = "") const {
std::cout << fValue << std::endl;
}
private:
void InitNeuron();
void DeleteLinksArray( TObjArray*& links );
void PrintLinks ( TObjArray* links ) const;
void PrintMessage ( EMsgType, TString message );
Int_t NumLinks(TObjArray* links) const {
if (links == NULL) return 0; return links->GetEntriesFast();
}
void NullifyLinks(TObjArray*& links) {
if (links != NULL) delete links; links = NULL;
}
TObjArray* fLinksIn;
TObjArray* fLinksOut;
Double_t fValue;
Double_t fActivationValue;
Double_t fDelta;
Double_t fDEDw;
Double_t fError;
Bool_t fForcedValue;
TActivation* fActivation;
TNeuronInput* fInputCalculator;
static MsgLogger* fgLogger;
MsgLogger& Log() const { return *fgLogger; }
ClassDef(TNeuron,0)
};
}
#endif