From 006a9d225218cd569d559154741dbef819655510 Mon Sep 17 00:00:00 2001 From: Baptiste Mouginot <mouginot.baptiste@gmail.com> Date: Thu, 7 Jan 2016 23:24:41 +0000 Subject: [PATCH] Add Bam name where it belong.. update XS_MLP model to improve MLP performance, Some bug correction on other Equivalence MLP model git-svn-id: svn+ssh://svn.in2p3.fr/class@798 0e7d625b-0364-4367-a6be-d5be4a48d228 --- .../Equivalence/EQM_FBR_BakerRoss_MOX.hxx | 1 + .../BaM/Model/Equivalence/EQM_MLP_Kinf.cxx | 9 +- .../BaM/Model/Equivalence/EQM_MLP_Kinf.hxx | 3 +- .../BaM/Model/Equivalence/EQM_PWR_MLP_MOX.hxx | 1 + .../Model/Equivalence/EQM_PWR_MLP_MOX_Am.hxx | 1 + source/branches/BaM/Model/XS/XSM_MLP.cxx | 165 +++++++----------- source/branches/BaM/Model/XS/XSM_MLP.hxx | 19 +- 7 files changed, 93 insertions(+), 106 deletions(-) diff --git a/source/branches/BaM/Model/Equivalence/EQM_FBR_BakerRoss_MOX.hxx b/source/branches/BaM/Model/Equivalence/EQM_FBR_BakerRoss_MOX.hxx index b6125293b..12b6acd62 100644 --- a/source/branches/BaM/Model/Equivalence/EQM_FBR_BakerRoss_MOX.hxx +++ b/source/branches/BaM/Model/Equivalence/EQM_FBR_BakerRoss_MOX.hxx @@ -26,6 +26,7 @@ using namespace std; @f$\alpha_{i} = \bar{\nu_{i}}\cdot\sigma_{i}^{fis} - \sigma_{i}^{abs}@f$ @author BLG + @author BaM @version 3.0 */ //________________________________________________________________________ diff --git a/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.cxx b/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.cxx index 871f5efa4..e7be2ad89 100644 --- a/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.cxx +++ b/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.cxx @@ -35,7 +35,9 @@ EQM_MLP_Kinf::EQM_MLP_Kinf(string WeightPathAlpha0, string WeightPathAlpha1, str fInformationFile = InformationFile; LoadKeyword(); ReadNFO();//Getting information from fInformationFile - + + InitialiseTMVAReader(); + fNumberOfBatch = NumOfBatch; fKThreshold = CriticalityThreshold ; SetBurnUpPrecision(0.005);//1 % of the targeted burnup @@ -274,7 +276,7 @@ void EQM_MLP_Kinf::InitialiseTMVAReader() // Create a set of variables and declare them to the reader // - the variable names MUST corresponds in name and type to those given in the weight file(s) used - vector<float> InputTMVA; + InputTMVA; for(int i = 0 ; i< (int)fMapOfTMVAVariableNames.size() ; i++) InputTMVA.push_back(0); Float_t Time; @@ -300,6 +302,9 @@ void EQM_MLP_Kinf::UpdateInputComposition(IsotopicVector TheFreshfuel, double Th IsotopicVector IVAccordingToUserInfoFile = TheFreshfuel.GetThisComposition(IVInputTMVA); + double Ntot = IVAccordingToUserInfoFile.GetSumOfAll(); + + IVAccordingToUserInfoFile *= 1/Ntot; map<ZAI,string>::iterator it; int j = 0; diff --git a/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.hxx b/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.hxx index 43f9e384b..68791a530 100644 --- a/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.hxx +++ b/source/branches/BaM/Model/Equivalence/EQM_MLP_Kinf.hxx @@ -32,7 +32,8 @@ Where @f$k_{Threshold}@f$ is the criticality threshold which take into account l in non simulated devices such as control rods and mixing grid. @author BLG - @version 1.0 + @author BaM +@version 1.0 */ //________________________________________________________________________ diff --git a/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX.hxx b/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX.hxx index c59b624f9..413bc0b1f 100644 --- a/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX.hxx +++ b/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX.hxx @@ -15,6 +15,7 @@ using namespace std; based on a Multi layer perceptron @author BLG + @author BaM @version 3.0 */ //________________________________________________________________________ diff --git a/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX_Am.hxx b/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX_Am.hxx index d919a3e98..f1da6c5be 100755 --- a/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX_Am.hxx +++ b/source/branches/BaM/Model/Equivalence/EQM_PWR_MLP_MOX_Am.hxx @@ -16,6 +16,7 @@ using namespace std; based on a Multi layer perceptron @author BLG + @author BaM @version 3.0 */ //________________________________________________________________________ diff --git a/source/branches/BaM/Model/XS/XSM_MLP.cxx b/source/branches/BaM/Model/XS/XSM_MLP.cxx index c79d57493..d9c7ce23b 100644 --- a/source/branches/BaM/Model/XS/XSM_MLP.cxx +++ b/source/branches/BaM/Model/XS/XSM_MLP.cxx @@ -5,7 +5,6 @@ #include "CLASSMethod.hxx" #include "StringLine.hxx" -#include "TMVA/Reader.h" #include "TMVA/Tools.h" #include "TMVA/MethodCuts.h" @@ -49,7 +48,9 @@ XSM_MLP::XSM_MLP(string TMVA_Weight_Directory,string InformationFile, bool IsTim LoadKeyword(); ReadNFO(); - + + InitialiseTMVAReader(); + } //________________________________________________________________________ @@ -69,7 +70,9 @@ XSM_MLP::XSM_MLP(CLASSLogger* Log,string TMVA_Weight_Directory,string Informatio LoadKeyword(); ReadNFO(); - + + InitialiseTMVAReader(); + } //________________________________________________________________________ @@ -227,76 +230,62 @@ void XSM_MLP::ReadWeightFile(string Filename, int &Z, int &A, int &I, int &React } //________________________________________________________________________ -TTree* XSM_MLP::CreateTMVAInputTree(IsotopicVector isotopicvector,int TimeStep) +void XSM_MLP::UpdateInputComposition(IsotopicVector TheFreshfuel,int TimeStep) { - /******Create Input data tree to be interpreted by TMVA::Reader***/ - TTree* InputTree = new TTree("InTMP", "InTMP"); - - vector<float> InputTMVA; - for(int i = 0 ; i< (int)fMapOfTMVAVariableNames.size() ; i++) - InputTMVA.push_back(0); - - float Time = 0; - - IsotopicVector IVInputTMVA; - map<ZAI ,string >::iterator it; - int j = 0; - - for( it = fMapOfTMVAVariableNames.begin() ; it != fMapOfTMVAVariableNames.end() ; it++) - { - InputTree->Branch( ((*it).second).c_str() ,&InputTMVA[j], ((*it).second + "/F").c_str()); - IVInputTMVA+= ((*it).first)*1; - j++; - } - - if( !fIsStepTime) - InputTree->Branch( "Time" ,&Time ,"Time/F" ); - IsotopicVector IVAccordingToUserInfoFile = isotopicvector.GetThisComposition(IVInputTMVA); - - double Ntot = IVAccordingToUserInfoFile.GetSumOfAll(); - - IVAccordingToUserInfoFile = IVAccordingToUserInfoFile/Ntot; + IsotopicVector IVAccordingToUserInfoFile = TheFreshfuel.GetThisComposition(IVInputTMVA); + + double Ntot = IVAccordingToUserInfoFile.GetSumOfAll(); + + IVAccordingToUserInfoFile *= 1/Ntot; - j = 0; + + DBGV("INPUT TMVA"); + + int j = 0; map<ZAI ,string >::iterator it2; - DBGV("INPUT TMVA"); + for( it2 = fMapOfTMVAVariableNames.begin() ; it2 != fMapOfTMVAVariableNames.end() ; it2++) { - InputTMVA[j] = IVAccordingToUserInfoFile.GetZAIIsotopicQuantity( (*it2).first ) ; + InputTMVA[j] = IVAccordingToUserInfoFile.GetZAIIsotopicQuantity( (*it2).first ); DBGV((*it2).first.Z() << " " << (*it2).first.A() << " " << InputTMVA[j]); j++; } Time = fMLP_Time[TimeStep]; - - InputTree->Fill(); - - return InputTree; + +} + +void XSM_MLP::InitialiseTMVAReader() +{ + reader = new TMVA::Reader( "Silent" ); + + for(int i = 0 ; i< (int)fMapOfTMVAVariableNames.size() ; i++) + InputTMVA.push_back(0); + + + for(int i = 0 ; i< (int)fMapOfTMVAVariableNames.size() ; i++) + InputTMVA.push_back(0); + + map<ZAI ,string >::iterator it; + int j = 0; + for( it = fMapOfTMVAVariableNames.begin() ; it != fMapOfTMVAVariableNames.end() ; it++) + { reader->AddVariable( ( (*it).second ).c_str(),&InputTMVA[j]); + j++; + } + if(!fIsStepTime) + reader->AddVariable( "Time" ,&Time); } + //________________________________________________________________________ -double XSM_MLP::ExecuteTMVA(string WeightFile,TTree* InputTree) +double XSM_MLP::ExecuteTMVA(string WeightFile, IsotopicVector isotopicvector, int TimeStep) { - DBGV( "File :" << WeightFile); - // --- Create the Reader object - TMVA::Reader *reader = new TMVA::Reader( "Silent" ); - - // Create a set of variables and declare them to the reader - // - the variable names MUST corresponds in name and type to those given in the weight file(s) used - vector<float> InputTMVA; - for(int i = 0 ; i< (int)fMapOfTMVAVariableNames.size() ; i++) - InputTMVA.push_back(0); - Float_t Time; - - map<ZAI ,string >::iterator it; - int j = 0; - for( it = fMapOfTMVAVariableNames.begin() ; it != fMapOfTMVAVariableNames.end() ; it++) - { reader->AddVariable( ( (*it).second ).c_str(),&InputTMVA[j]); - j++; - } - if(!fIsStepTime) - reader->AddVariable( "Time" ,&Time); - + + UpdateInputComposition(isotopicvector, TimeStep); + + + DBGV( "File :" << WeightFile); + // --- Book the MVA methods string dir = fTMVAWeightFolder; @@ -307,22 +296,9 @@ double XSM_MLP::ExecuteTMVA(string WeightFile,TTree* InputTree) TString methodName = "MLP method"; TString weightpath = dir + WeightFile ; reader->BookMVA( methodName, weightpath ); + + float val = (reader->EvaluateRegression( methodName ))[0]; - map<ZAI ,string >::iterator it2; - j = 0; - for( it2 = fMapOfTMVAVariableNames.begin() ; it2 != fMapOfTMVAVariableNames.end() ; it2++) - { - InputTree->SetBranchAddress(( (*it2).second ).c_str(),&InputTMVA[j]); - j++; - } - - if(!fIsStepTime) - InputTree->SetBranchAddress( "Time" ,&Time ); - - InputTree->GetEntry(0); - Float_t val = (reader->EvaluateRegression( methodName ))[0]; - - delete reader; DBGL return (double)val; @@ -348,29 +324,22 @@ EvolutionData XSM_MLP::GetCrossSectionsTime(IsotopicVector IV) int I = -2; int Reaction = -2; ReadWeightFile( fWeightFiles[i], Z, A, I, Reaction); + if( Z >= GetZAIThreshold() ) { - for(int TimeStep = 0;TimeStep<int(fMLP_Time.size());TimeStep++) + + TGraph* ZAIXSTGraph = new TGraph(); + + for(int TimeStep = 0; TimeStep < int(fMLP_Time.size()) ; TimeStep++) { - TTree* InputTree = CreateTMVAInputTree(IV,TimeStep); - - pair< map<ZAI, TGraph*>::iterator, bool> IResult; - - IResult = ExtrapolatedXS[Reaction].insert( pair<ZAI ,TGraph* >(ZAI(Z,A,I), new TGraph()) ); - - double XSValue = ExecuteTMVA(fWeightFiles[i],InputTree ); - if(IResult.second ) - { - (IResult.first)->second->SetPoint(0, (double)fMLP_Time[TimeStep], XSValue ); - - } - else - { - (IResult.first)->second->SetPoint( (IResult.first)->second->GetN(), (double)fMLP_Time[TimeStep], XSValue ); - } - - delete InputTree; - } + double XSValue = ExecuteTMVA(fWeightFiles[i], IV, TimeStep ); + ZAIXSTGraph->SetPoint( ZAIXSTGraph->GetN(), (double)fMLP_Time[TimeStep], XSValue ); + } + + pair< map<ZAI, TGraph*>::iterator, bool> IResult; + + IResult = ExtrapolatedXS[Reaction].insert( pair<ZAI ,TGraph* >(ZAI(Z,A,I), ZAIXSTGraph) ); + } } @@ -436,8 +405,7 @@ void XSM_MLP::ReadWeightFileStep(string Filename, int &Z, int &A, int &I, int &R EvolutionData XSM_MLP::GetCrossSectionsStep(IsotopicVector IV) { DBGL - TTree* InputTree = CreateTMVAInputTree(IV); - + EvolutionData EvolutionDataFromMLP = EvolutionData(); map<ZAI,TGraph*> ExtrapolatedXS[3]; @@ -467,11 +435,11 @@ EvolutionData XSM_MLP::GetCrossSectionsStep(IsotopicVector IV) if( IResult.second ) { - (IResult.first)->second->SetPoint(0, (double)fMLP_Time[TimeStep], ExecuteTMVA(fWeightFiles[i],InputTree) ); + (IResult.first)->second->SetPoint(0, (double)fMLP_Time[TimeStep], ExecuteTMVA(fWeightFiles[i],IV) ); } else { - (IResult.first)->second->SetPoint( (IResult.first)->second->GetN(), (double)fMLP_Time[TimeStep], ExecuteTMVA(fWeightFiles[i],InputTree) ); + (IResult.first)->second->SetPoint( (IResult.first)->second->GetN(), (double)fMLP_Time[TimeStep], ExecuteTMVA(fWeightFiles[i],IV) ); } } } @@ -487,7 +455,6 @@ EvolutionData XSM_MLP::GetCrossSectionsStep(IsotopicVector IV) EvolutionDataFromMLP.SetCaptureXS(ExtrapolatedXS[1]); EvolutionDataFromMLP.Setn2nXS(ExtrapolatedXS[2]); - delete InputTree; DBGL return EvolutionDataFromMLP; } diff --git a/source/branches/BaM/Model/XS/XSM_MLP.hxx b/source/branches/BaM/Model/XS/XSM_MLP.hxx index f7c748f12..fd197726b 100644 --- a/source/branches/BaM/Model/XS/XSM_MLP.hxx +++ b/source/branches/BaM/Model/XS/XSM_MLP.hxx @@ -13,7 +13,11 @@ @version 1.0 */ #include "XSModel.hxx" + #include "TTree.h" +#include "TMVA/Reader.h" + + #include <string> #include <fstream> #include <iostream> @@ -38,6 +42,7 @@ typedef void (XSM_MLP::*XS_MLP_DMthPtr)( const string & ) ; set of Multi Layer Perceptrons (MLP) @authors BLG + @authors BaM @version 1.0 */ //________________________________________________________________________ @@ -127,9 +132,10 @@ class XSM_MLP : public XSModel void ReadWeightFileStep(string Filename, int &Z, int &A, int &I, int &Reaction, int &TimeStep);; //!< Select the reaction according to the weight file name - - double ExecuteTMVA(string WeightFile, TTree* InputTree); //!<Execute the MLP according to the input tree created - TTree* CreateTMVAInputTree(IsotopicVector isotopicvector,int TimeStep = 0); //!<Create input tmva tree to be read by ExecuteTMVA + void InitialiseTMVAReader(); + + double ExecuteTMVA(string WeightFile, IsotopicVector isotopicvector, int TimeStep = 0); //!<Execute the MLP according to the input tree created + void UpdateInputComposition(IsotopicVector TheFreshfuel,int TimeStep = 0); //!<Create input tmva tree to be read by ExecuteTMVA vector<double> fMLP_Time; //!< Time vector of the data base @@ -141,7 +147,12 @@ class XSM_MLP : public XSModel bool fIsStepTime; //!< true if one TMVA weihgt per step time is requiered otherwise it assumes time is part of the MLP inputs map<ZAI,string> fMapOfTMVAVariableNames;//!< List of TMVA input variable names (read from fMLPInformationFile ) , name depends on the training step - + + TMVA::Reader *reader; + vector<float> InputTMVA; + IsotopicVector IVInputTMVA; + float Time; + #ifndef __CINT__ map<string, XS_MLP_DMthPtr> fDKeyword; #endif -- GitLab