<h1>examples/adderFromScratch.cpp</h1>Similar to learnAdd.cpp, but this time the training XML is generated as a string and not saved to a file, and parsed by the program itself to build the network. Then, the program asks two real numbers, and performs both the sum and the difference between them, putting the sum's output on the first output neuron and the difference's on the second output neuron. Anyway, using more than one neuron in the output layer is strongly discouraged, as the network usually won't set correctly the synaptical weights to give satisfying and accurate answers for all of the operations.<p>
<spanclass="comment">// XML initialization. Then, I say XML that 2+3=5, 3+3=6, 5+4=9</span>
<spanclass="comment">// Strings' format is "input1,input2,...,inputn;output1,output2,...,outputm</span>
NeuralNet::initXML(xml);
xml += NeuralNet::XMLFromSet(<spanclass="keywordtype">id</span>, <spanclass="stringliteral">"3,2;5,1"</span>);
xml += NeuralNet::XMLFromSet(<spanclass="keywordtype">id</span>, <spanclass="stringliteral">"4,2;6,2"</span>);
xml += NeuralNet::XMLFromSet(<spanclass="keywordtype">id</span>, <spanclass="stringliteral">"6,3;9,3"</span>);
NeuralNet::closeXML(xml);
cout << xml << endl;
net.<aname="a1"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#1c9e17437d41a7048611e21a3cc1c7dd"title="Train a network using a training set loaded from an XML file.">train</a>(xml, NeuralNet::str);
cout <<<spanclass="stringliteral">"First number to add: "</span>;
cin >> tmp;
v.push_back(tmp);
cout <<<spanclass="stringliteral">"Second number to add: "</span>;
cin >> tmp;
v.push_back(tmp);
net.<aname="a2"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#405b32d2928344314ecf0469070b0f17"title="It sets the input for the network.">setInput</a>(v);
net.<aname="a3"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#c129c180647362da963758bfd1ba6890"title="It propagates values through the network.">propagate</a>();
cout <<<spanclass="stringliteral">"Output: "</span><< net.<aname="a4"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#e6d2215ecc8b560db2f6797db642191c"title="It gets the output of the network in case the output layer contains more neurons...">getOutputs</a>()[0] <<<spanclass="stringliteral">"; "</span><< net.<aclass="code"href="classneuralpp_1_1NeuralNet.html#e6d2215ecc8b560db2f6797db642191c"title="It gets the output of the network in case the output layer contains more neurons...">getOutputs</a>()[1] << endl;