--- myst: substitutions: macro: python: 1-5,19-40,43-56,58-65,71-75 cpp: 6-10,17-33,36-48,50-58,65-68 bloc1: python: 29-30 cpp: 7,25 bloc2: python: 34-35 cpp: 28-29 bloc3: python: 37-38,40,44-46 cpp: 8,31,33,37-39 bloc4: python: "48" cpp: "41" bloc5: python: 50,52-53,56,58 cpp: 9,43,45,48,50 bloc6: python: 60,62-65,71-75 cpp: 52,54-57,64-68 console: python: 2-46 cpp: 6-50 --- # Macro "**modelerClassificationNeuralNetworks.{{extension}}**" ## Objective The objective of this macro is to build a surrogate model (an Artificial Neural Network) from a database for a **"Classification"** Problem. From a first database loaded from the ASCII file `problem2Classes_001000.dat`, which defines three variables $(x,y) \in [-1., 1]^{2}$ and $rc01 \in \{0, 1\}$ on 1000 patterns, {{ "```{figure} " + parent_dir + "/roottest/build/uranie/doc/modeler/use_cases/" + language + "/classification_neural_network/modelerClassificationNeuralNetworks_App.png\n" + ":align: center\n" + ":name: use_cases_modelerClassificationNeuralNetworks_App\n" + figure_scale + "\n" + "```" }} two ASCII files are created, one with the 800st patterns (`_problem2Classes_app_.dat`), the other with the 200 last patterns (`_problem2Classes_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. ## Macro {{uranie}} {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + macro[language] + "\n" + "```" }} The main {{tds}} loads the main ASCII data file `problem2Classes_001000.dat` {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc1[language] + "\n" + "```" }} The database is split with the internal iterator attribute in two parts by exporting the 800st patterns in a file and the remaining 200 in another one {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc2[language] + "\n" + "```" }} A second {{tds}} loads `_problem2Classes_app_.dat` and builds the surrogate model over all the variables with 3 hidden layers, a **Hyperbolic Tangent (TanH)** activation function (normalization) in the 3 hidden layers and set the function tolerance to 1e-.6. The **"@"** character behind the output name defines a **classification** problem. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc3[language] + "\n" + "```" }} The model is exported in an external file in C++ language `"uranie_ann_problem2Classes.C"` where the function name is `ANNproblem2Classes` {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc4[language] + "\n" + "```" }} The model is loaded from the macro `uranie_ann_problem2Classes.C` and applied on the second database with the function `ANNproblem2Classes`. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc5[language] + "\n" + "```" }} We draw on a 3D graph, the learning database (in green) and the estimations by the Artificial Neural Network with red points. {{ "```{literalinclude} " + parent_dir + "/roottest/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks." + extension + "\n" + ":language: " + language + "\n" + ":lines: " + bloc6[language] + "\n" + "```" }} ## Graph {{ "```{figure} " + parent_dir + "/roottest/build/uranie/doc/modeler/use_cases/" + language + "/classification_neural_network/modelerClassificationNeuralNetworks.png\n" + ":align: center\n" + ":name: use_cases_modelerClassificationNeuralNetworks\n" + figure_scale + "\n" + "\n" + "Graph of the macro **\"modelerClassificationNeuralNetworks." + extension + "\"**" + "\n" + "```" }} ## Console {{ "```{literalinclude} " + parent_dir + "/roottest/build/uranie/doc/modeler/use_cases/" + language + "/modelerClassificationNeuralNetworks_clean.log\n" + ":language: none\n" + ":lines: " + console[language] + "\n" + "```" }}