--- myst: substitutions: macro: python: 1-5,18-45,48-54,56-68 cpp: 6-10,17-38,41-47,49-61 bloc1: python: 19-20 cpp: 6,17 bloc2: python: 24-26 cpp: 21-22 bloc3: python: "28" cpp: "24" bloc4: python: 34-41 cpp: 27-34 bloc5: python: 45,48 cpp: 38,41 bloc6: python: 50,54,57 cpp: 43,47,50 --- # Macro "**modelerFlowrateMultiLinearRegression.{{extension}}**" ## Objective The objective of the macro is to build a multilinear regression between the predictors {{floinputs}} and a target variable **yhat** from the database contained in the ASCII file `flowrate_sampler_launcher_500.dat` defining values for these eight variables described in [](#launcher_introduction_simple_case_problem) on 500 patterns. Parameters of the regression are then exported in a .{{extension}} file `_FileContainingFunction_.C`: {{ "```{literalinclude} " + parent_dir + "/usermanual/use_cases/files/_FileContainingFunction_.C" + "\n" + ":language: cpp\n" + "```" }} This file contains a `MultiLinearFunction` function. Comparison is made with a database generated from random variables obeying uniform laws and output variable calculated with this database and the `MultiLinearFunction` function. ## Macro {{uranie}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + macro[language] + "\n" + "```" }} The {{tds}} is loaded with the database contained in the file `flowrate_sampler_launcher_500.dat` with the `fileDataRead` method: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc1[language] + "\n" + "```" }} The linear regression is initialised and characteristic values are computed for each variable with the `estimate` method: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc2[language] + "\n" + "```" }} ```{only} py The last argument is the option field, which in most cases is empty. Here it is filled with "DummyPython" which helps specify to python which constructor to choose. There are indeed several possible constructors these 5 five first arguments, but C++ can make the difference between them as the literal members are either `std::string`, `ROOT::TString`, `Char_t*` or even `Option_t*`. For python, these format are all `PyString`, so the sixth argument is compulsory to disentangle the possibilities. ``` The model is exported in an external file in C++ language `_FileContainingFunction_.C` where the function name is `MultiLinearFunction`: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc3[language] + "\n" + "```" }} A second {{tds}} is created. The previous variables then obey uniform laws and are linked as `TAttribute` in this new {{tds}}: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc4[language] + "\n" + "```" }} A sampling is realised with a LHS method on 1000 patterns: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc5[language] + "\n" + "```" }} The previously exported macro `_FileContainingFunction_.C` is loaded so as to perform calculation over the database in the second {{tds}} with the function `MultiLinearFunction`. Results are stored in the **ymod** variable: {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerFlowrateMultiLinearRegression." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc6[language] + "\n" + "```" }} ## Graph {{ "```{figure} " + parent_dir + "/roottest/build/uranie/doc/modeler/use_cases/" + language + "/multi_linear_regression/modelerFlowrateMultiLinearRegression.png\n" + ":align: center\n" + ":name: use_cases_modelerFlowrateMultiLinearRegression\n" + figure_scale + "\n" + "\n" + "Graph of the macro **\"modelerFlowrateMultiLinearRegression." + extension + "\"**" + "\n" + "```" }}