Documentation for 53a6c16730

This commit is contained in:
github-actions
2022-01-16 16:05:19 +00:00
parent 778f1be9e5
commit 2cab28c905
3620 changed files with 52045 additions and 41188 deletions

View File

@@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.2"/>
<meta name="generator" content="Doxygen 1.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: machine_learning/neural_network.cpp File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
@@ -30,8 +30,8 @@ MathJax.Hub.Config({
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
@@ -41,7 +41,7 @@ MathJax.Hub.Config({
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.2 -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
@@ -98,7 +98,7 @@ $(document).ready(function(){initNavTree('d2/d58/neural__network_8cpp.html','../
</div><!--header-->
<div class="contents">
<p>Implementation of <a href="https://en.wikipedia.org/wiki/Multilayer_perceptron" target="_blank">Multilayer Perceptron</a>.
<p>Implementation of [Multilayer Perceptron] (<a href="https://en.wikipedia.org/wiki/Multilayer_perceptron">https://en.wikipedia.org/wiki/Multilayer_perceptron</a>).
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;algorithm&gt;</code><br />
<code>#include &lt;cassert&gt;</code><br />
@@ -168,7 +168,7 @@ Functions</h2></td></tr>
<tr class="separator:ae66f6b31b5ad750f1fe042a706a4e3d4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p >Implementation of <a href="https://en.wikipedia.org/wiki/Multilayer_perceptron" target="_blank">Multilayer Perceptron</a>. </p>
<div class="textblock"><p >Implementation of [Multilayer Perceptron] (<a href="https://en.wikipedia.org/wiki/Multilayer_perceptron">https://en.wikipedia.org/wiki/Multilayer_perceptron</a>). </p>
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/imdeep2905" target="_blank">Deep Raval</a></dd></dl>
<p>A multilayer perceptron (MLP) is a class of feedforward artificial neural network (ANN). The term MLP is used ambiguously, sometimes loosely to any feedforward ANN, sometimes strictly to refer to networks composed of multiple layers of perceptrons (with threshold activation). Multilayer perceptrons are sometimes colloquially referred to as "vanilla" neural networks, especially when they have a single hidden layer.</p>
<p >An MLP consists of at least three layers of nodes: an input layer, a hidden layer and an output layer. Except for the input nodes, each node is a neuron that uses a nonlinear activation function. MLP utilizes a supervised learning technique called backpropagation for training. Its multiple layers and non-linear activation distinguish MLP from a linear perceptron. It can distinguish data that is not linearly separable.</p>
@@ -197,7 +197,7 @@ Functions</h2></td></tr>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>derivative of relu(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00081" name="l00081"></a><span class="lineno"> 81</span>{ <span class="keywordflow">return</span> x &gt;= 0.0 ? 1.0 : 0.0; }</div>
<div class="fragment"><div class="line"><span class="lineno"> 81</span>{ <span class="keywordflow">return</span> x &gt;= 0.0 ? 1.0 : 0.0; }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -229,7 +229,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns derivative of sigmoid(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span>{ <span class="keywordflow">return</span> x * (1 - x); }</div>
<div class="fragment"><div class="line"><span class="lineno"> 67</span>{ <span class="keywordflow">return</span> x * (1 - x); }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -261,7 +261,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns derivative of tanh(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span>{ <span class="keywordflow">return</span> 1 - x * x; }</div>
<div class="fragment"><div class="line"><span class="lineno"> 95</span>{ <span class="keywordflow">return</span> 1 - x * x; }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -293,7 +293,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns x </dd></dl>
<div class="fragment"><div class="line"><a id="l00112" name="l00112"></a><span class="lineno"> 112</span>{ <span class="keywordflow">return</span> x; }</div>
<div class="fragment"><div class="line"><span class="lineno"> 112</span>{ <span class="keywordflow">return</span> x; }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -321,11 +321,11 @@ Here is the call graph for this function:</div>
<p>Main function. </p>
<dl class="section return"><dt>Returns</dt><dd>0 on exit </dd></dl>
<div class="fragment"><div class="line"><a id="l00833" name="l00833"></a><span class="lineno"> 833</span> {</div>
<div class="line"><a id="l00834" name="l00834"></a><span class="lineno"> 834</span> <span class="comment">// Testing</span></div>
<div class="line"><a id="l00835" name="l00835"></a><span class="lineno"> 835</span> <a class="code hl_function" href="../../d2/d58/neural__network_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
<div class="line"><a id="l00836" name="l00836"></a><span class="lineno"> 836</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00837" name="l00837"></a><span class="lineno"> 837</span>}</div>
<div class="fragment"><div class="line"><span class="lineno"> 833</span> {</div>
<div class="line"><span class="lineno"> 834</span> <span class="comment">// Testing</span></div>
<div class="line"><span class="lineno"> 835</span> <a class="code hl_function" href="../../d2/d58/neural__network_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a>();</div>
<div class="line"><span class="lineno"> 836</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 837</span>}</div>
<div class="ttc" id="aneural__network_8cpp_html_aa8dca7b867074164d5f45b0f3851269d"><div class="ttname"><a href="../../d2/d58/neural__network_8cpp.html#aa8dca7b867074164d5f45b0f3851269d">test</a></div><div class="ttdeci">static void test()</div><div class="ttdef"><b>Definition:</b> neural_network.cpp:805</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
@@ -358,7 +358,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>relu(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00074" name="l00074"></a><span class="lineno"> 74</span>{ <span class="keywordflow">return</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a>(0.0, x); }</div>
<div class="fragment"><div class="line"><span class="lineno"> 74</span>{ <span class="keywordflow">return</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a>(0.0, x); }</div>
<div class="ttc" id="amax_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/max.html">std::max</a></div><div class="ttdeci">T max(T... args)</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
@@ -391,7 +391,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns sigmoid(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00060" name="l00060"></a><span class="lineno"> 60</span>{ <span class="keywordflow">return</span> 1.0 / (1.0 + <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/exp.html">std::exp</a>(-x)); }</div>
<div class="fragment"><div class="line"><span class="lineno"> 60</span>{ <span class="keywordflow">return</span> 1.0 / (1.0 + <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/exp.html">std::exp</a>(-x)); }</div>
<div class="ttc" id="aexp_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/numeric/math/exp.html">std::exp</a></div><div class="ttdeci">T exp(T... args)</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
@@ -424,7 +424,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns x * x </dd></dl>
<div class="fragment"><div class="line"><a id="l00106" name="l00106"></a><span class="lineno"> 106</span>{ <span class="keywordflow">return</span> x * x; }</div>
<div class="fragment"><div class="line"><span class="lineno"> 106</span>{ <span class="keywordflow">return</span> x * x; }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -456,7 +456,7 @@ Here is the call graph for this function:</div>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Returns tanh(x) </dd></dl>
<div class="fragment"><div class="line"><a id="l00088" name="l00088"></a><span class="lineno"> 88</span>{ <span class="keywordflow">return</span> 2 / (1 + <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/exp.html">std::exp</a>(-2 * x)) - 1; }</div>
<div class="fragment"><div class="line"><span class="lineno"> 88</span>{ <span class="keywordflow">return</span> 2 / (1 + <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/numeric/math/exp.html">std::exp</a>(-2 * x)) - 1; }</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
@@ -489,29 +489,29 @@ Here is the call graph for this function:</div>
</table>
</div><div class="memdoc">
<p >Function to test neural network </p><dl class="section return"><dt>Returns</dt><dd>none </dd></dl>
<div class="fragment"><div class="line"><a id="l00805" name="l00805"></a><span class="lineno"> 805</span> {</div>
<div class="line"><a id="l00806" name="l00806"></a><span class="lineno"> 806</span> <span class="comment">// Creating network with 3 layers for &quot;iris.csv&quot;</span></div>
<div class="line"><a id="l00807" name="l00807"></a><span class="lineno"> 807</span> <a class="code hl_class" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html">machine_learning::neural_network::NeuralNetwork</a> myNN =</div>
<div class="line"><a id="l00808" name="l00808"></a><span class="lineno"> 808</span> <a class="code hl_class" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html">machine_learning::neural_network::NeuralNetwork</a>({</div>
<div class="line"><a id="l00809" name="l00809"></a><span class="lineno"> 809</span> {4, <span class="stringliteral">&quot;none&quot;</span>}, <span class="comment">// First layer with 3 neurons and &quot;none&quot; as activation</span></div>
<div class="line"><a id="l00810" name="l00810"></a><span class="lineno"> 810</span> {6,</div>
<div class="line"><a id="l00811" name="l00811"></a><span class="lineno"> 811</span> <span class="stringliteral">&quot;relu&quot;</span>}, <span class="comment">// Second layer with 6 neurons and &quot;relu&quot; as activation</span></div>
<div class="line"><a id="l00812" name="l00812"></a><span class="lineno"> 812</span> {3, <span class="stringliteral">&quot;sigmoid&quot;</span>} <span class="comment">// Third layer with 3 neurons and &quot;sigmoid&quot; as</span></div>
<div class="line"><a id="l00813" name="l00813"></a><span class="lineno"> 813</span> <span class="comment">// activation</span></div>
<div class="line"><a id="l00814" name="l00814"></a><span class="lineno"> 814</span> });</div>
<div class="line"><a id="l00815" name="l00815"></a><span class="lineno"> 815</span> <span class="comment">// Printing summary of model</span></div>
<div class="line"><a id="l00816" name="l00816"></a><span class="lineno"> 816</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a61d30113d13304c664057118b92a5931">summary</a>();</div>
<div class="line"><a id="l00817" name="l00817"></a><span class="lineno"> 817</span> <span class="comment">// Training Model</span></div>
<div class="line"><a id="l00818" name="l00818"></a><span class="lineno"> 818</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a5172a6791b9bd24f4232bab8d6b81fff">fit_from_csv</a>(<span class="stringliteral">&quot;iris.csv&quot;</span>, <span class="keyword">true</span>, 100, 0.3, <span class="keyword">false</span>, 2, 32, <span class="keyword">true</span>);</div>
<div class="line"><a id="l00819" name="l00819"></a><span class="lineno"> 819</span> <span class="comment">// Testing predictions of model</span></div>
<div class="line"><a id="l00820" name="l00820"></a><span class="lineno"> 820</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><a id="l00821" name="l00821"></a><span class="lineno"> 821</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{5, 3.4, 1.6, 0.4}})) == 0);</div>
<div class="line"><a id="l00822" name="l00822"></a><span class="lineno"> 822</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><a id="l00823" name="l00823"></a><span class="lineno"> 823</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{6.4, 2.9, 4.3, 1.3}})) == 1);</div>
<div class="line"><a id="l00824" name="l00824"></a><span class="lineno"> 824</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><a id="l00825" name="l00825"></a><span class="lineno"> 825</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{6.2, 3.4, 5.4, 2.3}})) == 2);</div>
<div class="line"><a id="l00826" name="l00826"></a><span class="lineno"> 826</span> <span class="keywordflow">return</span>;</div>
<div class="line"><a id="l00827" name="l00827"></a><span class="lineno"> 827</span>}</div>
<div class="fragment"><div class="line"><span class="lineno"> 805</span> {</div>
<div class="line"><span class="lineno"> 806</span> <span class="comment">// Creating network with 3 layers for &quot;iris.csv&quot;</span></div>
<div class="line"><span class="lineno"> 807</span> <a class="code hl_class" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html">machine_learning::neural_network::NeuralNetwork</a> myNN =</div>
<div class="line"><span class="lineno"> 808</span> <a class="code hl_class" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html">machine_learning::neural_network::NeuralNetwork</a>({</div>
<div class="line"><span class="lineno"> 809</span> {4, <span class="stringliteral">&quot;none&quot;</span>}, <span class="comment">// First layer with 3 neurons and &quot;none&quot; as activation</span></div>
<div class="line"><span class="lineno"> 810</span> {6,</div>
<div class="line"><span class="lineno"> 811</span> <span class="stringliteral">&quot;relu&quot;</span>}, <span class="comment">// Second layer with 6 neurons and &quot;relu&quot; as activation</span></div>
<div class="line"><span class="lineno"> 812</span> {3, <span class="stringliteral">&quot;sigmoid&quot;</span>} <span class="comment">// Third layer with 3 neurons and &quot;sigmoid&quot; as</span></div>
<div class="line"><span class="lineno"> 813</span> <span class="comment">// activation</span></div>
<div class="line"><span class="lineno"> 814</span> });</div>
<div class="line"><span class="lineno"> 815</span> <span class="comment">// Printing summary of model</span></div>
<div class="line"><span class="lineno"> 816</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a61d30113d13304c664057118b92a5931">summary</a>();</div>
<div class="line"><span class="lineno"> 817</span> <span class="comment">// Training Model</span></div>
<div class="line"><span class="lineno"> 818</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a5172a6791b9bd24f4232bab8d6b81fff">fit_from_csv</a>(<span class="stringliteral">&quot;iris.csv&quot;</span>, <span class="keyword">true</span>, 100, 0.3, <span class="keyword">false</span>, 2, 32, <span class="keyword">true</span>);</div>
<div class="line"><span class="lineno"> 819</span> <span class="comment">// Testing predictions of model</span></div>
<div class="line"><span class="lineno"> 820</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><span class="lineno"> 821</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{5, 3.4, 1.6, 0.4}})) == 0);</div>
<div class="line"><span class="lineno"> 822</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><span class="lineno"> 823</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{6.4, 2.9, 4.3, 1.3}})) == 1);</div>
<div class="line"><span class="lineno"> 824</span> assert(<a class="code hl_function" href="../../d8/d77/namespacemachine__learning.html#a50480fccfb39de20ca47f1bf51ecb6ec">machine_learning::argmax</a>(</div>
<div class="line"><span class="lineno"> 825</span> myNN.<a class="code hl_function" href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">single_predict</a>({{6.2, 3.4, 5.4, 2.3}})) == 2);</div>
<div class="line"><span class="lineno"> 826</span> <span class="keywordflow">return</span>;</div>
<div class="line"><span class="lineno"> 827</span>}</div>
<div class="ttc" id="aclassmachine__learning_1_1neural__network_1_1_neural_network_html"><div class="ttname"><a href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html">machine_learning::neural_network::NeuralNetwork</a></div><div class="ttdef"><b>Definition:</b> neural_network.cpp:247</div></div>
<div class="ttc" id="aclassmachine__learning_1_1neural__network_1_1_neural_network_html_a3b9eac1824d365dce715fb17c33cb96f"><div class="ttname"><a href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a3b9eac1824d365dce715fb17c33cb96f">machine_learning::neural_network::NeuralNetwork::single_predict</a></div><div class="ttdeci">std::vector&lt; std::valarray&lt; double &gt; &gt; single_predict(const std::vector&lt; std::valarray&lt; double &gt; &gt; &amp;X)</div><div class="ttdef"><b>Definition:</b> neural_network.cpp:451</div></div>
<div class="ttc" id="aclassmachine__learning_1_1neural__network_1_1_neural_network_html_a5172a6791b9bd24f4232bab8d6b81fff"><div class="ttname"><a href="../../d4/df4/classmachine__learning_1_1neural__network_1_1_neural_network.html#a5172a6791b9bd24f4232bab8d6b81fff">machine_learning::neural_network::NeuralNetwork::fit_from_csv</a></div><div class="ttdeci">void fit_from_csv(const std::string &amp;file_name, const bool &amp;last_label, const int &amp;epochs, const double &amp;learning_rate, const bool &amp;normalize, const int &amp;slip_lines=1, const size_t &amp;batch_size=32, const bool &amp;shuffle=true)</div><div class="ttdef"><b>Definition:</b> neural_network.cpp:587</div></div>
@@ -532,7 +532,7 @@ Here is the call graph for this function:</div>
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_3343723ae086de42ee4ca9774da3a13f.html">machine_learning</a></li><li class="navelem"><a class="el" href="../../d2/d58/neural__network_8cpp.html">neural_network.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.2 </li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3 </li>
</ul>
</div>
</body>