13.7.7. Macro “modelerFlowratePolynChaosRegression.py”
13.7.7.1. Objective
The objective of this macro is to build a polynomial chaos expansion in order to get a surrogate model
along with a global sensitivity interpretation for the flowrate function, whose purpose and
behaviour have been already introduced in Presentation of the problem. The method
used here is the regression one, as discussed below.
13.7.7.2. Macro Uranie
"""
Example of Chaos polynomial expansion using regression estimation on flowrate
"""
from URANIE import DataServer, Launcher, Modeler
import ROOT
ROOT.gROOT.LoadMacro("UserFunctions.C")
# Define the DataServer
tds = DataServer.TDataServer("tdsflowreate", "DataBase flowreate")
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))
# Define of TNisp object
nisp = Modeler.TNisp(tds)
nisp.generateSample("QmcSobol", 500) # State that there is a sample ...
# Compute the output variable
tlf = Launcher.TLauncherFunction(tds, "flowrateModel", "*", "ymod")
tlf.setDrawProgressBar(False)
tlf.run()
# build a chaos polynomial
pc = Modeler.TPolynomialChaos(tds, nisp)
# compute the pc coefficients using the "Regression" method
degree = 4
pc.setDegree(degree)
pc.computeChaosExpansion("Regression")
# Uncertainty and sensitivity analysis
print("Variable ymod ================")
print("Mean = "+str(pc.getMean("ymod")))
print("Variance = "+str(pc.getVariance("ymod")))
print("First Order Indices ================")
print("Indice First Order[1] = "+str(pc.getIndexFirstOrder(0, 0)))
print("Indice First Order[2] = "+str(pc.getIndexFirstOrder(1, 0)))
print("Indice First Order[3] = "+str(pc.getIndexFirstOrder(2, 0)))
print("Indice First Order[4] = "+str(pc.getIndexFirstOrder(3, 0)))
print("Indice First Order[5] = "+str(pc.getIndexFirstOrder(4, 0)))
print("Indice First Order[6] = "+str(pc.getIndexFirstOrder(5, 0)))
print("Indice First Order[7] = "+str(pc.getIndexFirstOrder(6, 0)))
print("Indice First Order[8] = "+str(pc.getIndexFirstOrder(7, 0)))
print("Total Order Indices ================")
print("Indice Total Order[1] = "+str(pc.getIndexTotalOrder("rw", "ymod")))
print("Indice Total Order[2] = "+str(pc.getIndexTotalOrder("r", "ymod")))
print("Indice Total Order[3] = "+str(pc.getIndexTotalOrder("tu", "ymod")))
print("Indice Total Order[4] = "+str(pc.getIndexTotalOrder("tl", "ymod")))
print("Indice Total Order[5] = "+str(pc.getIndexTotalOrder("hu", "ymod")))
print("Indice Total Order[6] = "+str(pc.getIndexTotalOrder("hl", "ymod")))
print("Indice Total Order[7] = "+str(pc.getIndexTotalOrder("l", "ymod")))
print("Indice Total Order[8] = "+str(pc.getIndexTotalOrder("kw", "ymod")))
# Dump main factors up to a certain threshold
seuil = 0.99
print("Ordered functionnal ANOVA")
pc.getAnovaOrdered(seuil, 0)
print("Number of experiments = "+str(tds.getNPatterns()))
# save the pv in a program (C langage)
pc.exportFunction("NispFlowrate", "NispFlowrate")
The first part is just creating a TDataServer and providing the attributes needed to define the problem.
From there, a TNisp object is created, providing the dataserver that specifies the inputs. This
class is used to generate the sample.
# Define of TNisp object
nisp = Modeler.TNisp(tds)
nisp.generateSample("QmcSobol", 500) # State that there is a sample ...
The function is launched through a TLauncherFunction instance in order to get the output values
that will be needed to train the surrogate model.
tlf = Launcher.TLauncherFunction(tds, "flowrateModel", "*", "ymod")
tlf.run()
Finally, a TPolynomialChaos instance is created and the computation of the coefficients is
performed by requesting a truncature on the resulting degree of the polynomial expansion (set to 4)
and the use of a regression method.
pc = Modeler.TPolynomialChaos(tds, nisp)
# compute the pc coefficients using the "Regression" method
degree = 4
pc.setDegree(degree)
pc.computeChaosExpansion("Regression")
The rest of the code is showing how to access the resulting sensitivity indices either one-by-one, or ordered up to a chosen threshold of the output variance.
13.7.7.3. Console
--- Uranie v4.11/0 --- Developed with ROOT (6.36.06)
Copyright (C) 2013-2026 CEA/DES
Contact: support-uranie@cea.fr
Date: Thu Feb 12, 2026
Variable ymod ================
Mean = 77.65102218686935
Variance = 2079.6809330496953
First Order Indices ================
Indice First Order[1] = 0.8287315275344169
Indice First Order[2] = 1.0554825358264659e-06
Indice First Order[3] = 9.868045331678087e-08
Indice First Order[4] = 4.776680831542115e-06
Indice First Order[5] = 0.04140149326660007
Indice First Order[6] = 0.04132153620304167
Indice First Order[7] = 0.03940096615922832
Indice First Order[8] = 0.00954643619284736
Total Order Indices ================
Indice Total Order[1] = 0.8667727763800165
Indice Total Order[2] = 9.274665082296543e-06
Indice Total Order[3] = 7.017680590520732e-06
Indice Total Order[4] = 1.7194373944638416e-05
Indice Total Order[5] = 0.05419157561201169
Indice Total Order[6] = 0.05405781720242182
Indice Total Order[7] = 0.05221211558384676
Indice Total Order[8] = 0.012780873435736001