mirror of
https://github.com/BlackLight/neuralpp.git
synced 2024-12-29 12:45:12 +01:00
67 lines
4.5 KiB
HTML
67 lines
4.5 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/adderFromString.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 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/adderFromString.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 <iostream></span>
|
|
<span class="preprocessor">#include <<a class="code" href="neural_09_09_8hpp.html">neural++.hpp</a>></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&#39;s class.">NeuralNet</a> net(2, 2, 1, 0.002, 1000);
|
|
<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"</span>);
|
|
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"6,3;9"</span>);
|
|
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"2,3;5"</span>);
|
|
xml += NeuralNet::XMLFromSet(<span class="keywordtype">id</span>, <span class="stringliteral">"4,4;8"</span>);
|
|
NeuralNet::closeXML(xml);
|
|
cout << xml << 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<double> v;
|
|
cout << <span class="stringliteral">"Network status: trained\n\n"</span>;
|
|
|
|
cout << <span class="stringliteral">"First number to add: "</span>;
|
|
cin >> tmp;
|
|
v.push_back(tmp);
|
|
|
|
cout << <span class="stringliteral">"Second number to add: "</span>;
|
|
cin >> 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 << <span class="stringliteral">"Output: "</span> << net.<a name="a4"></a><a class="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;
|
|
<span class="keywordflow">return</span> 0;
|
|
}
|
|
|
|
</pre></div> </div>
|
|
<hr size="1"><address style="text-align: right;"><small>Generated on Fri Sep 4 11:25:49 2009 for Neural++ by
|
|
<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>
|