<h1>examples/doAdd.cpp</h1>Show how to use a network already trained and saved to a binary file. In this case, a network trained to simply perform sums between two real numbers, that should have already been created using learnAdd.<p>
<spanclass="comment">// Load the pre-trained network from "adder.net" file</span>
<spanclass="keywordflow">try</span> {
net = <aclass="code"href="classneuralpp_1_1NeuralNet.html"title="Main project&#39;s class.">NeuralNet</a>(NETFILE);
}
<spanclass="keywordflow">catch</span> (<aname="_a1"></a><aclass="code"href="classneuralpp_1_1NetworkFileNotFoundException.html"title="Exception thrown when doing an attempt to load a network from an invalid file.">NetworkFileNotFoundException</a> e) {
cerr <<<spanclass="stringliteral">"Fatal error while opening "</span><< NETFILE <<<spanclass="stringliteral">": "</span><< e.<aname="a2"></a><aclass="code"href="classneuralpp_1_1NetworkFileNotFoundException.html#24cde7729ab22d343f36e638cfc40702">what</a>();
<spanclass="keywordflow">return</span> 1;
}
cout <<<spanclass="stringliteral">"First number to add: "</span>;
cin >> a;
cout <<<spanclass="stringliteral">"Second number to add: "</span>;
cin >> b;
vector<double> v;
v.push_back(a);
v.push_back(b);
<spanclass="comment">// Set the numbers just read as input values, propagate those values, and get</span>
<spanclass="comment">// the output</span>
net.<aname="a3"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#405b32d2928344314ecf0469070b0f17"title="It sets the input for the network.">setInput</a>(v);
net.<aname="a4"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#c129c180647362da963758bfd1ba6890"title="It propagates values through the network.">propagate</a>();
cout <<<spanclass="stringliteral">"Neural net output: "</span><< net.<aname="a5"></a><aclass="code"href="classneuralpp_1_1NeuralNet.html#961dce8913264bf64c899dce4e25f810"title="It gets the output of the network (note: the layer output should contain an only...">getOutput</a>() << endl;