mirror of
https://github.com/BlackLight/neuralpp.git
synced 2024-11-16 14:57:14 +01:00
69 lines
4 KiB
HTML
69 lines
4 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/doAdd.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/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>
|
||
|
<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="preprocessor">#define NETFILE "adder.net"</span>
|
||
|
<span class="preprocessor"></span>
|
||
|
<span class="keywordtype">int</span> main() {
|
||
|
<span class="keywordtype">double</span> a,b;
|
||
|
<a name="_a0"></a><a class="code" href="classneuralpp_1_1NeuralNet.html" title="Main project&#39;s class.">NeuralNet</a> net;
|
||
|
|
||
|
<span class="comment">// Load the pre-trained network from "adder.net" file</span>
|
||
|
<span class="keywordflow">try</span> {
|
||
|
net = <a class="code" href="classneuralpp_1_1NeuralNet.html" title="Main project&#39;s class.">NeuralNet</a>(NETFILE);
|
||
|
}
|
||
|
|
||
|
<span class="keywordflow">catch</span> (<a name="_a1"></a><a class="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 << <span class="stringliteral">"Fatal error while opening "</span> << NETFILE << <span class="stringliteral">": "</span> << e.<a name="a2"></a><a class="code" href="classneuralpp_1_1NetworkFileNotFoundException.html#24cde7729ab22d343f36e638cfc40702">what</a>();
|
||
|
<span class="keywordflow">return</span> 1;
|
||
|
}
|
||
|
|
||
|
cout << <span class="stringliteral">"First number to add: "</span>;
|
||
|
cin >> a;
|
||
|
|
||
|
cout << <span class="stringliteral">"Second number to add: "</span>;
|
||
|
cin >> b;
|
||
|
|
||
|
vector<double> v;
|
||
|
v.push_back(a);
|
||
|
v.push_back(b);
|
||
|
|
||
|
<span class="comment">// Set the numbers just read as input values, propagate those values, and get</span>
|
||
|
<span class="comment">// the output</span>
|
||
|
net.<a name="a3"></a><a class="code" href="classneuralpp_1_1NeuralNet.html#405b32d2928344314ecf0469070b0f17" title="It sets the input for the network.">setInput</a>(v);
|
||
|
net.<a name="a4"></a><a class="code" href="classneuralpp_1_1NeuralNet.html#c129c180647362da963758bfd1ba6890" title="It propagates values through the network.">propagate</a>();
|
||
|
cout << <span class="stringliteral">"Neural net output: "</span> << net.<a name="a5"></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 Sun Aug 16 20:53:42 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>
|