Documentation / User's manual in C++ :
The objective of this macro is to perform a sensitivity analysis with brute force method on a set of eight parameters used in the flowrate model described in Section IV.1.2.1. Sensitivity indexes are computed dividing conditional variance by the standard deviation of the output variable.
Warning
This macro is purely illustrative. It is not meant to be used for proper results with a real code / function as it needs a large number of computation to only get the first order index. Its main appeal is to be nicely illustrative: it shows plainly the definition of the conditional expectation and also its variance used to defined the first order sobol indices.void drawBarWithTuple(TTree *tt, TString sx, TString sy, TString stitle)
{
TLeaf *lx = tt->GetLeaf(sx);
TLeaf *ly = tt->GetLeaf(sy);
TH1F *hDiv = new TH1F("hDivdrawBarWithTuple",stitle,3,0,3);
hDiv->SetCanExtend(TH1::kXaxis); //SetBit(TH1::kCanRebin);
hDiv->SetStats(0);
if ( hDiv ) {
hDiv->SetBarWidth(0.45);
hDiv->SetBarOffset(0.1);
hDiv->SetMarkerColor(2);
hDiv->SetMarkerSize(2);
hDiv->SetFillColor(49);
hDiv->SetTitle(stitle);
for (Int_t i = 0; i < tt->GetEntries(); i++) {
tt->GetEntry(i);
TString title = *((string*)lx->GetValuePointer());
hDiv->Fill(title, ly->GetValue());
}
hDiv->LabelsDeflate();
hDiv->LabelsOption(">u");
hDiv->SetMinimum(0.0);
hDiv->SetMaximum(1.0);
gStyle->SetPaintTextFormat("5.2f");
hDiv->Draw("bar2, text45");
}
}
void sensitivityBrutForceMethodFlowrate(Int_t nCond = 50, Int_t nbins = 10)
{
// Create a TDataServer
TDataServer * tds = new TDataServer();
cout << endl << " ******************************************************" << endl;
cout << " ** sensitivityBrutForceMethodFlowrate nbins[" << nbins << "] nCond[" << nCond << "]" << endl;
cout << " **" << endl;
// Add the eight attributes of the study with uniform law
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
Int_t nvar = tds->getNAttributes();
cout << " ** nX[" << nvar << "]" << endl;
Int_t nS = nbins*nvar*nCond;
cout << " ** nS[" << nS << "]" << endl;
// TSampling *sam = new TSampling(tds, "lhs", nS);
TQMC * sam = new TQMC(tds, "halton", nS);
sam->generateSample();
// Load the function
gROOT->LoadMacro("UserFunctions.C");
// Create a TLauncherFunction from a TDataServer and an analytical function
// Rename the outpout attribute "ymod"
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel","","ymod");
// Evaluate the function on all the design of experiments
tlf->setDrawProgressBar(kFALSE);
tlf->run();
TCanvas *Canvas = new TCanvas("c1", "Graph for the Macro modeler",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,2);
pad->cd(1);
tds->computeStatistic("ymod");
tds->draw("ymod");
Double_t dstdy = tds->getAttribute("ymod")->getStd();
Double_t svary = dstdy * dstdy;
cout << " ** ymod : std[" << dstdy << "] vary[" << svary << "]" << endl;
tds->getAttribute("ymod")->setOutput();
gStyle->SetOptStat(1);
// Tempory TTree for Histogram visualisation
Double_t valSobolCrt;
string sName;
TTree *tt = new TTree("sobolforcebrut","MonteCarlo brute force sobol sensitivity ");
tt->Branch("Var","string",&sName);
tt->Branch("Value",&valSobolCrt,"Value/D");
tt->SetMarkerColor(kRed);
tt->SetMarkerStyle(7);
tt->SetMarkerSize(1.75);
TCanvas *c = new TCanvas();
c->Divide(2);
c->cd(1);
for(Int_t ivar=0; ivar<nvar; ivar++) {
cout << " *****************************" << endl << " *** " << tds->getAttribute(ivar)->GetName() << endl;
const char * svar = tds->getAttribute(ivar)->GetName();
if(ivar==0)
pad->cd(2);
else
c->cd(1);
tds->drawProfile(Form("ymod:%s", svar),"",Form("nclass=%d", nbins));
TProfile *hprofs = (TProfile*)gPad->GetPrimitive(Form("Profile ymod:%s (Bin = %d )", svar, nbins+2));
TNtupleD * ntd = new TNtupleD("dd", "sjsjs", "i:x:m");
ntd->SetMarkerColor(kBlue);
ntd->SetMarkerStyle(8);
// ntd->SetMarkerSize(1.25);
Int_t nnbins = hprofs->GetNbinsX();
for(Int_t i=1; i <= nnbins; i++)
ntd->Fill(i-1, hprofs->GetBinCenter(i), hprofs->GetBinContent(i));
tds->draw(Form("ymod:%s", svar));
ntd->Draw("m:x", "","same");
if(ivar==0)
pad->cd(3);
else
c->cd(2);
ntd->Draw("m");
TH1F *htemp = (TH1F*)gPad->GetPrimitive("htemp");
Double_t dvarcond = htemp->GetRMS();
// Tempory TTree for histogram
sName=string(svar);
valSobolCrt = dvarcond*dvarcond /svary;
tt->Fill();
cout << " *** S1[ " << svar <<"] Cond. Var.[" << dvarcond*dvarcond << "] -- [" << valSobolCrt <<"]" << endl;
c->Modified(); c->Update(); c->SaveAs(Form("SAFlowRateVersus%s.png", svar));
delete ntd;
}
pad->cd(4);
drawBarWithTuple(tt, "Var", "Value", "Sensitivity Indexes : ymod [ Brute-Force Method ]");
}
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval:
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
A design-of-experiments is built with a "Halton" method ( = 4000):
TQMC * sam = new TQMC(tds, "halton", nS);
sam->generateSample();
The function flowrateModel
is loaded from the macro UserFunctions.C
(the
file can be found in ${URANIESYS}/share/uranie/macros
):
gROOT->LoadMacro("UserFunctions.C");
The flowrateModel
model is applied on previous variables:
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel","","ymod");
tlf->run();
Characteristic values for the output attribute are computed:
tds->computeStatistic("ymod");
Sensitivity indexes are computed in the for loop. Average value of output variable is computed on nbins+2=12 points for each input variable:
c->cd(1);
...
Int_t nnbins = hprofs->GetNbinsX();
for(Int_t i=1; i <= nnbins; i++)
ntd->Fill(i-1, hprofs->GetBinCenter(i), hprofs->GetBinContent(i));
The RMS value is obtained from the graphic of ymod versus the considered output variable and the sensitivity index is computed dividing the conditional variance value by the standard deviation of the output variable ymod.
c->cd(2);
ntd->Draw("m");
TH1F *htemp = (TH1F*)gPad->GetPrimitive("htemp");
Double_t dvarcond = htemp->GetRMS();
valSobolCrt = dvarcond*dvarcond /svary;
Processing sensitivityBrutForceMethodFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ****************************************************** ** sensitivityBrutForceMethodFlowrate nbins[10] nCond[50] ** ** nX[8] ** nS[4000] ** ymod : std[45.6059] vary[2079.9] ***************************** *** rw *** S1[ rw] Cond. Var.[1763.28] -- [0.847774] Info in <TCanvas::Print>: png file SAFlowRateVersusrw.png has been created ***************************** *** r *** S1[ r] Cond. Var.[0.0624988] -- [3.00489e-05] Info in <TCanvas::Print>: png file SAFlowRateVersusr.png has been created ***************************** *** tu *** S1[ tu] Cond. Var.[0.0886501] -- [4.26223e-05] Info in <TCanvas::Print>: png file SAFlowRateVersustu.png has been created ***************************** *** tl *** S1[ tl] Cond. Var.[0.0909604] -- [4.37331e-05] Info in <TCanvas::Print>: png file SAFlowRateVersustl.png has been created ***************************** *** hu *** S1[ hu] Cond. Var.[88.368] -- [0.0424867] Info in <TCanvas::Print>: png file SAFlowRateVersushu.png has been created ***************************** *** hl *** S1[ hl] Cond. Var.[88.2039] -- [0.0424078] Info in <TCanvas::Print>: png file SAFlowRateVersushl.png has been created ***************************** *** l *** S1[ l] Cond. Var.[84.9543] -- [0.0408454] Info in <TCanvas::Print>: png file SAFlowRateVersusl.png has been created ***************************** *** kw *** S1[ kw] Cond. Var.[20.8848] -- [0.0100413] Info in <TCanvas::Print>: png file SAFlowRateVersuskw.png has been created
The objective of this macro is to compute the finite differences indexes on a function.
{
// loading the flowrateModel function
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer and add the attributes (stochastic variables here)
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
tds->getAttribute("rw")->setDefaultValue(0.075);
tds->getAttribute("r")->setDefaultValue(25000.0);
tds->getAttribute("tu")->setDefaultValue(90000.0);
tds->getAttribute("tl")->setDefaultValue(90.0);
tds->getAttribute("hu")->setDefaultValue(1050.0);
tds->getAttribute("hl")->setDefaultValue(760.0);
tds->getAttribute("l")->setDefaultValue(1400.0);
tds->getAttribute("kw")->setDefaultValue(10500.0);
// Create a TFiniteDifferences object
TFiniteDifferences * tfindef = new TFiniteDifferences(tds,"flowrateModel", "rw:r:tu:tl:hu:hl:l:kw", "y", "steps=1%");
tfindef->setDrawProgressBar(kFALSE);
tfindef->computeIndexes();
TMatrixD matRes = tfindef->getSensitivityMatrix();
matRes.Print();
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the
file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific interval:
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
Each parameter gets a default value:
tds->getAttribute("rw")->setDefaultValue(0.075);
tds->getAttribute("r")->setDefaultValue(25000.0);
tds->getAttribute("tu")->setDefaultValue(90000.0);
tds->getAttribute("tl")->setDefaultValue(90.0);
tds->getAttribute("hu")->setDefaultValue(1050.0);
tds->getAttribute("hl")->setDefaultValue(760.0);
tds->getAttribute("l")->setDefaultValue(1400.0);
tds->getAttribute("kw")->setDefaultValue(10500.0);
To instantiate the TFiniteDifferences
object, one uses the TDataServer
, the name of the function,
the name of the output of the function, the names of the input variables separated by ":" and the option to specify
the sampling:
TFiniteDifferences * tfindef = new TFiniteDifferences(tds, "flowrateModel", "rw:r:tu:tl:hu:hl:l:kw","y", "steps=1%");
Computation of sensitivity indexes:
tfindef->computeIndexes();
Processing sensitivityFiniteDifferencesFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 1x8 matrix is as follows | 0 | 1 | 2 | 3 | 4 | ---------------------------------------------------------------------- 0 | 1019 -3.586e-07 1.265e-09 0.001265 0.1321 | 5 | 6 | 7 | ---------------------------------------------------------------------- 0 | -0.1321 -0.02729 0.003639
The objective of this macro is to perform a SRC regression on data stored in a TDataServer
. Data are loaded in
the TDataServer
from an ASCII data file flowrateUniformDesign.dat
:
#NAME: flowrateborehole #TITLE: Uniform design of flow rate borehole problem proposed by Ho and Xu(2000) #COLUMN_NAMES: rw| r| tu| tl| hu| hl| l| kw | ystar #COLUMN_TITLES: r_{#omega}| r | T_{u} | T_{l} | H_{u} | H_{l} | L | K_{#omega} | y^{*} #COLUMN_UNITS: m | m | m^{2}/yr | m^{2}/yr | m | m | m | m/yr | m^{3}/yr 0.0500 33366.67 63070.0 116.00 1110.00 768.57 1200.0 11732.14 26.18 0.0500 100.00 80580.0 80.73 1092.86 802.86 1600.0 10167.86 14.46 0.0567 100.00 98090.0 80.73 1058.57 717.14 1680.0 11106.43 22.75 0.0567 33366.67 98090.0 98.37 1110.00 734.29 1280.0 10480.71 30.98 0.0633 100.00 115600.0 80.73 1075.71 751.43 1600.0 11106.43 28.33 0.0633 16733.33 80580.0 80.73 1058.57 785.71 1680.0 12045.00 24.60 0.0700 33366.67 63070.0 98.37 1092.86 768.57 1200.0 11732.14 48.65 0.0700 16733.33 115600.0 116.00 990.00 700.00 1360.0 10793.57 35.36 0.0767 100.0 115600.0 80.73 1075.71 751.43 1520.0 10793.57 42.44 0.0767 16733.33 80580.0 80.73 1075.71 802.86 1120.0 9855.00 44.16 0.0833 50000.00 98090.0 63.10 1041.43 717.14 1600.0 10793.57 47.49 0.0833 50000.00 115600.0 63.10 1007.14 768.57 1440.0 11419.29 41.04 0.0900 16733.33 63070.0 116.00 1075.71 751.43 1120.0 11419.29 83.77 0.0900 33366.67 115600.0 116.00 1007.14 717.14 1360.0 11106.43 60.05 0.0967 50000.00 80580.0 63.10 1024.29 820.00 1360.0 9855.00 43.15 0.0967 16733.33 80580.0 98.37 1058.57 700.00 1120.0 10480.71 97.98 0.1033 50000.00 80580.0 63.10 1024.29 700.00 1520.0 10480.71 74.44 0.1033 16733.33 80580.0 98.37 1058.57 820.00 1120.0 10167.86 72.23 0.1100 50000.00 98090.0 63.10 1024.29 717.14 1520.0 10793.57 82.18 0.1100 100.00 63070.0 98.37 1041.43 802.86 1600.0 12045.00 68.06 0.1167 33366.67 63070.0 116.00 990.00 785.71 1280.0 12045.00 81.63 0.1167 100.00 98090.0 98.37 1092.86 802.86 1680.0 9855.00 72.5 0.1233 16733.33 115600.0 80.73 1092.86 734.29 1200.0 11419.29 161.35 0.1233 16733.33 63070.0 63.10 1041.43 785.71 1680.0 12045.00 86.73 0.1300 33366.67 80580.0 116.00 1110.00 768.57 1280.0 11732.14 164.78 0.1300 100.00 98090.0 98.37 1110.00 820.00 1280.0 10167.86 121.76 0.1367 50000.00 98090.0 63.10 1007.14 820.00 1440.0 10167.86 76.51 0.1367 33366.67 98090.0 116.00 1024.29 700.00 1200.0 10480.71 164.75 0.1433 50000.00 63070.0 116.00 990.00 785.71 1440.0 9855.00 89.54 0.1433 50000.00 115600.0 63.10 1007.14 734.29 1440.0 11732.14 141.09 0.1500 33366.67 63070.0 98.37 990.00 751.43 1360.0 11419.29 139.94 0.1500 100.00 115600.0 80.73 1041.43 734.29 1520.0 11106.43 157.59
{
// Create a TDataServer
TDataServer * tds = new TDataServer();
// Load a database in an ASCII file
tds->fileDataRead("flowrateUniformDesign.dat");
// Graph
TCanvas *Canvas = new TCanvas("c2", "Graph for the Macro",5,64,1270,667);
// Visualisation
tds->Draw("ystar:rw");
// Sensitivity analysis
TRegression *treg = new TRegression(tds, "rw:r:tu:tl:hu:hl:l:kw", "ystar", "src");
treg->computeIndexes();
treg->drawIndexes("Flowrate", "", "hist,first");
//treg->getResultTuple()->Scan();
// Graph
TCanvas *c = (TCanvas *)(gROOT->FindObject("__sensitivitycan__0"));
TCanvas *can = new TCanvas("c1", "Graph for the Macro sensitivityDataBaseFlowrate",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2);
pad->cd(1);
Canvas->DrawClonePad();
pad->cd(2);
c->DrawClonePad();
}
The TDataServer
is filled with the data file flowrateUniformDesign.dat
through the
fileDataRead
method:
tds->fileDataRead("flowrateUniformDesign.dat");
The regression is performed on all the variables with a SRC method and sensitivity indexes are computed:
TRegression *treg = new TRegression(tds, "rw:r:tu:tl:hu:hl:l:kw", "ystar", "src");
treg->computeIndexes();
The objective of this macro is to perform a Fast sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1.
void sensitivityFASTFunctionFlowrate(){
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// \param Size of a sampling.
Int_t nS = 4000;
// Graph
TFast * tfast = new TFast(tds, "flowrateModel", nS);
tfast->setDrawProgressBar(kFALSE);
tfast->computeIndexes("graph");
tfast->getResultTuple()->Scan("Out:Inp:Order:Method:Value","Algo==\"--first--\"");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the
file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific interval:
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
To instantiate the TFast
object, one uses the TDataServer
, the name of the function and the number
of samplings needed to perform sensitivity analysis (here nS=500):
TFast * tfast = new TFast(tds, "flowrateModel", nS);
Computation of sensitivity indexes:
tfast->computeIndexes();
Processing sensitivityFASTFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSpaceFilling.cxx] Line[167] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowreate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ************************************************************************ * Row * Out * Inp * Order * Method * Value * ************************************************************************ * 0 * flowrateM * rw * First * FAST * 0.8278187 * * 2 * flowrateM * r * First * FAST * 8.924e-07 * * 4 * flowrateM * tu * First * FAST * 2.308e-06 * * 6 * flowrateM * tl * First * FAST * 3.204e-05 * * 8 * flowrateM * hu * First * FAST * 0.0414390 * * 10 * flowrateM * hl * First * FAST * 0.0414046 * * 12 * flowrateM * l * First * FAST * 0.0392873 * * 14 * flowrateM * kw * First * FAST * 0.0094983 * ************************************************************************ ==> 8 selected entries
The objective of this macro is to perform a RBD sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1.
void sensitivityRBDFunctionFlowrate(){
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// \param Size of a sampling.
Int_t nS = 4000;
// Graph
TRBD * trbd = new TRBD(tds, "flowrateModel", nS);
trbd->setDrawProgressBar(kFALSE);
trbd->computeIndexes("graph");
trbd->getResultTuple()->Scan("Out:Inp:Order:Method:Value","Algo==\"--first--\"");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
To instantiate the TRBD
object, one uses the TDataServer
, the name of the function and the number
of samplings needed to perform sensitivity analysis (here =4000):
TRBD * trbd = new TRBD(tds, "flowrateModel", nS);
Computation of sensitivity indexes:
trbd->computeIndexes();
Processing sensitivityRBDFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSpaceFilling.cxx] Line[167] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowrate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ************************************************************************ * Row * Out * Inp * Order * Method * Value * ************************************************************************ * 0 * flowrateM * rw * First * RBD * 0.7558010 * * 2 * flowrateM * r * First * RBD * 0.0026080 * * 4 * flowrateM * tu * First * RBD * 0.0035324 * * 6 * flowrateM * tl * First * RBD * 0.0032848 * * 8 * flowrateM * hu * First * RBD * 0.0408758 * * 10 * flowrateM * hl * First * RBD * 0.0469345 * * 12 * flowrateM * l * First * RBD * 0.0347870 * * 14 * flowrateM * kw * First * RBD * 0.0165843 * ************************************************************************ ==> 8 selected entries
The objective of this macro is to perform a Morris sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1.
void sensitivityMorrisFunctionFlowrate(Int_t nk = 5)
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
Int_t nreplique = 3;
Int_t nlevel = 10;
TMorris * scmo = new TMorris(tds, "flowrateModel", nreplique, nlevel);
scmo->setDrawProgressBar(kFALSE);
scmo->generateSample();
tds->exportData("_morris_sampling_.dat");
scmo->computeIndexes();
tds->exportData("_morris_launching_.dat");
TTree *ntresu = scmo->getMorrisResults();
ntresu->Scan("*");
// Graph
TCanvas *cc = new TCanvas("c1", "Graph for the Macro sensitivityMorrisFunctionFlowrate",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2);
pad->cd(1);
scmo->drawSample("", -1,"nonewcanv");
pad->cd(2);
scmo->drawIndexes("mustar,nonewcanv");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval:
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
To instantiate the TMorris
, one uses the TDataServer
, the name of the function, the number of
replicas (here nreplique=3), the level parameter (here nlevel=10)
TMorris * scmo = new TMorris(tds, "flowrateModel", nreplique, nlevel);
Creation of the sampling:
scmo->generateSample();
Data are exported in an ASCII file:
tds->exportData("_morris_sampling_.dat");
Computation of sensitivity indexes:
scmo->computeIndexes();
Processing sensitivityMorrisFunctionFlowrate.C... ************************************************************************ * Row * Input * Output * mu.mu * mustar.mu * sigma.sig * ************************************************************************ * 0 * rw * flowrateM * 127.47900 * 127.47900 * 34.521839 * * 1 * r * flowrateM * -0.069601 * 0.0696013 * 0.0793689 * * 2 * tu * flowrateM * 0.0004201 * 0.0004201 * 0.0004641 * * 3 * tl * flowrateM * 0.4659763 * 0.4659763 * 0.3301256 * * 4 * hu * flowrateM * 21.192361 * 21.192361 * 8.8498989 * * 5 * hl * flowrateM * -32.74887 * 32.748874 * 30.146134 * * 6 * l * flowrateM * -23.89328 * 23.893280 * 8.2781934 * * 7 * kw * flowrateM * 7.5766167 * 7.5766167 * 2.7457665 * ************************************************************************
The objective of this macro is to perform a Morris sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1, but this time using the Relauncher architecture.
void sensitivityMorrisFunctionFlowrateRunner(Int_t nk = 5)
{
gROOT->LoadMacro("UserFunctions.C");
// Define the attributes
TUniformDistribution rw("rw", 0.05, 0.15);
TUniformDistribution r("r", 100.0, 50000.0);
TUniformDistribution tu("tu", 63070.0, 115600.0);
TUniformDistribution tl("tl", 63.1, 116.0);
TUniformDistribution hu("hu", 990.0, 1110.0);
TUniformDistribution hl("hl", 700.0, 820.0);
TUniformDistribution l("l", 1120.0, 1680.0);
TUniformDistribution kw("kw", 9855.0, 12045.0);
// Create the evaluator
TCIntEval code("flowrateModel");
// Create output attribute
TAttribute yout("flowrateModel");
// Provide input/output attributes to the assessor
code.setInputs(8, &rw, &r, &tu, &tl, &hu, &hl, &l, &kw);
code.setOutputs(1, &yout);
TSequentialRun run(&code); // To be replaced to distribute the computation
run.startSlave();
if( run.onMaster())
{
// Create the dataserver
TDataServer *tds = new TDataServer("sobol", "foo bar pouet chocolat");
tds->addAttribute(&rw);
tds->addAttribute(&r);
tds->addAttribute(&tu);
tds->addAttribute(&tl);
tds->addAttribute(&hu);
tds->addAttribute(&hl);
tds->addAttribute(&l);
tds->addAttribute(&kw);
Int_t nreplique = 3;
Int_t nlevel = 10;
// Create the Morris object
TMorris * scmo = new TMorris(tds, &run, nreplique, nlevel);
scmo->setDrawProgressBar(kFALSE);
scmo->generateSample();
tds->exportData("_morris_sampling_.dat");
scmo->computeIndexes();
tds->exportData("_morris_launching_.dat");
TTree *ntresu = scmo->getMorrisResults();
ntresu->Scan("*");
// Graph
TCanvas *cc = new TCanvas("c1", "Graph for the Macro sensitivityMorrisFunctionFlowrateRunner",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2);
pad->cd(1);
scmo->drawSample("", -1,"nonewcanv");
pad->cd(2);
scmo->drawIndexes("mustar,nonewcanv");
}
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval:
// Define the attributes
TUniformDistribution rw("rw", 0.05, 0.15);
TUniformDistribution r("r", 100.0, 50000.0);
TUniformDistribution tu("tu", 63070.0, 115600.0);
TUniformDistribution tl("tl", 63.1, 116.0);
TUniformDistribution hu("hu", 990.0, 1110.0);
TUniformDistribution hl("hl", 700.0, 820.0);
TUniformDistribution l("l", 1120.0, 1680.0);
TUniformDistribution kw("kw", 9855.0, 12045.0);
The interface to the function is then defined, using the Relauncher interface, through a
TCIntEval
object and a sequential runner:
// Create the evaluator
TCIntEval code("flowrateModel");
// Create output attribute
TAttribute yout("flowrateModel");
// Provide input/output attributes to the assessor
code.setInputs(8, &rw, &r, &tu, &tl, &hu, &hl, &l, &kw);
code.setOutputs(1, &yout);
TSequentialRun run(&code); // To be replaced to distribute the computation
run.startSlave();
The dataserver object is defined only on the master to avoid useless replication if one wants to run the estimation
of the function in parallel (by changing the TSequentialRun
by either a
TThreadedRun
or a TMpiRun
). To instantiate the
TMorris
object, one uses the TDataServer
, a pointer to the chosen runner, the number of replicas
(here nreplique=3), the level parameter (here nlevel=10)
TMorris * scmo = new TMorris(tds, &run, nreplique, nlevel);
Creation of the sampling:
scmo->generateSample();
Data are exported in an ASCII file:
tds->exportData("_morris_sampling_.dat");
Computation of sensitivity indexes:
scmo->computeIndexes();
The rest of the code is providing command to get a final plot.
Processing sensitivityMorrisFunctionFlowrateRunner.C... ************************************************************************ * Row * Input * Output * mu.mu * mustar.mu * sigma.sig * ************************************************************************ * 0 * rw * flowrateM * 127.47900 * 127.47900 * 34.521839 * * 1 * r * flowrateM * -0.069601 * 0.0696013 * 0.0793689 * * 2 * tu * flowrateM * 0.0004201 * 0.0004201 * 0.0004641 * * 3 * tl * flowrateM * 0.4659763 * 0.4659763 * 0.3301256 * * 4 * hu * flowrateM * 21.192361 * 21.192361 * 8.8498989 * * 5 * hl * flowrateM * -32.74887 * 32.748874 * 30.146134 * * 6 * l * flowrateM * -23.89328 * 23.893280 * 8.2781934 * * 7 * kw * flowrateM * 7.5766167 * 7.5766167 * 2.7457665 * ************************************************************************
The objective of this macro is to perform a regression with "SRC" method on a database generated with a function
using sampling of parameters obeying uniform laws with 4000 patterns. flowrateModel
is a
function defined in Section IV.1.2.1 and "loaded" through the
macro UserFunctions.C
(the file can be found in
${URANIESYS}/share/uranie/macros
). Function flowrateModel
uses the eight
variables defined in Section IV.1.2.1 and set in the main macro.
void sensitivityRegressionFunctionFlowrate(){
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// \param Size of a sampling.
Int_t nS = 4000;
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->setDrawProgressBar(kFALSE);
tlf->run();
TRegression * treg = new TRegression(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel", "SRC");
treg->computeIndexes();
treg->getResultTuple()->SetScanField(60);
treg->getResultTuple()->Scan("Out:Inp:Method:Algo:Value:CILower:CIUpper","Order==\"First\"");
TCanvas *can = new TCanvas("c1", "Graph for the Macro sensitivityRegressionFunctionFlowrate",5,64,1270,667);
treg->drawIndexes("Flowrate", "", "hist,first,nonewcanv");
}
Each attribute is related to a TAttribute
obeying uniform laws on specific intervals:
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
The sampling is generated on 4000 patterns with a LHS method:
TSampling *sampling = new TSampling(tds, "lhs", 4000);
sampling->generateSample();
Function flowrateModel
is set to perform calculation on the sampling:
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->run();
The regression is performed over all variables:
TRegression * treg = new TRegression(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel", "SRRC");
treg->computeIndexes();
Sensitivity indexes are then displayed through an histogram and a pie graph:
TCanvas *cc = new TCanvas("canhist", "histgramme");
treg->drawIndexes("Flowrate", "", "nonewcanv,hist,first");
TCanvas *ccc = new TCanvas("canpie", "TPie");
treg->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
Processing sensitivityRegressionFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ************************************************************************************* * Row * Out * Inp * Metho * Algo * Value * CILower * CIUpper * ************************************************************************************* * 0 * flowra * rw * SRC^2 * --first-- * 0.820265 * -1 * -1 * * 2 * flowra * rw * SRC^2 * --rho^2-- * 0.81668 * 0.805846 * 0.826888 * * 4 * flowra * r * SRC^2 * --first-- * 5.97e-06 * -1 * -1 * * 6 * flowra * r * SRC^2 * --rho^2-- * 1.92e-06 * 2.65e-07 * 0.001339 * * 8 * flowra * tu * SRC^2 * --first-- * 8.64e-06 * -1 * -1 * * 10 * flowra * tu * SRC^2 * --rho^2-- * 4.03e-06 * 3.14e-07 * 0.001306 * * 12 * flowra * tl * SRC^2 * --first-- * 5.73e-05 * -1 * -1 * * 14 * flowra * tl * SRC^2 * --rho^2-- * 0.000209 * 7.34e-07 * 0.002085 * * 16 * flowra * hu * SRC^2 * --first-- * 0.039645 * -1 * -1 * * 18 * flowra * hu * SRC^2 * --rho^2-- * 0.037119 * 0.026221 * 0.049000 * * 20 * flowra * hl * SRC^2 * --first-- * 0.040597 * -1 * -1 * * 22 * flowra * hl * SRC^2 * --rho^2-- * 0.039708 * 0.028688 * 0.052470 * * 24 * flowra * l * SRC^2 * --first-- * 0.040895 * -1 * -1 * * 26 * flowra * l * SRC^2 * --rho^2-- * 0.041241 * 0.029896 * 0.054454 * * 28 * flowra * kw * SRC^2 * --first-- * 0.009174 * -1 * -1 * * 30 * flowra * kw * SRC^2 * --rho^2-- * 0.009090 * 0.004191 * 0.015767 * * 32 * flowra * __sum__ * SRC^2 * --first-- * 0.95065 * -1 * -1 * * 34 * flowra * __R2__ * SRC^2 * --first-- * 0.947296 * -1 * -1 * * 36 * flowra * __R2A__ * SRC^2 * --first-- * 0.94719 * -1 * -1 * ************************************************************************************* ==> 19 selected entries
The objective of this macro is to perform Sobol sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1.
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
Int_t ns = 100000;
TSobol * tsobol = new TSobol(tds, "flowrateModel", ns, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel", "pouet");
tsobol->setDrawProgressBar(kFALSE);
tsobol->computeIndexes();
tsobol->getResultTuple()->Scan("*","Algo==\"--first--\" || Algo==\"--total--\"");
TCanvas *cc = new TCanvas("c1", "histgramme",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,1);
pad->cd(1);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,hist,all");
pad->cd(2);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
gSystem->Rename("_sobol_launching_.dat","ref_sobol_launching_.dat");
tds->exportData("_onlyMandN_sobol_launching_.dat","rw:r:tu:tl:hu:hl:l:kw:flowrateModel","sobol__n__iter__tdsflowreate < 100");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the
file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific interval:
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
To instantiate the TSobol
, one uses the TDataServer
, the name of the function and the number of samplings
needed to perform sensitivity analysis (here ns=600):
TSobol * tsobol = new TSobol(tds, "flowrateModel", ns, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel", "pouet");
Computation of the sensitivity indexes:
tsobol->computeIndexes();
The automatic backup of data (the file _sobol_launching_.dat
) is renamed so that it can be
used in other macros (see Section XIV.5.13 and Section XIV.5.15) while the tds contains is exported (only the and matrices content) to be also used in another macro (Section XIV.5.14) :
gSystem->Rename("_sobol_launching_.dat","ref_sobol_launching_.dat");
tds->exportData("_onlyMandN_sobol_launching_.dat","rw:r:tu:tl:hu:hl:l:kw:flowrateModel","sobol__n__iter__tdsflowreate < 100");
Processing sensitivitySobolFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSamplerStochastic.cxx] Line[66] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowreate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ** Case of Output atty [flowrateModel] nSimPerIndex 10000 ** Input att [rw] First [0.830033] Total Order[0.865762] ** Input att [r] First [0] Total Order[0.000102212] ** Input att [tu] First [0] Total Order[0.0001] ** Input att [tl] First [0] Total Order[0.000110756] ** Input att [hu] First [0.0417298] Total Order[0.0554922] ** Input att [hl] First [0.0367345] Total Order[0.0526188] ** Input att [l] First [0.0384214] Total Order[0.0535728] ** Input att [kw] First [0.00669831] Total Order[0.0132316] ************************************************************************************************************ * Row * Out.Out * Inp.Inp * Order.Ord * Method.Me * Algo.Algo * Value.Val * CILower.C * CIUpper.C * ************************************************************************************************************ * 0 * flowrateM * rw * First * Sobol * --first-- * 0.8300331 * 0.8238356 * 0.8360321 * * 4 * flowrateM * rw * Total * Sobol * --total-- * 0.8657619 * 0.8465652 * 0.8850599 * * 8 * flowrateM * r * First * Sobol * --first-- * 0 * 0 * 0.0196004 * * 12 * flowrateM * r * Total * Sobol * --total-- * 0.0001022 * 9.828e-05 * 0.0001062 * * 16 * flowrateM * tu * First * Sobol * --first-- * 0 * 0 * 0.0196004 * * 20 * flowrateM * tu * Total * Sobol * --total-- * 0.0001000 * 9.615e-05 * 0.0001039 * * 24 * flowrateM * tl * First * Sobol * --first-- * 0 * 0 * 0.0196004 * * 28 * flowrateM * tl * Total * Sobol * --total-- * 0.0001107 * 0.0001064 * 0.0001151 * * 32 * flowrateM * hu * First * Sobol * --first-- * 0.0417297 * 0.0221474 * 0.0612800 * * 36 * flowrateM * hu * Total * Sobol * --total-- * 0.0554921 * 0.0534156 * 0.0576470 * * 40 * flowrateM * hl * First * Sobol * --first-- * 0.0367345 * 0.0171464 * 0.0562944 * * 44 * flowrateM * hl * Total * Sobol * --total-- * 0.0526187 * 0.0506469 * 0.0546652 * * 48 * flowrateM * l * First * Sobol * --first-- * 0.0384214 * 0.0188352 * 0.0579782 * * 52 * flowrateM * l * Total * Sobol * --total-- * 0.0535727 * 0.0515661 * 0.0556552 * * 56 * flowrateM * kw * First * Sobol * --first-- * 0.0066983 * 0 * 0.0262952 * * 60 * flowrateM * kw * Total * Sobol * --total-- * 0.0132315 * 0.0127261 * 0.0137570 * * 64 * flowrateM * __sum__ * First * Sobol * --first-- * 0.9536171 * -1 * -1 * * 65 * flowrateM * __sum__ * Total * Sobol * --total-- * 1.0409902 * -1 * -1 * ************************************************************************************************************ ==> 18 selected entries
The objective of this macro is to perform Sobol sensitivity analysis on a set of eight parameters used in the
flowrateModel
model described in Section IV.1.2.1, but this time using the Relauncher architecture.
{
gROOT->LoadMacro("UserFunctions.C");
// Define the attributes
TUniformDistribution rw("rw", 0.05, 0.15);
TUniformDistribution r("r", 100.0, 50000.0);
TUniformDistribution tu("tu", 63070.0, 115600.0);
TUniformDistribution tl("tl", 63.1, 116.0);
TUniformDistribution hu("hu", 990.0, 1110.0);
TUniformDistribution hl("hl", 700.0, 820.0);
TUniformDistribution l("l", 1120.0, 1680.0);
TUniformDistribution kw("kw", 9855.0, 12045.0);
// Create the evaluator
TCIntEval code("flowrateModel");
// Create output attribute
TAttribute yout("flowrateModel");
// Provide input/output attributes to the assessor
code.setInputs(8, &rw, &r, &tu, &tl, &hu, &hl, &l, &kw);
code.setOutputs(1, &yout);
TSequentialRun run(&code); // To be replaced to distribute the computation
run.startSlave();
if( run.onMaster())
{
// Create the dataserver
TDataServer *tds = new TDataServer("sobol", "foo bar pouet chocolat");
tds->addAttribute(&rw);
tds->addAttribute(&r);
tds->addAttribute(&tu);
tds->addAttribute(&tl);
tds->addAttribute(&hu);
tds->addAttribute(&hl);
tds->addAttribute(&l);
tds->addAttribute(&kw);
// Create the sobol object
Int_t ns = 100000;
TSobol * tsobol = new TSobol(tds, &run, ns);
tsobol->setDrawProgressBar(kFALSE);
tsobol->computeIndexes();
if ( 1 ) {
TCanvas *cc = new TCanvas("c1", "histgramme",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,1);
pad->cd(1);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,hist,all");
pad->cd(2);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
}
}
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the
file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific interval:
// Define the attributes
TUniformDistribution rw("rw", 0.05, 0.15);
TUniformDistribution r("r", 100.0, 50000.0);
TUniformDistribution tu("tu", 63070.0, 115600.0);
TUniformDistribution tl("tl", 63.1, 116.0);
TUniformDistribution hu("hu", 990.0, 1110.0);
TUniformDistribution hl("hl", 700.0, 820.0);
TUniformDistribution l("l", 1120.0, 1680.0);
TUniformDistribution kw("kw", 9855.0, 12045.0);
The interface to the function is then defined, using the Relauncher interface, through a
TCIntEval
object and a sequential runner:
// Create the evaluator
TCIntEval code("flowrateModel");
// Create output attribute
TAttribute yout("flowrateModel");
// Provide input/output attributes to the assessor
code.setInputs(8, &rw, &r, &tu, &tl, &hu, &hl, &l, &kw);
code.setOutputs(1, &yout);
TSequentialRun run(&code); // To be replaced to distribute the computation
run.startSlave();
To instantiate the TSobol
, one uses the TDataServer
, a pointer to the runner and the number of
samplings needed to perform sensitivity analysis (here ns=600):
TSobol * tsobol = new TSobol(tds, &run, ns);
Computation of the sensitivity indexes:
tsobol->computeIndexes();
Data are exported from the TDataServer
to an ASCII file:
tds->exportData("_sobol_launching_.dat");
Processing sensitivitySobolFunctionFlowrateRunner.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSamplerStochastic.cxx] Line[66] <URANIE::INFO> TSamplerStochastic::init: the TDS [sobol] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ** Case of Output atty [flowrateModel] nSimPerIndex 10000 ** Input att [rw] First [0.830033] Total Order[0.865762] ** Input att [r] First [0] Total Order[0.000102212] ** Input att [tu] First [0] Total Order[0.0001] ** Input att [tl] First [0] Total Order[0.000110756] ** Input att [hu] First [0.0417298] Total Order[0.0554922] ** Input att [hl] First [0.0367345] Total Order[0.0526188] ** Input att [l] First [0.0384214] Total Order[0.0535728] ** Input att [kw] First [0.00669831] Total Order[0.0132316]
Warning
The levele command will be installed on your machine only if a Fortran compiler is found
The objective of this macro is to perform a SRC and SRRC measurement on the temporal use-case levele. This use-case is an example of code that takes a dozen of entries in order to compute the evolution of dose as a function of time. The result of every computation consists in 3 vectors: the time (always the same value disregarding all entries), the dose called "y" and a third useless information.
{
// OS abstraction
string which_levele =
string(gSystem->GetBuildArch()) == "win64" ? "where levele" : "which levele";
//Exit if levele not found
if(gSystem->Exec(which_levele.c_str()))
exit(-1);
//Create DataServer and add input attributes
TDataServer *tds = new URANIE::DataServer::TDataServer("tds", "levelE usecase");
tds->addAttribute( new TUniformDistribution("t", 100, 1000));
tds->addAttribute( new TLogUniformDistribution("kl", 0.001, .01));
tds->addAttribute( new TLogUniformDistribution("kc", 1.0e-6, 1.0e-5));
tds->addAttribute( new TLogUniformDistribution("v1", 1.0e-3, 1.0e-1));
tds->addAttribute( new TUniformDistribution("l1", 100., 500.));
tds->addAttribute( new TUniformDistribution("r1", 1., 5.));
tds->addAttribute( new TUniformDistribution("rc1", 3., 30.));
tds->addAttribute( new TLogUniformDistribution("v2", 1.0e-2, 1.0e-1));
tds->addAttribute( new TUniformDistribution("l2", 50., 200.));
tds->addAttribute( new TUniformDistribution("r2", 1., 5.));
tds->addAttribute( new TUniformDistribution("rc2", 3., 30.));
tds->addAttribute( new TLogUniformDistribution("w", 1.0e5, 1.0e7));
//Tell the code where to find attribute value in input file
TString sIn = "levelE_input_with_values_rows.in";
tds->getAttribute("t")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("kl")->setFileKey(sIn,"", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("kc")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("v1")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("l1")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("r1")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("rc1")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("v2")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("l2")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("r2")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("rc2")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
tds->getAttribute("w")->setFileKey(sIn, "", "%e",TAttributeFileKey::kNewRow);
// Create DOE
Int_t ns = 1024;
TSampling *samp = new TSampling(tds, "lhs", ns);
samp->generateSample();
//How to read ouput files
TOutputFileRow *out = new TOutputFileRow("_output_levelE_withRow_.dat");
//Tell the output file that attribute IS a vector and is SECOND column
out->addAttribute(new TAttribute("y", TAttribute::kVector), 2 );
//Creation of TCode
TCode *myc = new TCode(tds," levele 2> /dev/null");
myc->addOutputFile(out);
//Run the code
TLauncher * tl = new TLauncher(tds, myc);
tl->run();
//Launch Regression
TRegression *tsen = new TRegression(tds, "t:kl:kc:v1:l1:r1:rc1:v2:l2:r2:rc2:w" , "y", "SRCSRRC");
tsen->computeIndexes();
TTree *res=tsen->getResultTuple();
//Plotting mess
double tps[26]={20000,30000,40000,50000,60000,70000,80000,90000,100000, 200000,300000,400000,500000,600000,700000,800000,900000, 1e+06,2e+06,3e+06,4e+06,5e+06,6e+06,7e+06,8e+06,9e+06};
int colors[12] ={1,2,3,4,6,7,8,15,30,38,41,46};
TCanvas *c2 = new TCanvas("c2","c2",5,64,1600,500);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(3,1); pad->cd(1);
gPad->SetLogx(); gPad->SetGrid();
TMultiGraph *mg = new TMultiGraph();
res->Draw("Value","Inp==\"__R2__\" && Order==\"Total\" && Method==\"SRRC^2\"","goff");
double *data3=res->GetV1();
TGraph *gr3 = new TGraph(26,tps,data3); gr3->SetMarkerColor(2); gr3->SetLineColor(2); gr3->SetMarkerStyle(23);
mg->Add(gr3);
res->Draw("Value","Inp==\"__R2__\" && Order==\"Total\" && Method==\"SRC^2\"","goff");
double *data4=res->GetV1();
TGraph *gr4 = new TGraph(26,tps,data4); gr4->SetMarkerColor(4); gr4->SetLineColor(4); gr4->SetMarkerStyle(23);
mg->Add(gr4);
mg->Draw("APC");
mg->GetXaxis()->SetTitle("Time");
mg->GetYaxis()->SetTitle("#sum Sobol");
mg->GetYaxis()->SetRangeUser(0.0,1.0);
//Legend
gStyle->SetLegendBorderSize(0);
gStyle->SetFillStyle(0);
TLegend *lg = new TLegend(0.25,0.7,0.45,0.9);
lg->AddEntry(gr4,"R2 SRC","lp");
lg->AddEntry(gr3,"R2 SRRC","lp");
lg->Draw();
pad->cd(2); gPad->SetLogx(); gPad->SetGrid();
TMultiGraph *mg2 = new TMultiGraph();
string names[12] = {"t","kl","kc","v1","l1","r1","rc1","v2","l2","r2","rc2","w"};
TGraph *src[12];
TLegend *leg = new TLegend(0.25,0.3,0.45,0.89,"Cumulative contributions");
leg->SetTextSize(0.035);
for(unsigned int igr=0; igr<12; igr++)
{
string sel="Inp==\""+names[igr]+"\" && Order==\"Total\" && Method==\"SRC^2\" && Algo!=\"--rho^2--\"";
res->Draw("Value", sel.c_str(),"goff");
double *data=res->GetV1();
src[igr] = new TGraph();
src[igr]->SetMarkerColor(colors[igr]); src[igr]->SetLineColor(colors[igr]); src[igr]->SetFillColor(colors[igr]);
src[igr]->SetPoint(0, 0.99999999*tps[0], 0);
for(unsigned int ip=0; ip<26; ip++)
{
double x=0, y=0;
if(igr!=0)
src[igr-1]->GetPoint(ip+1,x,y);
src[igr]->SetPoint(ip+1, tps[ip], y+data[ip]);
}
src[igr]->SetPoint(27, tps[25]*1.000000001, 0);
leg->AddEntry(src[igr],names[igr].c_str(),"f");
}
for(int igr2=11; igr2>-1; igr2--)
mg2->Add(src[igr2]);
mg2->Draw("AFL");
mg2->GetXaxis()->SetTitle("Time");
mg2->GetYaxis()->SetTitle("SRC^{2}");
mg2->GetYaxis()->SetRangeUser(0.0,0.3);
leg->Draw();
pad->cd(3); gPad->SetLogx(); gPad->SetGrid();
TMultiGraph *mg3 = new TMultiGraph();
TGraph *srrc[12];
for(unsigned int igr=0; igr<12; igr++)
{
string sel="Inp==\""+names[igr]+"\" && Order==\"Total\" && Method==\"SRRC^2\" && Algo!=\"--rho^2--\"";
res->Draw("Value", sel.c_str(),"goff");
double *data=res->GetV1();
srrc[igr] = new TGraph();
srrc[igr]->SetMarkerColor(colors[igr]); srrc[igr]->SetLineColor(colors[igr]); srrc[igr]->SetFillColor(colors[igr]);
srrc[igr]->SetPoint(0, 0.99999999*tps[0], 0);
for(unsigned int ip=0; ip<26; ip++)
{
double x=0, y=0;
if(igr!=0)
srrc[igr-1]->GetPoint(ip+1,x,y);
srrc[igr]->SetPoint(ip+1, tps[ip], y+data[ip]);
}
srrc[igr]->SetPoint(27, tps[25]*1.000000001, 0);
srrc[igr]->SetTitle( names[igr].c_str() );
}
for(int igr2=11; igr2>-1; igr2--)
mg3->Add(srrc[igr2]);
// mg3->Draw("a fb l3d");
mg3->Draw("AFL");
mg3->GetXaxis()->SetTitle("Time");
mg3->GetYaxis()->SetTitle("SRRC^{2}");
mg3->GetYaxis()->SetRangeUser(0.0,1.0);
leg->Draw();
}
The levele external code is located in the bin directory of the Uranie installation.
When looking at the code and comparing it to an usual Regression estimation, the organisation is completely transparent. The only noticeable (and compulsory) thing to do is to change the default type of the attribute read at the end of the job. This is done in this line:
out->addAttribute(new TAttribute("y", TAttribute::kVector), 2 );
where the output attribute is provided, changing its nature to a vector, thanks to the second argument of the
TAttribute
constructor from the default (kReal
) to the desired
nature (kVector
). Once this is done, this information is broadcast internally to the code
that knows how to deal with this type of attribute.
The rest of the code is the graphical part, leading to the figure below (it is provided to illustrate how to represent results).
The results of the previous macro is shown in Figure XIV.53, where the left panel represents the value of the coefficients both the SRC and SRRC coefficients estimation. The middle and right panel display the cumulative sum of the quadratic value of the coefficient respectively for the SRC and SRRC case.
Warning
The levele command will be installed on your machine only if a Fortran compiler is found
The objective of this macro is to perform a full Sobol analysis on the temporal use-case levele. This use-case is an example of code that takes a dozen of entries in order to compute the evolution of dose as a function of time. The result of every computation consists in 3 vectors: the time (always the same value disregarding all entries), the dose called "y" and a third useless information.
{
// OS abstraction
string which_levele =
string(gSystem->GetBuildArch()) == "win64" ? "where levele" : "which levele";
//Exit if levele not found
if(gSystem->Exec(which_levele.c_str()))
exit(-1);
// Define the DataServer
TDataServer *tds = new TDataServer("tdsLevelE","levele");
tds->addAttribute( new TUniformDistribution("t", 100, 1000) );
tds->addAttribute( new TLogUniformDistribution("kl", 0.001, 0.01) );
tds->addAttribute( new TLogUniformDistribution("kc", 0.000001, 0.00001) );
tds->addAttribute( new TLogUniformDistribution("v1", 0.001, 0.1) );
tds->addAttribute( new TUniformDistribution("l1", 100, 500) );
tds->addAttribute( new TUniformDistribution("r1", 1, 5) );
tds->addAttribute( new TUniformDistribution("rc1", 3, 30) );
tds->addAttribute( new TLogUniformDistribution("v2", 0.01, 0.1) );
tds->addAttribute( new TUniformDistribution("l2", 50, 200) );
tds->addAttribute( new TUniformDistribution("r2", 1, 5) );
tds->addAttribute( new TUniformDistribution("rc2", 3, 30) );
tds->addAttribute( new TLogUniformDistribution("w", 100000, 10000000) );
//Tell the code where to find attribute value in input file
TString sIn="levelE_input_with_values_rows.in";
tds->getAttribute("t")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("kl")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("kc")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("v1")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("l1")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("r1")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("rc1")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("v2")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("l2")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("r2")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("rc2")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
tds->getAttribute("w")->setFileKey(sIn, "", "%e", TAttributeFileKey::kNewRow);
//How to read ouput files
TOutputFileRow *out = new TOutputFileRow("_output_levelE_withRow_.dat");
//Tell the output file that attribute IS a vector and is SECOND column
out->addAttribute(new TAttribute("y", TAttribute::kVector), 2 );
//Creation of TCode
TCode *myc = new TCode(tds,"levele 2> /dev/null");
myc->addOutputFile(out);
//Run Sobol analysis
TSobol * tsobol = new TSobol(tds, myc, 10000);
tsobol->computeIndexes();
TTree *ntresu = (TTree*)tsobol->getResultTuple();
//Plotting mess
int colors[12] ={1,2,3,4,6,7,8,15,30,38,41,46};
double tps[26]={20000,30000,40000,50000,60000,70000,80000,90000,100000, 200000,300000,400000,500000,600000,700000,800000,900000, 1e+06,2e+06,3e+06,4e+06,5e+06,6e+06,7e+06,8e+06,9e+06};
TCanvas *c2 = new TCanvas("c2","c2",5,64,1200,900);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(1,2); pad->cd(1); gPad->SetLogx(); gPad->SetGrid();
//LegendandMArker
gStyle->SetMarkerStyle(3);
gStyle->SetLegendBorderSize(0);
gStyle->SetFillStyle(0);
TMultiGraph *mg2 = new TMultiGraph();
string names[12] = {"t","kl","kc","v1","l1","r1","rc1","v2","l2","r2","rc2","w"};
TGraphAsymmErrors *fdeg[12];
TLegend *leg[6]; double *data, *themin, *themax;
for(unsigned int igr=0; igr<12; igr++)
{
stringstream sel; sel << "Inp==\"" << names[igr] << "\" && Order==\"First\" && Algo==\"martinez11\"";
ntresu->Draw("CILower:CIUpper:Value", sel.str().c_str(),"goff");
data=ntresu->GetV3();
themin=ntresu->GetV1();
themax=ntresu->GetV2();
for(unsigned int i=0; i<26; i++)
{
themin[i] = data[i] - themin[i];
themax[i] = - data[i] + themax[i];
}
if(igr%2==0)
{
leg[igr/2] = new TLegend(0.1+0.15*(igr/2),0.91,0.25+0.15*(igr/2),0.98);
leg[igr/2]->SetTextSize(0.045);
}
fdeg[igr] = new TGraphAsymmErrors(26,tps, data,0, 0, themin, themax);
fdeg[igr]->SetMarkerColor(colors[igr]); fdeg[igr]->SetLineColor(colors[igr]); fdeg[igr]->SetFillColor(colors[igr]);
leg[igr/2]->AddEntry(fdeg[igr],names[igr].c_str(),"pl");
}
for(int igr2=11; igr2>-1; igr2--)
mg2->Add(fdeg[igr2]);
mg2->Draw("APC");
mg2->GetXaxis()->SetTitle("Time");
mg2->GetYaxis()->SetTitle("S_{1}[martinez11]");
for( int igr3=0; igr3<6; igr3++ )
leg[igr3]->Draw();
TMultiGraph *mg = new TMultiGraph();
TGraphAsymmErrors *tdeg[12];
pad->cd(2); gPad->SetLogx(); gPad->SetGrid();
for(unsigned int igr=0; igr<12; igr++)
{
stringstream sel; sel << "Inp==\"" << names[igr] << "\" && Order==\"Total\" && Algo==\"martinez11\"";
ntresu->Draw("CILower:CIUpper:Value", sel.str().c_str(),"goff");
data=ntresu->GetV3();
themin=ntresu->GetV1();
themax=ntresu->GetV2();
for(unsigned int i=0; i<26; i++)
{
themin[i] = data[i] - themin[i];
themax[i] = - data[i] + themax[i];
}
for(unsigned int ip=0; ip<26; ip++)
{
if(ip==0)
{
tdeg[igr] = new TGraphAsymmErrors();
tdeg[igr]->SetMarkerColor(colors[igr]); tdeg[igr]->SetLineColor(colors[igr]); tdeg[igr]->SetFillColor(colors[igr]);
}
tdeg[igr]->SetPoint(ip, tps[ip], data[ip]);
tdeg[igr]->SetPointError(ip, 0, 0, themin[ip], themax[ip]);
}
}
for(int igr2=11; igr2>-1; igr2--)
mg->Add(tdeg[igr2]);
mg->Draw("APC");
mg->GetXaxis()->SetTitle("Time");
mg->GetYaxis()->SetTitle("S_{T}[martinez11]");
for( int igr3=0; igr3<6; igr3++ )
leg[igr3]->Draw();
}
The levele external code is located in the bin directory of the Uranie installation.
When looking at the code and comparing it to an usual Sobol estimation, the organisation is completely transparent. The only noticeable (and compulsory) thing to do is to change the default type of the attribute read at the end of the job. This is done in this line:
out->addAttribute(new TAttribute("y", TAttribute::kVector), 2 );
where the output attribute is provided, changing its nature to a vector, thanks to the second argument of the
TAttribute
constructor from the default (kReal
) to the desired
nature (kVector
). Once this is done, this information is broadcast internally to the code
that knows how to deal with this type of attribute.
The rest of the code is the graphical part, leading to the figure below (it is provided to illustrate how to represent results).
The results of the previous macro is shown in Figure XIV.54, where the evolution of the sobol coefficient is shown for all inputs with the uncertainty band, for the first order coefficient and the total one, respectively on the top and bottom panel.
The objective of this macro is to perform a full Sobol analysis using the existing file created when the Sobol class is allowed to perform the design-of-experiments and the estimations by itself (see the first item in the tip box in Section VI.5.2 for more details). This would mean that the only computation done would be to estimate the coefficients (no external code / function called).
Warning
Theref_sobol_launching_.dat
file used as input is not provided in the usual sub-directory
"/share/uranie/macros" of the installation folder of Uranie
($URANIESYS) but can be generated by the user by running the macro discussed in Section XIV.5.9.
{
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->fileDataRead("ref_sobol_launching_.dat");
TSobol * tsobol = new TSobol(tds, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel");
tsobol->computeIndexes();
TCanvas *cc = new TCanvas("c1", "histgramme",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,1);
pad->cd(1);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,hist,all");
pad->cd(2);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
}
There are no external code or function to be run here. The input file ref_sobol_launching_.dat
has to be generated by the use of sensitivtySobolFunctionFlowrate.C
. Once done it is loaded
into the dataserver and the TSobol
object is constructed from the simplest constructor with
only the pointer to the dataserver, the input and output list:
TSobol * tsobol = new TSobol(tds, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel");
Once done, the computeIndexes()
method is called and few lines are shown to display the
results in the classical plot form, leading to the figure below (it is provided to illustrate how to represent
results). The numerical results are shown in the console below and are identical to the ones shown in Section XIV.5.9.4 from where the full sample is coming from.
The results of the previous macro is shown in Figure XIV.55, where the evolution of the sobol coefficient is shown for all inputs with the uncertainty band, for the first order coefficient and the total one, respectively on the top and bottom panel.
Processing sensitivitySobolRe-estimation.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ** Case of Output atty [flowrateModel] nSimPerIndex 10000 ** Input att [rw] First [0.830033] Total Order[0.865762] ** Input att [r] First [0] Total Order[0.000102212] ** Input att [tu] First [0] Total Order[0.0001] ** Input att [tl] First [0] Total Order[0.000110756] ** Input att [hu] First [0.0417298] Total Order[0.0554922] ** Input att [hl] First [0.0367345] Total Order[0.0526188] ** Input att [l] First [0.0384214] Total Order[0.0535728] ** Input att [kw] First [0.00669831] Total Order[0.0132316]
The objective of this macro is to perform a Sobol analysis using the some already made computations in order to be able to save ressources. The idea (discussed in the second item in the tip box in Section VI.5.2 is indeed to use the provided points as the first estimations corresponding to both the and matrices content. The class will still have to create all the cross configurations (the matrices) and launch their corresponding estimations. In order to do that there are few things to keep in mind:
The input file (here
_onlyMandN_sobol_launching_.dat
) should contains input and output variables only, the user being in charge of having a decent design-of-experiments for the sobol estimation.
Warning
The_onlyMandN_sobol_launching_.dat
file used as input is not provided in the usual sub-directory
"/share/uranie/macros" of the installation folder of Uranie
($URANIESYS) but can be generated by the user by running the macro discussed in Section XIV.5.9.
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->fileDataRead("_onlyMandN_sobol_launching_.dat");
int ns=10000;
TSobol * tsobol = new TSobol(tds, "flowrateModel", ns, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel", "WithData");
tsobol->setDrawProgressBar(kFALSE);
tsobol->computeIndexes();
TCanvas *cc = new TCanvas("c1", "histgramme",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,1);
pad->cd(1);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,hist,all");
pad->cd(2);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
}
As for Section XIV.5.9, the UserFunctions.C
file
is loaded and the input file _onlyMandN_sobol_launching_.dat
(which should have been
generated by the use of sensitivtySobolFunctionFlowrate.C
), is loaded into the
dataserver. The TSobol
object is constructed from the usual function constructor with a
noticing difference: the option field is filled with WithData to specify that data are
already there and the code has to use these data and split them into both the and matrices.
TSobol * tsobol = new TSobol(tds, "flowrateModel", ns, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel", "WithData");
Once done, the computeIndexes()
method is called and few lines are shown to display the
results in the classical plot form, leading to the figure below (it is provided to illustrate how to represent
results). The numerical results are shown in the console below and are identical to the ones shown in Section XIV.5.9.4 from where the original set of points is coming from.
The results of the previous macro is shown in Figure XIV.56, where the evolution of the sobol coefficient is shown for all inputs with the uncertainty band, for the first order coefficient and the total one, respectively on the top and bottom panel.
Processing sensitivitySobolWithData.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ** Case of Output atty [flowrateModel] nSimPerIndex 10000 ** Input att [rw] First [0.830033] Total Order[0.865762] ** Input att [r] First [0] Total Order[0.000102212] ** Input att [tu] First [0] Total Order[0.0001] ** Input att [tl] First [0] Total Order[0.000110756] ** Input att [hu] First [0.0417298] Total Order[0.0554922] ** Input att [hl] First [0.0367345] Total Order[0.0526188] ** Input att [l] First [0.0384214] Total Order[0.0535728] ** Input att [kw] First [0.00669831] Total Order[0.0132316]
The objective of this macro is to perform a full Sobol analysis using the existing file created when the Sobol class is allowed to perform the design-of-experiments and the estimations by itself when this one is not considered accurate enough (from the statistical point of view). The idea is to use anyway all the computations already done and generate some more to increase the statistical precision. In order to do that there are few things to keep in mind:
The problem should obviously be exactly the same: same input and output (name, statistical laws, parameter values...).
The input file (here
ref_sobol_launching_.dat
) should contains the internal variable in order to figure out from what matrices every configuration is taken out of (generally an iterator whose name should look likesobol__n__iter__
plus the dataserver name).If the pseudo-random generator seed is set to a given value, bBe sure that you are not be using the same seed than the once used to generate the input file, which would lead to twice the same events.
One can find another discussion for this objective in the third item in the tip box in Section VI.5.2.
Warning
Theref_sobol_launching_.dat
file used as input is not provided in the usual sub-directory
"/share/uranie/macros" of the installation folder of Uranie
($URANIESYS) but can be generated by the user by running the macro discussed in Section XIV.5.9.
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
int ns=100000;
TSobol * tsobol = new TSobol(tds, "flowrateModel", ns, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel");
tsobol->loadOtherSobolFile("ref_sobol_launching_.dat");
tsobol->setDrawProgressBar(kFALSE);
tsobol->computeIndexes();
tsobol->getResultTuple()->Scan("*","Algo==\"--first--\" || Algo==\"--total--\"");
TCanvas *cc = new TCanvas("c1", "histgramme",5,64,1270,667);
TPad *pad = new TPad("pad","pad",0, 0.03, 1, 1); pad->Draw();
pad->Divide(2,1);
pad->cd(1);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,hist,all");
pad->cd(2);
tsobol->drawIndexes("Flowrate", "", "nonewcanv,pie,first");
}
As for Section XIV.5.9, the UserFunctions.C
file
is loaded and all the input stochastic distribution are chosen wisely. The number of new estimations is set (to
10000, doubling the statistic as this is also the number used in Section XIV.5.9 which provided the input file that would be used to complete this
estimation).
All the code lines are exactly those taken out of Section XIV.5.9.2 but the one that is used to load a previous estimation which is shown below:
tsobol->loadOtherSobolFile("ref_sobol_launching_.dat");
Once done, the computeIndexes()
method is called and few lines are shown to display the
results in the classical plot form, leading to the figure below (it is provided to illustrate how to represent
results). The numerical results are shown in the console below and the improvement in terms of statistical
precision can be seen by comparing the 95 percent confidence intervals going from Section XIV.5.9.4 to Section XIV.5.15.4.
The results of the previous macro is shown in Figure XIV.57, where the evolution of the sobol coefficient is shown for all inputs with the uncertainty band, for the first order coefficient and the total one, respectively on the top and bottom panel.
Processing sensitivitySobolLoadFile.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[759] <URANIE::WARNING> TDataServer::fileDataRead: Expected iterator tdsflowreate_1__n__iter__ not found but tdsflowreate__n__iter__ looks like an URANIE iterator => Will be used as so. <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSamplerStochastic.cxx] Line[66] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowreate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ** Case of Output atty [flowrateModel] nSimPerIndex 20000 ** Input att [rw] First [0.823516] Total Order[0.873849] ** Input att [r] First [0] Total Order[5.22438e-05] ** Input att [tu] First [0] Total Order[5e-05] ** Input att [tl] First [0] Total Order[6.08391e-05] ** Input att [hu] First [0.0319889] Total Order[0.0547724] ** Input att [hl] First [0.0304453] Total Order[0.0540884] ** Input att [l] First [0.0315935] Total Order[0.0527791] ** Input att [kw] First [0] Total Order[0.0129065] ************************************************************************************************************ * Row * Out.Out * Inp.Inp * Order.Ord * Method.Me * Algo.Algo * Value.Val * CILower.C * CIUpper.C * ************************************************************************************************************ * 0 * flowrateM * rw * First * Sobol * --first-- * 0.8235162 * 0.8190045 * 0.8279262 * * 4 * flowrateM * rw * Total * Sobol * --total-- * 0.8738492 * 0.8602341 * 0.8875120 * * 8 * flowrateM * r * First * Sobol * --first-- * 0 * 0 * 0.0138594 * * 12 * flowrateM * r * Total * Sobol * --total-- * 5.224e-05 * 5.081e-05 * 5.371e-05 * * 16 * flowrateM * tu * First * Sobol * --first-- * 0 * 0 * 0.0138594 * * 20 * flowrateM * tu * Total * Sobol * --total-- * 5.000e-05 * 4.863e-05 * 5.140e-05 * * 24 * flowrateM * tl * First * Sobol * --first-- * 0 * 0 * 0.0138594 * * 28 * flowrateM * tl * Total * Sobol * --total-- * 6.083e-05 * 5.917e-05 * 6.254e-05 * * 32 * flowrateM * hu * First * Sobol * --first-- * 0.0319888 * 0.0181374 * 0.0458280 * * 36 * flowrateM * hu * Total * Sobol * --total-- * 0.0547723 * 0.0533147 * 0.0562686 * * 40 * flowrateM * hl * First * Sobol * --first-- * 0.0304453 * 0.0165929 * 0.0442861 * * 44 * flowrateM * hl * Total * Sobol * --total-- * 0.0540884 * 0.0526485 * 0.0555665 * * 48 * flowrateM * l * First * Sobol * --first-- * 0.0315935 * 0.0177418 * 0.0454330 * * 52 * flowrateM * l * Total * Sobol * --total-- * 0.0527791 * 0.0513732 * 0.0542224 * * 56 * flowrateM * kw * First * Sobol * --first-- * 0 * 0 * 0.0138594 * * 60 * flowrateM * kw * Total * Sobol * --total-- * 0.0129065 * 0.0125558 * 0.0132669 * * 64 * flowrateM * __sum__ * First * Sobol * --first-- * 0.9175440 * -1 * -1 * * 65 * flowrateM * __sum__ * Total * Sobol * --total-- * 1.0485587 * -1 * -1 * ************************************************************************************************************ ==> 18 selected entries
The objective of this macro is to perform a sensitivity analysis using the Johnson's relative weight method on a
set of eight parameters used in the flowrateModel
model described in Section IV.1.2.1.
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// \param Size of a sampling.
Int_t nS = 1000;
TString FuncName="flowrateModel";
TJohnsonRW *tjrw = new TJohnsonRW(tds, FuncName, nS, "rw:r:tu:tl:hu:hl:l:kw", FuncName);
tjrw->computeIndexes();
// Get the results on screen
tjrw->getResultTuple()->Scan("Out:Inp:Method:Value","Order==\"First\"");
// Get the results as plots
TCanvas *cc = new TCanvas("canhist", "histgramme");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,hist,first");
cc->Print("appliUranieFlowrateJohnsonRW1000Histogram.png");
TCanvas *ccc = new TCanvas("canpie", "TPie");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,pie");
ccc->Print("appliUranieFlowrateJohnsonRW1000Pie.png");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
To instantiate the TJohnsonRW
object, one uses the TDataServer
, the name of the function, the number
of samplings needed to perform sensitivity analysis (here =4000) and the input and output variables:
TJohnsonRW * tjrw = new TJohnsonRW(tds, FuncName, nS, "rw:r:tu:tl:hu:hl:l:kw", FuncName);
Computation of sensitivity indexes:
trbd->computeIndexes();
The rest is very common to all sensitivity macros discussed here: it will produce two plots (the first one being a histogram show below) and the console is also shown below for completness.
Processing sensitivityJohnsonRWFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSamplerStochastic.cxx] Line[66] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowrate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ************************************************************ * Row * Out * Inp * Method * Value * ************************************************************ * 0 * flowrateM * rw * JohnsonRW * 0.8636266 * * 2 * flowrateM * r * JohnsonRW * 4.598e-05 * * 4 * flowrateM * tu * JohnsonRW * 8.775e-06 * * 6 * flowrateM * tl * JohnsonRW * 9.689e-05 * * 8 * flowrateM * hu * JohnsonRW * 0.0439173 * * 10 * flowrateM * hl * JohnsonRW * 0.0435594 * * 12 * flowrateM * l * JohnsonRW * 0.0378304 * * 14 * flowrateM * kw * JohnsonRW * 0.0109144 * * 16 * flowrateM * __R2__ * JohnsonRW * 0.9447092 * * 18 * flowrateM * __R2A__ * JohnsonRW * 0.9442633 * ************************************************************ ==> 10 selected entries
The objective of this macro is to perform a sensitivity analysis using the Johnson's relative weight method on a
set of eight parameters used in the flowrateModel
model described in Section IV.1.2.1. Compared to version detailled in Section XIV.5.16, the idea is here to correlate the input variables
with a random correlation matrix.
// Function defined to generate randomly a good, highly-correlated, input correlation matrix
TMatrixD GenCorr(int _nX=8, bool correlated=true)
{
gRandom->SetSeed(__rdtsc());
//Define a randomly filled matrix
TMatrixD A(_nX,_nX);
for (int i=0; i<_nX; i++)
for (int j=0; j<_nX; j++)
A(i,j)=gRandom->Gaus(0,1);
// Compute AA^T and normalise it to get "covariance matrix"
TMatrixD Gamma(A,TMatrixD::kMultTranspose,A);
Gamma*=1./_nX;
// Get the inverse of the diagonal matrix to do as if this was 1/sqrt(variance)
TMatrixD Sig(_nX,_nX);
for(int i=0;i<_nX;i++) Sig(i,i)=1./sqrt( Gamma(i,i) );
// Compute the correlation matrix
TMatrixD Corr(Sig*Gamma,TMatrixD::kMult, Sig);
if( !correlated )
Corr.UnitMatrix();
return Corr;
}
void sensitivityJohnsonRWCorrelatedFunctionFlowrate()
{
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// \param Size of a sampling.
Int_t nS = 1000;
TString FuncName="flowrateModel";
// Get a correlation matrix for the inputs
TMatrixD inCorr=GenCorr(8,true);
inCorr.Print();
TJohnsonRW *tjrw = new TJohnsonRW(tds, FuncName, nS, "rw:r:tu:tl:hu:hl:l:kw", FuncName);
//Set the correlation
tjrw->setInputCorrelationMatrix(inCorr);
tjrw->computeIndexes();
// Get the results on screen
tjrw->getResultTuple()->Scan("Out:Inp:Method:Value","Order==\"First\"");
// Get the results as plots
TCanvas *cc = new TCanvas("canhist", "histgramme");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,hist,first");
cc->Print("appliUranieFlowrateJohnsonRWCorrelated1000Histogram.png");
TCanvas *ccc = new TCanvas("canpie", "TPie");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,pie");
ccc->Print("appliUranieFlowrateJohnsonRWCorrelated1000Pie.png");
}
The first function, called GenCorr
, is not discussed, because it is really technical and
not really interesting here. The only thing to know is that it provides a proper correlation matrix: a
positive-definite symmetrical matrix.
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Compared to the discussion in Section XIV.5.16.2, the instantiation of the attributes and the
TJohnsonRW
object is the same. The only difference is done when injecting the correlation
matrix, which is done in these lines:
// Get a correlation matrix for the inputs
TMatrixD inCorr=GenCorr(8,true);
//Set the correlation
tjrw->setInputCorrelationMatrix(inCorr);
The computation of sensitivity indices can finally be done:
trbd->computeIndexes();
The rest is very common to all sensitivity macros discussed here: it will produce two plots (the first one being a histogram show below) and the console is also shown below for completness.
Processing sensitivityJohnsonRWCorrelatedFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 8x8 matrix is as follows | 0 | 1 | 2 | 3 | 4 | ---------------------------------------------------------------------- 0 | 1 0.4488 0.2894 -0.05727 0.3627 1 | 0.4488 1 0.02022 -0.2547 0.3764 2 | 0.2894 0.02022 1 0.4982 -0.2078 3 | -0.05727 -0.2547 0.4982 1 -0.9199 4 | 0.3627 0.3764 -0.2078 -0.9199 1 5 | 0.2569 -0.1996 -0.288 0.1004 -0.1362 6 | -0.2167 -0.4425 0.004268 0.1412 -0.111 7 | -0.2948 0.1982 -0.001661 0.1943 -0.3131 | 5 | 6 | 7 | ---------------------------------------------------------------------- 0 | 0.2569 -0.2167 -0.2948 1 | -0.1996 -0.4425 0.1982 2 | -0.288 0.004268 -0.001661 3 | 0.1004 0.1412 0.1943 4 | -0.1362 -0.111 -0.3131 5 | 1 -0.1943 0.2848 6 | -0.1943 1 -0.4415 7 | 0.2848 -0.4415 1 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::INFO> <URANIE::INFO> *** URANIE INFORMATION *** <URANIE::INFO> *** File[${SOURCEDIR}/meTIER/sampler/souRCE/TSamplerStochastic.cxx] Line[66] <URANIE::INFO> TSamplerStochastic::init: the TDS [tdsflowrate] contains data: we need to empty it ! <URANIE::INFO> *** END of URANIE INFORMATION *** <URANIE::INFO> ************************************************************ * Row * Out * Inp * Method * Value * ************************************************************ * 0 * flowrateM * rw * JohnsonRW * 0.5113911 * * 2 * flowrateM * r * JohnsonRW * 0.1409327 * * 4 * flowrateM * tu * JohnsonRW * 0.0505176 * * 6 * flowrateM * tl * JohnsonRW * 0.0482684 * * 8 * flowrateM * hu * JohnsonRW * 0.0969452 * * 10 * flowrateM * hl * JohnsonRW * 0.0306674 * * 12 * flowrateM * l * JohnsonRW * 0.0836757 * * 14 * flowrateM * kw * JohnsonRW * 0.0376016 * * 16 * flowrateM * __R2__ * JohnsonRW * 0.9500813 * * 18 * flowrateM * __R2A__ * JohnsonRW * 0.9496787 * ************************************************************ ==> 10 selected entries
The objective of this macro is to perform a sensitivity analysis using the Johnson's relative weight method on a
set of eight parameters which IS NOT the usual flowrateModel
model. Indeed, compared to
version detailled in Section XIV.5.17,
the idea is here to correlate the input variables with a random correlation matrix and to translate this into a
full correlation matrix, meaning defining a "fake" output by computing their covariance with every input as if this
output was a perfect linear combination of these inputs.
An important particularity of this study is that no data are generated at all, it only uses the correlation matrix.
// Function defined to generate randomly a good, highly-correlated, correlation matrix for inputs
// and defibe the proper covariance with the output to do as if this output if a perfect linear combination
// of the inputs
TMatrixD GenCorr(int _nX=8, bool correlated=true)
{
gRandom->SetSeed(__rdtsc());
//Define a randomly filled matrix
TMatrixD A(_nX,_nX);
for (int i=0; i<_nX; i++)
for (int j=0; j<_nX; j++)
A(i,j)=gRandom->Gaus(0,1);
// Compute AA^T and normalise it to get "covariance matrix"
TMatrixD Gamma(A,TMatrixD::kMultTranspose,A);
Gamma*=1./_nX;
// Get the inverse of the diagonal matrix to do as if this was 1/sqrt(variance)
TMatrixD Sig(_nX,_nX);
for(int i=0;i<_nX;i++) Sig(i,i)=1./sqrt( Gamma(i,i) );
// Compute the input correlation matrix
TMatrixD inCorr(Sig*Gamma,TMatrixD::kMult, Sig);
if( !correlated )
inCorr.UnitMatrix();
double varY=inCorr.Sum();
// Proper correlation, output included
TMatrixD Corr(_nX+1,_nX+1);
Corr.UnitMatrix();
// putting already defined input
Corr.SetSub(0,0,inCorr);
// Adjust the covariance of the output wrt to all inputs
for(unsigned int i=0; i<_nX; i++)
{
double value=0;
for(unsigned int j=0; j<_nX; j++)
value+=inCorr(i,j);
Corr(_nX,i) = Corr(i,_nX) = value / sqrt(varY);
}
return Corr;
}
void sensitivityJohnsonRWJustCorrelationFakeFlowrate()
{
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute("rw");
tds->addAttribute("r");
tds->addAttribute("tu");
tds->addAttribute("tl");
tds->addAttribute("hu");
tds->addAttribute("hl");
tds->addAttribute("l");
tds->addAttribute("kw");
// outputs
tds->addAttribute("flowrateModel");
tds->getAttribute("flowrateModel")->setOutput();
// Get the full correlation matrix
TMatrixD inCorr=GenCorr(8,true);
// Johnson definition
TJohnsonRW * tjrw = new TJohnsonRW(tds, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel");
//Putting the newly defined correlation that states our output as a perfect linear combination of inputs
tjrw->setCorrelationMatrix(inCorr);
tjrw->computeIndexes();
// Get the results on screen
tjrw->getResultTuple()->Scan("Out:Inp:Method:Value","Order==\"First\"");
// Get the results as plots
TCanvas *cc = new TCanvas("canhist", "histgramme");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,hist,first");
cc->Print("appliUranieFakeFlowrateJohnsonRWCorrelationHistogram.png");
TCanvas *ccc = new TCanvas("canpie", "TPie");
tjrw->drawIndexes("Flowrate", "", "nonewcanv,pie");
ccc->Print("appliUranieFakeFlowrateJohnsonRWCorrelationPie.png");
}
The first function, called GenCorr
, is not discussed, because it is really technical and
not really interesting here. The only thing to know is that it provides a proper correlation matrix: a
positive-definite symmetrical matrix for the input and it computes the covariance for a "fake" output that would be
a perfect linear combination of all the inputs.
Because of this, the function flowrateModel
is not loaded anymore and the definition of
the attributes is not the same: it is not necessary to use TStochasticAttribute
because no
data are generated here:
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowrate", "DataBase flowrate");
tds->addAttribute("rw");
tds->addAttribute("r");
tds->addAttribute("tu");
tds->addAttribute("tl");
tds->addAttribute("hu");
tds->addAttribute("hl");
tds->addAttribute("l");
tds->addAttribute("kw");
// outputs
tds->addAttribute("flowrateModel");
tds->getAttribute("flowrateModel")->setOutput();
Compared to the discussion in Section XIV.5.17.2, the only differences are the
instantiation of the TJohnsonRW
object and the method code to provide the correlation
matrix.
// Get the full correlation matrix
TMatrixD inCorr=GenCorr(8,true);
// Johnson definition
TJohnsonRW * tjrw = new TJohnsonRW(tds, "rw:r:tu:tl:hu:hl:l:kw", "flowrateModel");
//Putting the newly defined correlation that states our output as a perfect linear combination of inputs
tjrw->setCorrelationMatrix(inCorr);
The method called to provide the correlation matrix is setCorrelationMatrix
and it means
that the user give a full correlation matrix (input and output variables), on the contrary to the one used in Section XIV.5.17.2 which is
setInputCorrelationMatrix
, which set only the input correlation matrix.
The computation of sensitivity indices can finally be done:
trbd->computeIndexes();
The rest is very common to all sensitivity macros discussed here: it will produce two plots (the first one being a histogram show below) and the console is also shown below for completness.
Processing sensitivityJohnsonRWJustCorrelationFakeFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[2020] <URANIE::WARNING> TDataServer::getNPatterns[tdsflowrate] WARNING <URANIE::WARNING> The TTree is NULL <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/meTIER/sensitivity/souRCE/TSensitivity.cxx] Line[165] <URANIE::WARNING> TSensitivity::constructor ERROR The TTree is empty [] <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> <URANIE::WARNING> <URANIE::WARNING> *** URANIE WARNING *** <URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[8099] <URANIE::WARNING> TDataServer::getTuple Error : There is no tree! <URANIE::WARNING> *** END of URANIE WARNING *** <URANIE::WARNING> ************************************************************ * Row * Out * Inp * Method * Value * ************************************************************ * 0 * flowrateM * rw * JohnsonRW * 0.2844573 * * 2 * flowrateM * r * JohnsonRW * 0.1600467 * * 4 * flowrateM * tu * JohnsonRW * 0.2004196 * * 6 * flowrateM * tl * JohnsonRW * 0.0512434 * * 8 * flowrateM * hu * JohnsonRW * 0.0446220 * * 10 * flowrateM * hl * JohnsonRW * 0.1295644 * * 12 * flowrateM * l * JohnsonRW * 0.0333889 * * 14 * flowrateM * kw * JohnsonRW * 0.0962574 * * 16 * flowrateM * __R2__ * JohnsonRW * 1 * ************************************************************ ==> 9 selected entries
The objective of this macro is to perform a sensitivity analysis using the HSIC method on a
set of eight parameters used in the flowrateModel
model described in Section IV.1.2.1.
void sensitivityHSICFunctionFlowrate(){
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// Generation of the sample (it can be a given sample).
Int_t nS = 500;
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->setDrawProgressBar(kFALSE);
tlf->run();
// Create a THSIC object, compute indexes and print results
THSIC * thsic = new THSIC(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel");
thsic->computeIndexes("quiet");
thsic->getResultTuple()->SetScanField(60);
thsic->getResultTuple()->Scan("Out:Inp:Method:Order:Value:CILower:CIUpper");
// Print HSIC indexes
TCanvas *can = new TCanvas("c1", "Graph for the Macro sensitivityHSICFunctionFlowrate",5,64,1270,667);
thsic->drawIndexes("Flowrate", "", "hist,first,nonewcanv");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
HSIC does not need a specific DOE, it works with a given sample. We generate a sample with TSampling
and we evaluate it using TLauncherFunction
Int_t nS = 500;
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->setDrawProgressBar(kFALSE);
tlf->run();
To instantiate the THSIC
object, one uses the TDataServer
,the name of the input and output variables:
THSIC * thsic = new THSIC(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel");
Computation of sensitivity indexes:
thsic->computeIndexes();
It will produce one plots containing the HSIC indexes and the p-value to test the Independance between inputs and outputs.The console is also shown below for completness.
Processing sensitivityHSICFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ************************************************************************************* * Row * Out * Inp * Metho * Order * Value * CILower * CIUpper * ************************************************************************************* * 0 * flowra * rw * HSic * R2HSic * 0.804431 * -1 * -1 * * 1 * flowra * rw * HSic * HSic * 0.072723 * 0.071620 * 0.073826 * * 2 * flowra * rw * HSic * pValues * 6.8e-106 * -1 * -1 * * 3 * flowra * r * HSic * R2HSic * 0.002238 * -1 * -1 * * 4 * flowra * r * HSic * HSic * 0.000202 * -0.00090 * 0.001305 * * 5 * flowra * r * HSic * pValues * 0.712174 * -1 * -1 * * 6 * flowra * tu * HSic * R2HSic * 0.002528 * -1 * -1 * * 7 * flowra * tu * HSic * HSic * 0.000228 * -0.00087 * 0.001331 * * 8 * flowra * tu * HSic * pValues * 0.662668 * -1 * -1 * * 9 * flowra * tl * HSic * R2HSic * 0.003806 * -1 * -1 * * 10 * flowra * tl * HSic * HSic * 0.000344 * -0.00075 * 0.001447 * * 11 * flowra * tl * HSic * pValues * 0.449068 * -1 * -1 * * 12 * flowra * hu * HSic * R2HSic * 0.025554 * -1 * -1 * * 13 * flowra * hu * HSic * HSic * 0.002309 * 0.001206 * 0.003412 * * 14 * flowra * hu * HSic * pValues * 3.13e-05 * -1 * -1 * * 15 * flowra * hl * HSic * R2HSic * 0.020243 * -1 * -1 * * 16 * flowra * hl * HSic * HSic * 0.001829 * 0.000726 * 0.002932 * * 17 * flowra * hl * HSic * pValues * 0.000445 * -1 * -1 * * 18 * flowra * l * HSic * R2HSic * 0.024934 * -1 * -1 * * 19 * flowra * l * HSic * HSic * 0.002253 * 0.001150 * 0.003356 * * 20 * flowra * l * HSic * pValues * 5.64e-05 * -1 * -1 * * 21 * flowra * kw * HSic * R2HSic * 0.010567 * -1 * -1 * * 22 * flowra * kw * HSic * HSic * 0.000955 * -0.00014 * 0.002058 * * 23 * flowra * kw * HSic * pValues * 0.032459 * -1 * -1 * *************************************************************************************
The objective of this macro is to perform a sensitivity analysis using the SobolRank method on a
set of eight parameters used in the flowrateModel
model described in Section IV.1.2.1.
void sensitivitySobolRankFunctionFlowrate(){
gROOT->LoadMacro("UserFunctions.C");
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
// Generation of the sample (it can be a given sample).
Int_t nS = 500;
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->setDrawProgressBar(kFALSE);
tlf->run();
// Create a TSobolRank object, compute indexes and print results
TSobolRank * tsobolrank = new TSobolRank(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel");
tsobolrank->computeIndexes("quiet");
tsobolrank->getResultTuple()->SetScanField(60);
tsobolrank->getResultTuple()->Scan("Out:Inp:Method:Order:Value:CILower:CIUpper");
// Print Sobol indexes
TCanvas *can = new TCanvas("c1", "Graph for the Macro sensitivitySobolRankFunctionFlowrate",5,64,1270,667);
tsobolrank->drawIndexes("Flowrate", "", "hist,first,nonewcanv");
}
The function flowrateModel
is loaded from the macro UserFunctions.C
(the file can be found in ${URANIESYS}/share/uranie/macros
)
gROOT->LoadMacro("UserFunctions.C");
Each parameter is related to the TDataServer
as a TAttribute
and obeys an uniform law on specific
interval
// Define the DataServer
TDataServer *tds = new TDataServer("tdsflowreate", "DataBase flowreate");
tds->addAttribute( new TUniformDistribution("rw", 0.05, 0.15));
tds->addAttribute( new TUniformDistribution("r", 100.0, 50000.0));
tds->addAttribute( new TUniformDistribution("tu", 63070.0, 115600.0));
tds->addAttribute( new TUniformDistribution("tl", 63.1, 116.0));
tds->addAttribute( new TUniformDistribution("hu", 990.0, 1110.0));
tds->addAttribute( new TUniformDistribution("hl", 700.0, 820.0));
tds->addAttribute( new TUniformDistribution("l", 1120.0, 1680.0));
tds->addAttribute( new TUniformDistribution("kw", 9855.0, 12045.0));
SobolRank does not need a specific DOE, it works with a given sample. We generate a sample with TSampling
and we evaluate it using TLauncherFunction
Int_t nS = 500;
TSampling *sampling = new TSampling(tds, "lhs", nS);
sampling->generateSample();
TLauncherFunction * tlf = new TLauncherFunction(tds, "flowrateModel");
tlf->setDrawProgressBar(kFALSE);
tlf->run();
To instantiate the TSobolRank
object, one uses the TDataServer
,the name of the input and output variables:
TSobolRank * tsobolrank = new TSobolRank(tds, "rw:r:tu:tl:hu:hl:l:kw","flowrateModel");
Computation of sensitivity indexes:
tsobolrank->computeIndexes();
It will produce one plots containing the HSIC indexes and the p-value to test the Independance between inputs and outputs.The console is also shown below for completness.
Processing sensitivitySobolRankFunctionFlowrate.C... --- Uranie v0.0/0 --- Developed with ROOT (6.32.02) Copyright (C) 2013-2024 CEA/DES Contact: support-uranie@cea.fr Date: Tue Jan 09, 2024 ************************************************************************************* * Row * Out * Inp * Metho * Order * Value * CILower * CIUpper * ************************************************************************************* * 0 * flowra * rw * Sobol * First * 0.816872 * -1 * -1 * * 1 * flowra * r * Sobol * First * -0.04759 * -1 * -1 * * 2 * flowra * tu * Sobol * First * -0.04164 * -1 * -1 * * 3 * flowra * tl * Sobol * First * -0.00414 * -1 * -1 * * 4 * flowra * hu * Sobol * First * 0.041272 * -1 * -1 * * 5 * flowra * hl * Sobol * First * 0.036748 * -1 * -1 * * 6 * flowra * l * Sobol * First * 0.062867 * -1 * -1 * * 7 * flowra * kw * Sobol * First * 0.021273 * -1 * -1 * *************************************************************************************