TheAlgorithms-C/dd/d8c/adaline__learning_8c.html
2022-09-08 00:17:03 +00:00

512 lines
52 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<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.5"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C: machine_learning/adaline_learning.c File Reference</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<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>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.5 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('dd/d8c/adaline__learning_8c.html','../../'); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> </div>
<div class="headertitle"><div class="title">adaline_learning.c File Reference</div></div>
</div><!--header-->
<div class="contents">
<p><a href="https://en.wikipedia.org/wiki/ADALINE" target="_blank">Adaptive Linear Neuron (ADALINE)</a> implementation
<a href="#details">More...</a></p>
<div class="textblock"><code>#include &lt;assert.h&gt;</code><br />
<code>#include &lt;limits.h&gt;</code><br />
<code>#include &lt;math.h&gt;</code><br />
<code>#include &lt;stdbool.h&gt;</code><br />
<code>#include &lt;stdio.h&gt;</code><br />
<code>#include &lt;stdlib.h&gt;</code><br />
<code>#include &lt;time.h&gt;</code><br />
</div><div class="textblock"><div class="dynheader">
Include dependency graph for adaline_learning.c:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d9/dcc/adaline__learning_8c__incl.svg" width="611" height="124"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
</div>
</div>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d2/daa/structadaline.html">adaline</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">structure to hold adaline model parameters <a href="../../d2/daa/structadaline.html#details">More...</a><br /></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="define-members" name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:ga555ba960994e9bccb2029764588f694f"><td class="memItemLeft" align="right" valign="top">
#define&#160;</td><td class="memItemRight" valign="bottom"><b>MAX_ADALINE_ITER</b>&#160;&#160;&#160;500</td></tr>
<tr class="memdesc:ga555ba960994e9bccb2029764588f694f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Maximum number of iterations to learn. <br /></td></tr>
<tr class="separator:ga555ba960994e9bccb2029764588f694f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gab4d49d73dec94c092b7ffadba55fb020"><td class="memItemLeft" align="right" valign="top">
#define&#160;</td><td class="memItemRight" valign="bottom"><b>ADALINE_ACCURACY</b>&#160;&#160;&#160;1e-5</td></tr>
<tr class="memdesc:gab4d49d73dec94c092b7ffadba55fb020"><td class="mdescLeft">&#160;</td><td class="mdescRight">convergence accuracy \(=1\times10^{-5}\) <br /></td></tr>
<tr class="separator:gab4d49d73dec94c092b7ffadba55fb020"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="func-members" name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gacd88962c5f6341e43cbc69b4a7d3485b"><td class="memItemLeft" align="right" valign="top">struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">new_adaline</a> (const int num_features, const double eta)</td></tr>
<tr class="memdesc:gacd88962c5f6341e43cbc69b4a7d3485b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Default constructor. <a href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">More...</a><br /></td></tr>
<tr class="separator:gacd88962c5f6341e43cbc69b4a7d3485b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga6f35caa3084772cc126ac7b20f67f665"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">delete_adaline</a> (struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a> *ada)</td></tr>
<tr class="memdesc:ga6f35caa3084772cc126ac7b20f67f665"><td class="mdescLeft">&#160;</td><td class="mdescRight">delete dynamically allocated memory <a href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">More...</a><br /></td></tr>
<tr class="separator:ga6f35caa3084772cc126ac7b20f67f665"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga43576566b020c4157d4fb28f0dd45cfa"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#ga43576566b020c4157d4fb28f0dd45cfa">adaline_activation</a> (double x)</td></tr>
<tr class="memdesc:ga43576566b020c4157d4fb28f0dd45cfa"><td class="mdescLeft">&#160;</td><td class="mdescRight"><a href="https://en.wikipedia.org/wiki/Heaviside_step_function" target="_blank">Heaviside activation function</a> <img src="https://upload.wikimedia.org/wikipedia/commons/d/d9/Dirac_distribution_CDF.svg" alt="" style="pointer-events: none;" width="200px" class="inline"/> <a href="../../da/d2a/group__adaline.html#ga43576566b020c4157d4fb28f0dd45cfa">More...</a><br /></td></tr>
<tr class="separator:ga43576566b020c4157d4fb28f0dd45cfa"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gadb1a7acb555ad62daaf3806bf2fed036"><td class="memItemLeft" align="right" valign="top">char *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a> (const struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a> *ada)</td></tr>
<tr class="memdesc:gadb1a7acb555ad62daaf3806bf2fed036"><td class="mdescLeft">&#160;</td><td class="mdescRight">Operator to print the weights of the model. <a href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">More...</a><br /></td></tr>
<tr class="separator:gadb1a7acb555ad62daaf3806bf2fed036"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gac70b578aee679005fd336073969c3d94"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a> (struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a> *ada, const double *x, double *out)</td></tr>
<tr class="memdesc:gac70b578aee679005fd336073969c3d94"><td class="mdescLeft">&#160;</td><td class="mdescRight">predict the output of the model for given set of features <a href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">More...</a><br /></td></tr>
<tr class="separator:gac70b578aee679005fd336073969c3d94"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga20d3642e0a87f36fdb7bf91b023cd166"><td class="memItemLeft" align="right" valign="top">double&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#ga20d3642e0a87f36fdb7bf91b023cd166">adaline_fit_sample</a> (struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a> *ada, const double *x, const int y)</td></tr>
<tr class="memdesc:ga20d3642e0a87f36fdb7bf91b023cd166"><td class="mdescLeft">&#160;</td><td class="mdescRight">Update the weights of the model using supervised learning for one feature vector. <a href="../../da/d2a/group__adaline.html#ga20d3642e0a87f36fdb7bf91b023cd166">More...</a><br /></td></tr>
<tr class="separator:ga20d3642e0a87f36fdb7bf91b023cd166"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaa52120912e32d2893fe1c6d78da5befd"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">adaline_fit</a> (struct <a class="el" href="../../d2/daa/structadaline.html">adaline</a> *ada, double **X, const int *y, const int N)</td></tr>
<tr class="memdesc:gaa52120912e32d2893fe1c6d78da5befd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Update the weights of the model using supervised learning for an array of vectors. <a href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">More...</a><br /></td></tr>
<tr class="separator:gaa52120912e32d2893fe1c6d78da5befd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab4ecb3accf5d9e0263087e7265bbe3a9"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d8c/adaline__learning_8c.html#ab4ecb3accf5d9e0263087e7265bbe3a9">test1</a> (double eta)</td></tr>
<tr class="memdesc:ab4ecb3accf5d9e0263087e7265bbe3a9"><td class="mdescLeft">&#160;</td><td class="mdescRight">test function to predict points in a 2D coordinate system above the line \(x=y\) as +1 and others as -1. <a href="../../dd/d8c/adaline__learning_8c.html#ab4ecb3accf5d9e0263087e7265bbe3a9">More...</a><br /></td></tr>
<tr class="separator:ab4ecb3accf5d9e0263087e7265bbe3a9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a05cc9a0acb524fde727a4d7b4a747ee6"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d8c/adaline__learning_8c.html#a05cc9a0acb524fde727a4d7b4a747ee6">test2</a> (double eta)</td></tr>
<tr class="memdesc:a05cc9a0acb524fde727a4d7b4a747ee6"><td class="mdescLeft">&#160;</td><td class="mdescRight">test function to predict points in a 2D coordinate system above the line \(x+3y=-1\) as +1 and others as -1. <a href="../../dd/d8c/adaline__learning_8c.html#a05cc9a0acb524fde727a4d7b4a747ee6">More...</a><br /></td></tr>
<tr class="separator:a05cc9a0acb524fde727a4d7b4a747ee6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3f37b9f073f7e57fd0b39d70718af1b1"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d8c/adaline__learning_8c.html#a3f37b9f073f7e57fd0b39d70718af1b1">test3</a> (double eta)</td></tr>
<tr class="memdesc:a3f37b9f073f7e57fd0b39d70718af1b1"><td class="mdescLeft">&#160;</td><td class="mdescRight">test function to predict points in a 3D coordinate system lying within the sphere of radius 1 and centre at origin as +1 and others as -1. <a href="../../dd/d8c/adaline__learning_8c.html#a3f37b9f073f7e57fd0b39d70718af1b1">More...</a><br /></td></tr>
<tr class="separator:a3f37b9f073f7e57fd0b39d70718af1b1"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dd/d8c/adaline__learning_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a> (int argc, char **argv)</td></tr>
<tr class="memdesc:a3c04138a5bfe5d72780bb7e82a18e627"><td class="mdescLeft">&#160;</td><td class="mdescRight">Main function. <a href="../../dd/d8c/adaline__learning_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">More...</a><br /></td></tr>
<tr class="separator:a3c04138a5bfe5d72780bb7e82a18e627"><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 ><a href="https://en.wikipedia.org/wiki/ADALINE" target="_blank">Adaptive Linear Neuron (ADALINE)</a> implementation </p>
<p ><img src="https://upload.wikimedia.org/wikipedia/commons/b/be/Adaline_flow_chart.gif" alt="" width="200px" class="inline"/> <a href="https://commons.wikimedia.org/wiki/File:Adaline_flow_chart.gif" target="_blank">source</a> ADALINE is one of the first and simplest single layer artificial neural network. The algorithm essentially implements a linear function </p><p class="formulaDsp">
\[ f\left(x_0,x_1,x_2,\ldots\right) =
\sum_j x_jw_j+\theta
\]
</p>
<p> where \(x_j\) are the input features of a sample, \(w_j\) are the coefficients of the linear function and \(\theta\) is a constant. If we know the \(w_j\), then for any given set of features, \(y\) can be computed. Computing the \(w_j\) is a supervised learning algorithm wherein a set of features and their corresponding outputs are given and weights are computed using stochastic gradient descent method. </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a3c04138a5bfe5d72780bb7e82a18e627" name="a3c04138a5bfe5d72780bb7e82a18e627"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3c04138a5bfe5d72780bb7e82a18e627">&#9670;&#160;</a></span>main()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">int main </td>
<td>(</td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>argc</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">char **&#160;</td>
<td class="paramname"><em>argv</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<p>Main function. </p>
<div class="fragment"><div class="line"><span class="lineno"> 399</span>{</div>
<div class="line"><span class="lineno"> 400</span> srand(time(NULL)); <span class="comment">// initialize random number generator</span></div>
<div class="line"><span class="lineno"> 401</span> </div>
<div class="line"><span class="lineno"> 402</span> <span class="keywordtype">double</span> eta = 0.1; <span class="comment">// default value of eta</span></div>
<div class="line"><span class="lineno"> 403</span> <span class="keywordflow">if</span> (argc == 2) <span class="comment">// read eta value from commandline argument if present</span></div>
<div class="line"><span class="lineno"> 404</span> eta = strtof(argv[1], NULL);</div>
<div class="line"><span class="lineno"> 405</span> </div>
<div class="line"><span class="lineno"> 406</span> <a class="code hl_function" href="../../d2/df6/kohonen__som__topology_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a>(eta);</div>
<div class="line"><span class="lineno"> 407</span> </div>
<div class="line"><span class="lineno"> 408</span> printf(<span class="stringliteral">&quot;Press ENTER to continue...\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 409</span> getchar();</div>
<div class="line"><span class="lineno"> 410</span> </div>
<div class="line"><span class="lineno"> 411</span> <a class="code hl_function" href="../../d6/d76/k__means__clustering_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a>(eta);</div>
<div class="line"><span class="lineno"> 412</span> </div>
<div class="line"><span class="lineno"> 413</span> printf(<span class="stringliteral">&quot;Press ENTER to continue...\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 414</span> getchar();</div>
<div class="line"><span class="lineno"> 415</span> </div>
<div class="line"><span class="lineno"> 416</span> <a class="code hl_function" href="../../d2/df6/kohonen__som__topology_8c.html#a6d0455dd5c30adda100e95f0423c786e">test3</a>(eta);</div>
<div class="line"><span class="lineno"> 417</span> </div>
<div class="line"><span class="lineno"> 418</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 419</span>}</div>
<div class="ttc" id="ak__means__clustering_8c_html_a0283886819c7c140a023582b7269e2d0"><div class="ttname"><a href="../../d6/d76/k__means__clustering_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a></div><div class="ttdeci">void test2()</div><div class="ttdef"><b>Definition:</b> k_means_clustering.c:356</div></div>
<div class="ttc" id="akohonen__som__topology_8c_html_a1440a7779ac56f47a3f355ce4a8c7da0"><div class="ttname"><a href="../../d2/df6/kohonen__som__topology_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a></div><div class="ttdeci">void test1()</div><div class="ttdoc">Test that creates a random set of points distributed in four clusters in 2D space and trains an SOM t...</div><div class="ttdef"><b>Definition:</b> kohonen_som_topology.c:406</div></div>
<div class="ttc" id="akohonen__som__topology_8c_html_a6d0455dd5c30adda100e95f0423c786e"><div class="ttname"><a href="../../d2/df6/kohonen__som__topology_8c.html#a6d0455dd5c30adda100e95f0423c786e">test3</a></div><div class="ttdeci">void test3()</div><div class="ttdoc">Test that creates a random set of points distributed in eight clusters in 3D space and trains an SOM ...</div><div class="ttdef"><b>Definition:</b> kohonen_som_topology.c:609</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../dd/d8c/adaline__learning_8c_a3c04138a5bfe5d72780bb7e82a18e627_cgraph.svg" width="100%" height="600"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
</div>
<a id="ab4ecb3accf5d9e0263087e7265bbe3a9" name="ab4ecb3accf5d9e0263087e7265bbe3a9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab4ecb3accf5d9e0263087e7265bbe3a9">&#9670;&#160;</a></span>test1()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void test1 </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>eta</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>test function to predict points in a 2D coordinate system above the line \(x=y\) as +1 and others as -1. </p>
<p >Note that each point is defined by 2 values or 2 features. </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">eta</td><td>learning rate (optional, default=0.01) </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><span class="lineno"> 226</span>{</div>
<div class="line"><span class="lineno"> 227</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../d2/daa/structadaline.html">adaline</a> ada = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">new_adaline</a>(2, <a class="code hl_variable" href="../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2">eta</a>); <span class="comment">// 2 features</span></div>
<div class="line"><span class="lineno"> 228</span> </div>
<div class="line"><span class="lineno"> 229</span> <span class="keyword">const</span> <span class="keywordtype">int</span> N = 10; <span class="comment">// number of sample points</span></div>
<div class="line"><span class="lineno"> 230</span> <span class="keyword">const</span> <span class="keywordtype">double</span> saved_X[10][2] = {{0, 1}, {1, -2}, {2, 3}, {3, -1},</div>
<div class="line"><span class="lineno"> 231</span> {4, 1}, {6, -5}, {-7, -3}, {-8, 5},</div>
<div class="line"><span class="lineno"> 232</span> {-9, 2}, {-10, -15}};</div>
<div class="line"><span class="lineno"> 233</span> </div>
<div class="line"><span class="lineno"> 234</span> <span class="keywordtype">double</span> **X = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(N * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
<div class="line"><span class="lineno"> 235</span> <span class="keyword">const</span> <span class="keywordtype">int</span> Y[10] = {1, -1, 1, -1, -1,</div>
<div class="line"><span class="lineno"> 236</span> -1, 1, 1, 1, -1}; <span class="comment">// corresponding y-values</span></div>
<div class="line"><span class="lineno"> 237</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++)</div>
<div class="line"><span class="lineno"> 238</span> {</div>
<div class="line"><span class="lineno"> 239</span> X[i] = (<span class="keywordtype">double</span> *)saved_X[i];</div>
<div class="line"><span class="lineno"> 240</span> }</div>
<div class="line"><span class="lineno"> 241</span> </div>
<div class="line"><span class="lineno"> 242</span> printf(<span class="stringliteral">&quot;------- Test 1 -------\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 243</span> printf(<span class="stringliteral">&quot;Model before fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 244</span> </div>
<div class="line"><span class="lineno"> 245</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">adaline_fit</a>(&amp;ada, X, Y, N);</div>
<div class="line"><span class="lineno"> 246</span> printf(<span class="stringliteral">&quot;Model after fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 247</span> </div>
<div class="line"><span class="lineno"> 248</span> <span class="keywordtype">double</span> test_x[] = {5, -3};</div>
<div class="line"><span class="lineno"> 249</span> <span class="keywordtype">int</span> pred = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a>(&amp;ada, test_x, NULL);</div>
<div class="line"><span class="lineno"> 250</span> printf(<span class="stringliteral">&quot;Predict for x=(5,-3): % d\n&quot;</span>, pred);</div>
<div class="line"><span class="lineno"> 251</span> assert(pred == -1);</div>
<div class="line"><span class="lineno"> 252</span> printf(<span class="stringliteral">&quot; ...passed\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 253</span> </div>
<div class="line"><span class="lineno"> 254</span> <span class="keywordtype">double</span> test_x2[] = {5, 8};</div>
<div class="line"><span class="lineno"> 255</span> pred = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a>(&amp;ada, test_x2, NULL);</div>
<div class="line"><span class="lineno"> 256</span> printf(<span class="stringliteral">&quot;Predict for x=(5, 8): % d\n&quot;</span>, pred);</div>
<div class="line"><span class="lineno"> 257</span> assert(pred == 1);</div>
<div class="line"><span class="lineno"> 258</span> printf(<span class="stringliteral">&quot; ...passed\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 259</span> </div>
<div class="line"><span class="lineno"> 260</span> <span class="comment">// for (int i = 0; i &lt; N; i++)</span></div>
<div class="line"><span class="lineno"> 261</span> <span class="comment">// free(X[i]);</span></div>
<div class="line"><span class="lineno"> 262</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X);</div>
<div class="line"><span class="lineno"> 263</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">delete_adaline</a>(&amp;ada);</div>
<div class="line"><span class="lineno"> 264</span>}</div>
<div class="ttc" id="agroup__adaline_html_ga6f35caa3084772cc126ac7b20f67f665"><div class="ttname"><a href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">delete_adaline</a></div><div class="ttdeci">void delete_adaline(struct adaline *ada)</div><div class="ttdoc">delete dynamically allocated memory</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:89</div></div>
<div class="ttc" id="agroup__adaline_html_gaa52120912e32d2893fe1c6d78da5befd"><div class="ttname"><a href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">adaline_fit</a></div><div class="ttdeci">void adaline_fit(struct adaline *ada, double **X, const int *y, const int N)</div><div class="ttdoc">Update the weights of the model using supervised learning for an array of vectors.</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:184</div></div>
<div class="ttc" id="agroup__adaline_html_gac70b578aee679005fd336073969c3d94"><div class="ttname"><a href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a></div><div class="ttdeci">int adaline_predict(struct adaline *ada, const double *x, double *out)</div><div class="ttdoc">predict the output of the model for given set of features</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:136</div></div>
<div class="ttc" id="agroup__adaline_html_gacd88962c5f6341e43cbc69b4a7d3485b"><div class="ttname"><a href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">new_adaline</a></div><div class="ttdeci">struct adaline new_adaline(const int num_features, const double eta)</div><div class="ttdoc">Default constructor.</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:59</div></div>
<div class="ttc" id="agroup__adaline_html_gadb1a7acb555ad62daaf3806bf2fed036"><div class="ttname"><a href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a></div><div class="ttdeci">char * adaline_get_weights_str(const struct adaline *ada)</div><div class="ttdoc">Operator to print the weights of the model.</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:112</div></div>
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
<div class="ttc" id="astructadaline_html"><div class="ttname"><a href="../../d2/daa/structadaline.html">adaline</a></div><div class="ttdoc">structure to hold adaline model parameters</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:44</div></div>
<div class="ttc" id="astructadaline_html_a85dbd7cce6195d11ebb388220b96bde2"><div class="ttname"><a href="../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2">adaline::eta</a></div><div class="ttdeci">double eta</div><div class="ttdoc">learning rate of the algorithm</div><div class="ttdef"><b>Definition:</b> adaline_learning.c:45</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../dd/d8c/adaline__learning_8c_ab4ecb3accf5d9e0263087e7265bbe3a9_cgraph.svg" width="100%" height="478"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
</div>
<a id="a05cc9a0acb524fde727a4d7b4a747ee6" name="a05cc9a0acb524fde727a4d7b4a747ee6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a05cc9a0acb524fde727a4d7b4a747ee6">&#9670;&#160;</a></span>test2()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void test2 </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>eta</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>test function to predict points in a 2D coordinate system above the line \(x+3y=-1\) as +1 and others as -1. </p>
<p >Note that each point is defined by 2 values or 2 features. The function will create random sample points for training and test purposes. </p><dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">eta</td><td>learning rate (optional, default=0.01) </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><span class="lineno"> 274</span>{</div>
<div class="line"><span class="lineno"> 275</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../d2/daa/structadaline.html">adaline</a> ada = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">new_adaline</a>(2, <a class="code hl_variable" href="../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2">eta</a>); <span class="comment">// 2 features</span></div>
<div class="line"><span class="lineno"> 276</span> </div>
<div class="line"><span class="lineno"> 277</span> <span class="keyword">const</span> <span class="keywordtype">int</span> N = 50; <span class="comment">// number of sample points</span></div>
<div class="line"><span class="lineno"> 278</span> </div>
<div class="line"><span class="lineno"> 279</span> <span class="keywordtype">double</span> **X = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(N * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
<div class="line"><span class="lineno"> 280</span> <span class="keywordtype">int</span> *Y = (<span class="keywordtype">int</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(N * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)); <span class="comment">// corresponding y-values</span></div>
<div class="line"><span class="lineno"> 281</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++) X[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(2 * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
<div class="line"><span class="lineno"> 282</span> </div>
<div class="line"><span class="lineno"> 283</span> <span class="comment">// generate sample points in the interval</span></div>
<div class="line"><span class="lineno"> 284</span> <span class="comment">// [-range2/100 , (range2-1)/100]</span></div>
<div class="line"><span class="lineno"> 285</span> <span class="keywordtype">int</span> <a class="code hl_struct" href="../../df/dea/structdata.html">range</a> = 500; <span class="comment">// sample points full-range</span></div>
<div class="line"><span class="lineno"> 286</span> <span class="keywordtype">int</span> range2 = <a class="code hl_struct" href="../../df/dea/structdata.html">range</a> &gt;&gt; 1; <span class="comment">// sample points half-range</span></div>
<div class="line"><span class="lineno"> 287</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++)</div>
<div class="line"><span class="lineno"> 288</span> {</div>
<div class="line"><span class="lineno"> 289</span> <span class="keywordtype">double</span> x0 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 290</span> <span class="keywordtype">double</span> x1 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 291</span> X[i][0] = x0;</div>
<div class="line"><span class="lineno"> 292</span> X[i][1] = x1;</div>
<div class="line"><span class="lineno"> 293</span> Y[i] = (x0 + 3. * x1) &gt; -1 ? 1 : -1;</div>
<div class="line"><span class="lineno"> 294</span> }</div>
<div class="line"><span class="lineno"> 295</span> </div>
<div class="line"><span class="lineno"> 296</span> printf(<span class="stringliteral">&quot;------- Test 2 -------\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 297</span> printf(<span class="stringliteral">&quot;Model before fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 298</span> </div>
<div class="line"><span class="lineno"> 299</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">adaline_fit</a>(&amp;ada, X, Y, N);</div>
<div class="line"><span class="lineno"> 300</span> printf(<span class="stringliteral">&quot;Model after fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 301</span> </div>
<div class="line"><span class="lineno"> 302</span> <span class="keywordtype">int</span> N_test_cases = 5;</div>
<div class="line"><span class="lineno"> 303</span> <span class="keywordtype">double</span> test_x[2];</div>
<div class="line"><span class="lineno"> 304</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N_test_cases; i++)</div>
<div class="line"><span class="lineno"> 305</span> {</div>
<div class="line"><span class="lineno"> 306</span> <span class="keywordtype">double</span> x0 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 307</span> <span class="keywordtype">double</span> x1 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 308</span> </div>
<div class="line"><span class="lineno"> 309</span> test_x[0] = x0;</div>
<div class="line"><span class="lineno"> 310</span> test_x[1] = x1;</div>
<div class="line"><span class="lineno"> 311</span> <span class="keywordtype">int</span> pred = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a>(&amp;ada, test_x, NULL);</div>
<div class="line"><span class="lineno"> 312</span> printf(<span class="stringliteral">&quot;Predict for x=(% 3.2f,% 3.2f): % d\n&quot;</span>, x0, x1, pred);</div>
<div class="line"><span class="lineno"> 313</span> </div>
<div class="line"><span class="lineno"> 314</span> <span class="keywordtype">int</span> expected_val = (x0 + 3. * x1) &gt; -1 ? 1 : -1;</div>
<div class="line"><span class="lineno"> 315</span> assert(pred == expected_val);</div>
<div class="line"><span class="lineno"> 316</span> printf(<span class="stringliteral">&quot; ...passed\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 317</span> }</div>
<div class="line"><span class="lineno"> 318</span> </div>
<div class="line"><span class="lineno"> 319</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++) <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X[i]);</div>
<div class="line"><span class="lineno"> 320</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X);</div>
<div class="line"><span class="lineno"> 321</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(Y);</div>
<div class="line"><span class="lineno"> 322</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">delete_adaline</a>(&amp;ada);</div>
<div class="line"><span class="lineno"> 323</span>}</div>
<div class="ttc" id="astructdata_html"><div class="ttname"><a href="../../df/dea/structdata.html">data</a></div><div class="ttdef"><b>Definition:</b> prime_factoriziation.c:25</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../dd/d8c/adaline__learning_8c_a05cc9a0acb524fde727a4d7b4a747ee6_cgraph.svg" width="100%" height="478"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
</div>
<a id="a3f37b9f073f7e57fd0b39d70718af1b1" name="a3f37b9f073f7e57fd0b39d70718af1b1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3f37b9f073f7e57fd0b39d70718af1b1">&#9670;&#160;</a></span>test3()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void test3 </td>
<td>(</td>
<td class="paramtype">double&#160;</td>
<td class="paramname"><em>eta</em></td><td>)</td>
<td></td>
</tr>
</table>
</div><div class="memdoc">
<p>test function to predict points in a 3D coordinate system lying within the sphere of radius 1 and centre at origin as +1 and others as -1. </p>
<p >Note that each point is defined by 3 values but we use 6 features. The function will create random sample points for training and test purposes. The sphere centred at origin and radius 1 is defined as: \(x^2+y^2+z^2=r^2=1\) and if the \(r^2&lt;1\), point lies within the sphere else, outside.</p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramdir">[in]</td><td class="paramname">eta</td><td>learning rate (optional, default=0.01) </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><span class="lineno"> 337</span>{</div>
<div class="line"><span class="lineno"> 338</span> <span class="keyword">struct </span><a class="code hl_struct" href="../../d2/daa/structadaline.html">adaline</a> ada = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b">new_adaline</a>(6, <a class="code hl_variable" href="../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2">eta</a>); <span class="comment">// 2 features</span></div>
<div class="line"><span class="lineno"> 339</span> </div>
<div class="line"><span class="lineno"> 340</span> <span class="keyword">const</span> <span class="keywordtype">int</span> N = 50; <span class="comment">// number of sample points</span></div>
<div class="line"><span class="lineno"> 341</span> </div>
<div class="line"><span class="lineno"> 342</span> <span class="keywordtype">double</span> **X = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(N * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
<div class="line"><span class="lineno"> 343</span> <span class="keywordtype">int</span> *Y = (<span class="keywordtype">int</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(N * <span class="keyword">sizeof</span>(<span class="keywordtype">int</span>)); <span class="comment">// corresponding y-values</span></div>
<div class="line"><span class="lineno"> 344</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++) X[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(6 * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
<div class="line"><span class="lineno"> 345</span> </div>
<div class="line"><span class="lineno"> 346</span> <span class="comment">// generate sample points in the interval</span></div>
<div class="line"><span class="lineno"> 347</span> <span class="comment">// [-range2/100 , (range2-1)/100]</span></div>
<div class="line"><span class="lineno"> 348</span> <span class="keywordtype">int</span> <a class="code hl_struct" href="../../df/dea/structdata.html">range</a> = 200; <span class="comment">// sample points full-range</span></div>
<div class="line"><span class="lineno"> 349</span> <span class="keywordtype">int</span> range2 = <a class="code hl_struct" href="../../df/dea/structdata.html">range</a> &gt;&gt; 1; <span class="comment">// sample points half-range</span></div>
<div class="line"><span class="lineno"> 350</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++)</div>
<div class="line"><span class="lineno"> 351</span> {</div>
<div class="line"><span class="lineno"> 352</span> <span class="keywordtype">double</span> x0 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 353</span> <span class="keywordtype">double</span> x1 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 354</span> <span class="keywordtype">double</span> x2 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 355</span> X[i][0] = x0;</div>
<div class="line"><span class="lineno"> 356</span> X[i][1] = x1;</div>
<div class="line"><span class="lineno"> 357</span> X[i][2] = x2;</div>
<div class="line"><span class="lineno"> 358</span> X[i][3] = x0 * x0;</div>
<div class="line"><span class="lineno"> 359</span> X[i][4] = x1 * x1;</div>
<div class="line"><span class="lineno"> 360</span> X[i][5] = x2 * x2;</div>
<div class="line"><span class="lineno"> 361</span> Y[i] = (x0 * x0 + x1 * x1 + x2 * x2) &lt;= 1 ? 1 : -1;</div>
<div class="line"><span class="lineno"> 362</span> }</div>
<div class="line"><span class="lineno"> 363</span> </div>
<div class="line"><span class="lineno"> 364</span> printf(<span class="stringliteral">&quot;------- Test 3 -------\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 365</span> printf(<span class="stringliteral">&quot;Model before fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 366</span> </div>
<div class="line"><span class="lineno"> 367</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd">adaline_fit</a>(&amp;ada, X, Y, N);</div>
<div class="line"><span class="lineno"> 368</span> printf(<span class="stringliteral">&quot;Model after fit: %s\n&quot;</span>, <a class="code hl_function" href="../../da/d2a/group__adaline.html#gadb1a7acb555ad62daaf3806bf2fed036">adaline_get_weights_str</a>(&amp;ada));</div>
<div class="line"><span class="lineno"> 369</span> </div>
<div class="line"><span class="lineno"> 370</span> <span class="keywordtype">int</span> N_test_cases = 5;</div>
<div class="line"><span class="lineno"> 371</span> <span class="keywordtype">double</span> test_x[6];</div>
<div class="line"><span class="lineno"> 372</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N_test_cases; i++)</div>
<div class="line"><span class="lineno"> 373</span> {</div>
<div class="line"><span class="lineno"> 374</span> <span class="keywordtype">double</span> x0 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 375</span> <span class="keywordtype">double</span> x1 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 376</span> <span class="keywordtype">double</span> x2 = ((rand() % <a class="code hl_struct" href="../../df/dea/structdata.html">range</a>) - range2) / 100.f;</div>
<div class="line"><span class="lineno"> 377</span> test_x[0] = x0;</div>
<div class="line"><span class="lineno"> 378</span> test_x[1] = x1;</div>
<div class="line"><span class="lineno"> 379</span> test_x[2] = x2;</div>
<div class="line"><span class="lineno"> 380</span> test_x[3] = x0 * x0;</div>
<div class="line"><span class="lineno"> 381</span> test_x[4] = x1 * x1;</div>
<div class="line"><span class="lineno"> 382</span> test_x[5] = x2 * x2;</div>
<div class="line"><span class="lineno"> 383</span> <span class="keywordtype">int</span> pred = <a class="code hl_function" href="../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94">adaline_predict</a>(&amp;ada, test_x, NULL);</div>
<div class="line"><span class="lineno"> 384</span> printf(<span class="stringliteral">&quot;Predict for x=(% 3.2f,% 3.2f): % d\n&quot;</span>, x0, x1, pred);</div>
<div class="line"><span class="lineno"> 385</span> </div>
<div class="line"><span class="lineno"> 386</span> <span class="keywordtype">int</span> expected_val = (x0 * x0 + x1 * x1 + x2 * x2) &lt;= 1 ? 1 : -1;</div>
<div class="line"><span class="lineno"> 387</span> assert(pred == expected_val);</div>
<div class="line"><span class="lineno"> 388</span> printf(<span class="stringliteral">&quot; ...passed\n&quot;</span>);</div>
<div class="line"><span class="lineno"> 389</span> }</div>
<div class="line"><span class="lineno"> 390</span> </div>
<div class="line"><span class="lineno"> 391</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; N; i++) <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X[i]);</div>
<div class="line"><span class="lineno"> 392</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X);</div>
<div class="line"><span class="lineno"> 393</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(Y);</div>
<div class="line"><span class="lineno"> 394</span> <a class="code hl_function" href="../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665">delete_adaline</a>(&amp;ada);</div>
<div class="line"><span class="lineno"> 395</span>}</div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../dd/d8c/adaline__learning_8c_a3f37b9f073f7e57fd0b39d70718af1b1_cgraph.svg" width="100%" height="478"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<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="../../dd/d8c/adaline__learning_8c.html">adaline_learning.c</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.5 </li>
</ul>
</div>
</body>
</html>