#ifndef ROOT_TMVA_PDEFoam
#define ROOT_TMVA_PDEFoam
#include <iosfwd>
#include <cassert>
#ifndef ROOT_TH2D
#include "TH2D.h"
#endif
#ifndef ROOT_TObjArray
#include "TObjArray.h"
#endif
#ifndef ROOT_TObjString
#include "TObjString.h"
#endif
#ifndef ROOT_TVectorT
#include "TVectorT.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TMVA_VariableInfo
#include "TMVA/VariableInfo.h"
#endif
#ifndef ROOT_TMVA_Timer
#include "TMVA/Timer.h"
#endif
#ifndef ROOT_TObject
#include "TObject.h"
#endif
#ifndef ROOT_TRandom3
#include "TRandom3.h"
#endif
namespace TMVA {
class PDEFoamCell;
class PDEFoamVect;
class PDEFoamDistr;
class PDEFoam;
enum EFoamType { kSeparate, kDiscr, kMonoTarget, kMultiTarget };
}
#ifndef ROOT_TMVA_PDEFoamDistr
#include "TMVA/PDEFoamDistr.h"
#endif
#ifndef ROOT_TMVA_PDEFoamVect
#include "TMVA/PDEFoamVect.h"
#endif
#ifndef ROOT_TMVA_PDEFoamCell
#include "TMVA/PDEFoamCell.h"
#endif
namespace TMVA {
enum EKernel { kNone=0, kGaus=1, kLinN=2 };
enum ETargetSelection { kMean=0, kMpv=1 };
enum ECellType { kAll, kActive, kInActive };
enum ECellValue { kNev, kDiscriminator, kDiscriminatorError, kTarget0,
kTarget0Error, kMeanValue, kRms, kRmsOvMean, kDensity };
enum EDTSeparation { kFoam, kGiniIndex, kMisClassificationError,
kCrossEntropy };
}
namespace TMVA {
std::ostream& operator<< ( std::ostream& os, const PDEFoam& pdefoam );
std::istream& operator>> ( std::istream& istr, PDEFoam& pdefoam );
class PDEFoam : public TObject {
protected:
TString fName;
Int_t fDim;
Int_t fNCells;
Int_t fNBin;
Int_t fNSampl;
Int_t fEvPerBin;
Int_t *fMaskDiv;
Int_t *fInhiDiv;
Int_t fNoAct;
Int_t fLastCe;
PDEFoamCell **fCells;
TObjArray *fHistEdg;
Double_t *fRvec;
TRandom3 *fPseRan;
Double_t *fAlpha;
EFoamType fFoamType;
Double_t *fXmin;
Double_t *fXmax;
UInt_t fNElements;
UInt_t fNmin;
UInt_t fMaxDepth;
Float_t fVolFrac;
Bool_t fFillFoamWithOrigWeights;
EDTSeparation fDTSeparation;
Bool_t fPeekMax;
PDEFoamDistr *fDistr;
Timer *fTimer;
TObjArray *fVariableNames;
mutable MsgLogger* fLogger;
private:
template<typename T> T Sqr(T x) const { return x*x; }
PDEFoamDistr* GetDistr() const { assert(fDistr); return fDistr; }
protected:
void OutputGrow(Bool_t finished = false );
Float_t WeightGaus(PDEFoamCell*, std::vector<Float_t>&, UInt_t dim=0);
Double_t WeightLinNeighbors( std::vector<Float_t> &txvec, ECellValue cv,
Int_t dim1=-1, Int_t dim2=-1,
Bool_t TreatEmptyCells=kFALSE );
void InitCells();
Int_t CellFill(Int_t, PDEFoamCell*);
void Explore(PDEFoamCell *Cell);
void DTExplore(PDEFoamCell *Cell);
void Varedu(Double_t [], Int_t&, Double_t&,Double_t&);
void MakeAlpha();
void Grow();
Long_t PeekMax();
Long_t PeekLast();
Int_t Divide(PDEFoamCell *);
Double_t Eval(Double_t *xRand, Double_t &event_density);
Float_t GetSeparation(Float_t s, Float_t b);
Double_t GetCellElement(PDEFoamCell *cell, UInt_t i);
void SetCellElement(PDEFoamCell *cell, UInt_t i, Double_t value);
Double_t GetCellValue(PDEFoamCell*, ECellValue);
Bool_t CellValueIsUndefined( PDEFoamCell* );
PDEFoamCell* FindCell(std::vector<Float_t>&);
std::vector<TMVA::PDEFoamCell*> FindCells(std::vector<Float_t>&);
void FindCellsRecursive(std::vector<Float_t>&, PDEFoamCell*,
std::vector<PDEFoamCell*> &);
std::vector<Float_t> GetCellTargets( std::vector<Float_t> &tvals, ETargetSelection ts );
Double_t GetBuildUpCellEvents(PDEFoamCell* cell);
PDEFoam(const PDEFoam&);
public:
PDEFoam();
PDEFoam(const TString&);
virtual ~PDEFoam();
void Init();
void FillBinarySearchTree( const Event* ev, Bool_t NoNegWeights=kFALSE );
void Create();
void FillFoamCells(const Event* ev, Bool_t NoNegWeights=kFALSE);
void CalcCellDiscr();
void CalcCellTarget();
void ResetCellElements(Bool_t allcells = false);
void SetDim(Int_t kDim);
void SetnCells(Long_t nCells){fNCells =nCells;}
void SetnSampl(Long_t nSampl){fNSampl =nSampl;}
void SetnBin(Int_t nBin){fNBin = nBin;}
void SetEvPerBin(Int_t EvPerBin){fEvPerBin =EvPerBin;}
void SetInhiDiv(Int_t, Int_t );
void SetNElements(UInt_t numb){fNElements = numb;}
void SetVolumeFraction(Float_t vfr){fVolFrac = vfr;}
void SetFoamType(EFoamType ft);
void SetFillFoamWithOrigWeights(Bool_t new_val){fFillFoamWithOrigWeights=new_val;}
void SetDTSeparation(EDTSeparation new_val){fDTSeparation=new_val;}
void SetPeekMax(Bool_t new_val){ fPeekMax = new_val; }
Int_t GetTotDim() const {return fDim; }
TString GetFoamName() const {return fName; }
UInt_t GetNElements() const {return fNElements; }
Float_t GetVolumeFraction() const {return fVolFrac;}
EFoamType GetFoamType() const {return fFoamType;};
UInt_t GetNActiveCells() const {return fNoAct;};
UInt_t GetNInActiveCells() const {return GetNCells()-GetNActiveCells();};
UInt_t GetNCells() const {return fNCells;};
PDEFoamCell* GetRootCell() const {return fCells[0];};
void SetNmin(UInt_t val) { fNmin=val; }
UInt_t GetNmin() { return fNmin; }
Bool_t GetFillFoamWithOrigWeights() const { return fFillFoamWithOrigWeights; }
void SetMaxDepth(UInt_t maxdepth) { fMaxDepth = maxdepth; }
UInt_t GetMaxDepth() const { return fMaxDepth; }
void SetXmin(Int_t idim, Double_t wmin);
void SetXmax(Int_t idim, Double_t wmax);
Double_t GetXmin(Int_t idim) const {return fXmin[idim];}
Double_t GetXmax(Int_t idim) const {return fXmax[idim];}
void AddVariableName(const char *s) { AddVariableName(new TObjString(s)); }
void AddVariableName(TObjString *s) { fVariableNames->Add(s); }
TObjString* GetVariableName(Int_t idx) {return dynamic_cast<TObjString*>(fVariableNames->At(idx));}
void DeleteBinarySearchTree();
Float_t VarTransform(Int_t idim, Float_t x) const;
std::vector<Float_t> VarTransform(std::vector<Float_t> &invec) const;
Float_t VarTransformInvers(Int_t idim, Float_t x) const;
std::vector<Float_t> VarTransformInvers(std::vector<Float_t> &invec) const;
void CheckAll(Int_t);
void PrintCell(Long_t iCell=0);
void PrintCells();
void CheckCells(Bool_t remove_empty_cells=false);
void RemoveEmptyCell(Int_t iCell);
void PrintCellElements();
MsgLogger& Log() const { return *fLogger; }
friend std::ostream& operator<< ( std::ostream& os, const PDEFoam& pdefoam );
friend std::istream& operator>> ( std::istream& istr, PDEFoam& pdefoam );
void ReadStream(istream &);
void PrintStream(ostream &) const;
void ReadXML( void* parent );
void AddXMLTo( void* parent );
TH2D* Project2(Int_t idim1, Int_t idim2, const char *opt="cell_value",
const char *ker="kNone", UInt_t maxbins=50);
Double_t GetProjectionCellValue( PDEFoamCell* cell,
Int_t idim1, Int_t idim2, ECellValue cv );
TH1D* Draw1Dim(const char *opt, Int_t nbin);
void RootPlot2dim( const TString& filename, TString opt,
Bool_t CreateCanvas = kTRUE, Bool_t colors = kTRUE,
Bool_t log_colors = kFALSE );
Double_t GetCellValue(std::vector<Float_t>&, ECellValue);
Double_t GetCellDiscr(std::vector<Float_t> &xvec, EKernel kernel=kNone);
Double_t GetCellDensity(std::vector<Float_t> &xvec, EKernel kernel=kNone);
Double_t GetAverageNeighborsValue(std::vector<Float_t> &txvec, ECellValue cv);
Double_t GetCellRegValue0(std::vector<Float_t>&, EKernel kernel=kNone);
std::vector<Float_t> GetProjectedRegValue(std::vector<Float_t> &vals, EKernel kernel=kNone, ETargetSelection ts=kMean);
ClassDef(PDEFoam,5)
};
}
inline Float_t TMVA::PDEFoam::VarTransform(Int_t idim, Float_t x) const
{
return (x-fXmin[idim])/(fXmax[idim]-fXmin[idim]);
}
inline std::vector<Float_t> TMVA::PDEFoam::VarTransform(std::vector<Float_t> &invec) const
{
std::vector<Float_t> outvec;
for(UInt_t i=0; i<invec.size(); i++)
outvec.push_back(VarTransform(i, invec.at(i)));
return outvec;
}
inline Float_t TMVA::PDEFoam::VarTransformInvers(Int_t idim, Float_t x) const
{
return x*(fXmax[idim]-fXmin[idim]) + fXmin[idim];
}
inline std::vector<Float_t> TMVA::PDEFoam::VarTransformInvers(std::vector<Float_t> &invec) const
{
std::vector<Float_t> outvec;
for(UInt_t i=0; i<invec.size(); i++)
outvec.push_back(VarTransformInvers(i, invec.at(i)));
return outvec;
}
#endif