13.7.4. Macro “modelerFlowrateNeuralNetworks.py”
13.7.4.1. Objective
The objective of this macro is to build a surrogate model (an Artificial Neural Network) from a
database. From a first database created from an ASCII file flowrate_sampler_launcher_500.dat (which
defines values for eight variables described in Presentation of the problem on
500 patterns), two ASCII files are created: one with the 300st patterns
(_flowrate_sampler_launcher_app_.dat), the other with the 200 last patterns
(_flowrate_sampler_launcher_val_.dat). The surrogate model is built with the database extracted
from the first of the two files, the second allowing to perform calculations with a function.
13.7.4.2. Macro Uranie
"""
Example of neural network usage on flowrate
"""
from URANIE import DataServer, Launcher, Modeler
import ROOT
# Create a DataServer.TDataServer
# Load a database in an ASCII file
tdsu = DataServer.TDataServer("tdsu", "tds u")
tdsu.fileDataRead("flowrate_sampler_launcher_500.dat")
#
tdsu.exportData("_flowrate_sampler_launcher_app_.dat", "",
"tdsFlowrate__n__iter__<=300")
tdsu.exportData("_flowrate_sampler_launcher_val_.dat", "",
"tdsFlowrate__n__iter__>300")
tds = DataServer.TDataServer("tdsFlowrate", "tds for flowrate")
tds.fileDataRead("_flowrate_sampler_launcher_app_.dat")
c = ROOT.TCanvas("c1", "Graph for the Macro modeler", 5, 64, 1270, 667)
# Buils a surrogate model (Artificial Neural Networks) from the DataBase
tann = Modeler.TANNModeler(tds, "rw:r:tu:tl:hu:hl:l:kw, 3,yhat")
tann.setFcnTol(1e-5)
# tann.setLog()
tann.train(3, 2, "test")
tann.exportFunction("pmmlc++", "uranie_ann_flowrate", "ANNflowrate")
ROOT.gROOT.LoadMacro("uranie_ann_flowrate.C")
tdsv = DataServer.TDataServer()
tdsv.fileDataRead("_flowrate_sampler_launcher_val_.dat")
print(tdsv.getNPatterns())
# evaluate the surrogate model on the database
tlf = Launcher.TLauncherFunction(tdsv, "ANNflowrate",
"rw:r:tu:tl:hu:hl:l:kw", "yann")
tlf.run()
tdsv.startViewer()
tdsv.Draw("yann:yhat")
# tdsv.draw("yhat")
The main TDataServer loads the main ASCII data file flowrate_sampler_launcher_500.dat
tdsu = DataServer.TDataServer("tdsu", "tds u")
tdsu.fileDataRead("flowrate_sampler_launcher_500.dat")
The database is split in two parts by exporting the 300st patterns in a file and the remaining 200 in another one:
tdsu.exportData("_flowrate_sampler_launcher_app_.dat", "",
"tdsFlowrate__n__iter__<=300")
tdsu.exportData("_flowrate_sampler_launcher_val_.dat", "",
"tdsFlowrate__n__iter__>300")
A second TDataServer loads _flowrate_sampler_launcher_app_.dat and builds the surrogate model over all
the variables:
tds = DataServer.TDataServer("tdsFlowrate", "tds for flowrate")
tds.fileDataRead("_flowrate_sampler_launcher_app_.dat")
tann = Modeler.TANNModeler(tds, "rw:r:tu:tl:hu:hl:l:kw, 3,yhat")
tann.setFcnTol(1e-5)
tann.train(3, 2, "test")
The model is exported in an external file in C++ language "uranie_ann_flowrate.C" where the function
name is ANNflowrate:
tann.exportFunction("c++", "uranie_ann_flowrate","ANNflowrate")
The model is loaded from the macro "uranie_ann_flowrate.C" and applied on the second database with
the function ANNflowrate:
ROOT.gROOT.LoadMacro("uranie_ann_flowrate.C")
tdsv = DataServer.TDataServer()
tdsv.fileDataRead("_flowrate_sampler_launcher_val_.dat")
tlf = Launcher.TLauncherFunction(tdsv, "ANNflowrate",
"rw:r:tu:tl:hu:hl:l:kw", "yann")
tlf.run()
13.7.4.3. Graph
Figure 13.40 Graph of the macro “modelerFlowrateNeuralNetworks.py”
13.7.4.4. 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
<URANIE::WARNING>
<URANIE::WARNING> *** URANIE WARNING ***
<URANIE::WARNING> *** File[${SOURCEDIR}/dataSERVER/souRCE/TDataServer.cxx] Line[760]
<URANIE::WARNING> TDataServer::fileDataRead: Expected iterator tdsu__n__iter__ not found but tdsFlowrate__n__iter__ looks like an URANIE iterator => Will be used as so.
<URANIE::WARNING> *** END of URANIE WARNING ***
<URANIE::WARNING>
** TANNModeler::train niter[3] ninit[2]
** init the ANN
** Input (1) Name[rw] Min[0.101018] Max[0.0295279]
** Input (2) Name[r] Min[25668.6] Max[14838.3]
** Input (3) Name[tu] Min[89914.4] Max[14909]
** Input (4) Name[tl] Min[89.0477] Max[15.0121]
** Input (5) Name[hu] Min[1048.92] Max[34.8615]
** Input (6) Name[hl] Min[763.058] Max[33.615]
** Input (7) Name[l] Min[1401.09] Max[163.611]
** Input (8) Name[kw] Min[10950.2] Max[635.503]
** Output (1) Name[yhat] Min[78.0931] Max[44.881]
** Tolerance (1e-05)
** sHidden (3) (3)
** Nb Weights (31)
** ActivationFunction[LOGISTIC]
**
** iter[1/3] : *= : mse_min[0.00150425]
** iter[2/3] : ** : mse_min[0.0024702]
** iter[3/3] : *= : mse_min[0.00122167]
** solutions : 3
** isol[1] iter[0] learn[0.00126206] test[0.00150425] *
** isol[2] iter[1] learn[0.00152949] test[0.0024702]
** isol[3] iter[2] learn[0.00107926] test[0.00122167] *
** CPU training finished. Total elapsed time: 1.84 sec
*******************************
*** TModeler::exportFunction lang[pmmlc++] file[uranie_ann_flowrate] name[ANNflowrate] soption[]
*******************************
*******************************
*** exportFunction lang[pmmlc++] file[uranie_ann_flowrate] name[ANNflowrate]
*******************************
PMML Constructor: uranie_ann_flowrate.pmml
*** End Of exportModelPMML
*******************************
*** End Of exportFunction
*******************************