neuralpp/doc/html/examples_2adderFromScratch_...

67 lines
4.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Neural++: examples/adderFromScratch.cpp</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="examples.html"><span>Examples</span></a></li>
</ul>
</div>
</div>
<div class="contents">
<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>
<div class="fragment"><pre class="fragment">
<span class="preprocessor">#include &lt;iostream&gt;</span>
<span class="preprocessor">#include &lt;<a class="code" href="neural_09_09_8hpp.html">neural++.hpp</a>&gt;</span>
<span class="keyword">using namespace </span>std;
<span class="keyword">using namespace </span>neuralpp;
<span class="keywordtype">int</span> main() {
<a name="_a0"></a><a class="code" href="classneuralpp_1_1NeuralNet.html" title="Main project&amp;#39;s class.">NeuralNet</a> net(2, 2, 2, 0.005, 100);
<span class="keywordtype">string</span> xml;
<span class="keywordtype">double</span> tmp;
<span class="keywordtype">int</span> <span class="keywordtype">id</span> = 0;
<span class="comment">// XML initialization. Then, I say XML that 2+3=5, 3+3=6, 5+4=9</span>
<span class="comment">// Strings' format is "input1,input2,...,inputn;output1,output2,...,outputm</span>
NeuralNet::initXML(xml);
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"3,2;5,1"</span>);
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"4,2;6,2"</span>);
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"6,3;9,3"</span>);
NeuralNet::closeXML(xml);
cout &lt;&lt; xml &lt;&lt; endl;
net.<a name="a1"></a><a class="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);
vector&lt;double&gt; v;
cout &lt;&lt; <span class="stringliteral">"Network status: trained\n\n"</span>;
cout &lt;&lt; <span class="stringliteral">"First number to add: "</span>;
cin &gt;&gt; tmp;
v.push_back(tmp);
cout &lt;&lt; <span class="stringliteral">"Second number to add: "</span>;
cin &gt;&gt; tmp;
v.push_back(tmp);
net.<a name="a2"></a><a class="code" href="classneuralpp_1_1NeuralNet.html#405b32d2928344314ecf0469070b0f17" title="It sets the input for the network.">setInput</a>(v);
net.<a name="a3"></a><a class="code" href="classneuralpp_1_1NeuralNet.html#c129c180647362da963758bfd1ba6890" title="It propagates values through the network.">propagate</a>();
cout &lt;&lt; <span class="stringliteral">"Output: "</span> &lt;&lt; net.<a name="a4"></a><a class="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] &lt;&lt; <span class="stringliteral">"; "</span> &lt;&lt; net.<a class="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] &lt;&lt; endl;
<span class="keywordflow">return</span> 0;
}
</pre></div> </div>
<hr size="1"><address style="text-align: right;"><small>Generated on Sun Aug 16 20:53:42 2009 for Neural++ by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>