2020-06-28 23:07:29 +08:00
<!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" >
< head >
< meta http-equiv = "Content-Type" content = "text/xhtml;charset=UTF-8" / >
< meta http-equiv = "X-UA-Compatible" content = "IE=9" / >
2020-09-03 20:54:15 +08:00
< meta name = "generator" content = "Doxygen 1.8.20" / >
2020-06-28 23:07:29 +08:00
< 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 style = "height: 56px;" >
< td id = "projectalign" style = "padding-left: 0.5em;" >
< div id = "projectname" > Algorithms_in_C
  < span id = "projectnumber" > 1.0.0< / span >
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2020-09-03 20:54:15 +08:00
<!-- Generated by Doxygen 1.8.20 -->
2020-06-28 23:07:29 +08:00
< script type = "text/javascript" >
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @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:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
$(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:cf05388f2679ee054f2beb29a391d25f4e673ac3& dn=gpl-2.0.txt GPL-v2 */
$(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" >
< iframe src = "javascript:void(0)" frameborder = "0"
name="MSearchResults" id="MSearchResults">
< / iframe >
< / div >
< div class = "header" >
< div class = "summary" >
< a href = "#nested-classes" > Data Structures< / a > |
< a href = "#define-members" > Macros< / a > |
< 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" > Adaptive Linear Neuron (ADALINE)< / a > implementation
< a href = "#details" > More...< / a > < / p >
< div class = "textblock" > < code > #include < assert.h> < / code > < br / >
< code > #include < limits.h> < / code > < br / >
< code > #include < math.h> < / code > < br / >
< code > #include < stdbool.h> < / code > < br / >
< code > #include < stdio.h> < / code > < br / >
< code > #include < stdlib.h> < / code > < br / >
< code > #include < time.h> < / 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 = "127" > < 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 name = "nested-classes" > < / a >
Data Structures< / h2 > < / td > < / tr >
< tr class = "memitem:" > < td class = "memItemLeft" align = "right" valign = "top" > struct   < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../d2/daa/structadaline.html" > adaline< / a > < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > structure to hold adaline model parameters < a href = "../../d2/daa/structadaline.html#details" > More...< / a > < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "define-members" > < / a >
Macros< / h2 > < / td > < / tr >
2020-07-04 02:15:35 +08:00
< tr class = "memitem:ga555ba960994e9bccb2029764588f694f" > < td class = "memItemLeft" align = "right" valign = "top" >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../da/d2a/group__adaline.html#ga555ba960994e9bccb2029764588f694f" > MAX_ADALINE_ITER< / a >       500< / td > < / tr >
< tr class = "memdesc:ga555ba960994e9bccb2029764588f694f" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Maximum number of iterations to learn. < br / > < / td > < / tr >
< tr class = "separator:ga555ba960994e9bccb2029764588f694f" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:gab4d49d73dec94c092b7ffadba55fb020" > < td class = "memItemLeft" align = "right" valign = "top" >
#define  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../da/d2a/group__adaline.html#gab4d49d73dec94c092b7ffadba55fb020" > ADALINE_ACCURACY< / a >       1e-5< / td > < / tr >
< tr class = "memdesc:gab4d49d73dec94c092b7ffadba55fb020" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > convergence accuracy \(=1\times10^{-5}\) < br / > < / td > < / tr >
< tr class = "separator:gab4d49d73dec94c092b7ffadba55fb020" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-28 23:07:29 +08:00
< / table > < table class = "memberdecls" >
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a name = "func-members" > < / a >
Functions< / h2 > < / td > < / tr >
2020-07-04 02:15:35 +08:00
< tr class = "memitem:gacd88962c5f6341e43cbc69b4a7d3485b" > < td class = "memItemLeft" align = "right" valign = "top" > struct < a class = "el" href = "../../d2/daa/structadaline.html" > adaline< / a >   < / 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" >   < / 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" >   < / td > < / tr >
< tr class = "memitem:ga6f35caa3084772cc126ac7b20f67f665" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / 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" >   < / 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" >   < / td > < / tr >
< tr class = "memitem:ga43576566b020c4157d4fb28f0dd45cfa" > < td class = "memItemLeft" align = "right" valign = "top" > int  < / 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" >   < / td > < td class = "mdescRight" > < a href = "https://en.wikipedia.org/wiki/Heaviside_step_function" > 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" >   < / td > < / tr >
< tr class = "memitem:ga251695a79baa885cafdcf6d8ed4ac120" > < td class = "memItemLeft" align = "right" valign = "top" > char *  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (const struct < a class = "el" href = "../../d2/daa/structadaline.html" > adaline< / a > *ada)< / td > < / tr >
< tr class = "memdesc:ga251695a79baa885cafdcf6d8ed4ac120" > < td class = "mdescLeft" >   < / td > < td class = "mdescRight" > Operator to print the weights of the model. < a href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ga251695a79baa885cafdcf6d8ed4ac120" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:gac70b578aee679005fd336073969c3d94" > < td class = "memItemLeft" align = "right" valign = "top" > int  < / 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" >   < / 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" >   < / td > < / tr >
< tr class = "memitem:ga20d3642e0a87f36fdb7bf91b023cd166" > < td class = "memItemLeft" align = "right" valign = "top" > double  < / 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" >   < / 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" >   < / td > < / tr >
2020-07-17 04:36:47 +08:00
< tr class = "memitem:gaa52120912e32d2893fe1c6d78da5befd" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / 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 >
2020-07-04 02:15:35 +08:00
< tr class = "memdesc:gaa52120912e32d2893fe1c6d78da5befd" > < td class = "mdescLeft" >   < / 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" >   < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "memitem:ab4ecb3accf5d9e0263087e7265bbe3a9" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../dd/d8c/adaline__learning_8c.html#ab4ecb3accf5d9e0263087e7265bbe3a9" > test1< / a > (double eta)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:ab4ecb3accf5d9e0263087e7265bbe3a9" > < td class = "mdescLeft" >   < / 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:ab4ecb3accf5d9e0263087e7265bbe3a9" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a05cc9a0acb524fde727a4d7b4a747ee6" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../dd/d8c/adaline__learning_8c.html#a05cc9a0acb524fde727a4d7b4a747ee6" > test2< / a > (double eta)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a05cc9a0acb524fde727a4d7b4a747ee6" > < td class = "mdescLeft" >   < / 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a05cc9a0acb524fde727a4d7b4a747ee6" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:a3f37b9f073f7e57fd0b39d70718af1b1" > < td class = "memItemLeft" align = "right" valign = "top" > void  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../dd/d8c/adaline__learning_8c.html#a3f37b9f073f7e57fd0b39d70718af1b1" > test3< / a > (double eta)< / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memdesc:a3f37b9f073f7e57fd0b39d70718af1b1" > < td class = "mdescLeft" >   < / 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 >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a3f37b9f073f7e57fd0b39d70718af1b1" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2020-06-29 04:40:24 +08:00
< tr class = "memitem:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "a3c04138a5bfe5d72780bb7e82a18e627" > < / a >
int  < / 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" >   < / td > < td class = "mdescRight" > Main function. < br / > < / td > < / tr >
2020-06-28 23:07:29 +08:00
< tr class = "separator:a3c04138a5bfe5d72780bb7e82a18e627" > < td class = "memSeparator" colspan = "2" >   < / 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" > 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" > 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 >
2020-07-04 02:15:35 +08:00
< 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" > Krishna Vedala< / a > < / dd > < / dl >
2020-06-28 23:07:29 +08:00
< / div > < h2 class = "groupheader" > Function Documentation< / h2 >
< a id = "ab4ecb3accf5d9e0263087e7265bbe3a9" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ab4ecb3accf5d9e0263087e7265bbe3a9" > ◆ < / 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  < / td >
< td class = "paramname" > < em > eta< / em > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< 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 >
2020-07-04 02:15:35 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00226" > < / a > < span class = "lineno" > 226< / span >   {< / div >
< div class = "line" > < a name = "l00227" > < / a > < span class = "lineno" > 227< / span >   < span class = "keyword" > struct < / span > < a class = "code" href = "../../d2/daa/structadaline.html" > adaline< / a > ada = < a class = "code" href = "../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b" > new_adaline< / a > (2, < a class = "code" href = "../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2" > eta< / a > ); < span class = "comment" > // 2 features< / span > < / div >
2020-06-29 04:40:24 +08:00
< div class = "line" > < a name = "l00228" > < / a > < span class = "lineno" > 228< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00229" > < / a > < 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 >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00230" > < / a > < 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" > < a name = "l00231" > < / a > < span class = "lineno" > 231< / span >   {4, 1}, {6, -5}, {-7, -3}, {-8, 5},< / div >
< div class = "line" > < a name = "l00232" > < / a > < span class = "lineno" > 232< / span >   {-9, 2}, {-10, -15}};< / div >
< div class = "line" > < a name = "l00233" > < / a > < span class = "lineno" > 233< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00234" > < / a > < span class = "lineno" > 234< / span >   < span class = "keywordtype" > double< / span > **X = (< span class = "keywordtype" > double< / span > **)malloc(N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *));< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00235" > < / a > < 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" > < a name = "l00236" > < / a > < span class = "lineno" > 236< / span >   -1, 1, 1, 1, -1}; < span class = "comment" > // corresponding y-values< / span > < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00237" > < / a > < span class = "lineno" > 237< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++)< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00238" > < / a > < span class = "lineno" > 238< / span >   {< / div >
< div class = "line" > < a name = "l00239" > < / a > < span class = "lineno" > 239< / span >   X[i] = (< span class = "keywordtype" > double< / span > *)saved_X[i];< / div >
< div class = "line" > < a name = "l00240" > < / a > < span class = "lineno" > 240< / span >   }< / div >
< div class = "line" > < a name = "l00241" > < / a > < span class = "lineno" > 241< / span >   < / div >
< div class = "line" > < a name = "l00242" > < / a > < span class = "lineno" > 242< / span >   printf(< span class = "stringliteral" > " ------- Test 1 -------\n" < / span > );< / div >
< div class = "line" > < a name = "l00243" > < / a > < span class = "lineno" > 243< / span >   printf(< span class = "stringliteral" > " Model before fit: %s" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
< div class = "line" > < a name = "l00244" > < / a > < span class = "lineno" > 244< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00245" > < / a > < span class = "lineno" > 245< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd" > adaline_fit< / a > (& ada, X, Y, N);< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00246" > < / a > < span class = "lineno" > 246< / span >   printf(< span class = "stringliteral" > " Model after fit: %s\n" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
< div class = "line" > < a name = "l00247" > < / a > < span class = "lineno" > 247< / span >   < / div >
< div class = "line" > < a name = "l00248" > < / a > < span class = "lineno" > 248< / span >   < span class = "keywordtype" > double< / span > test_x[] = {5, -3};< / div >
< div class = "line" > < a name = "l00249" > < / a > < span class = "lineno" > 249< / span >   < span class = "keywordtype" > int< / span > pred = < a class = "code" href = "../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94" > adaline_predict< / a > (& ada, test_x, NULL);< / div >
< div class = "line" > < a name = "l00250" > < / a > < span class = "lineno" > 250< / span >   printf(< span class = "stringliteral" > " Predict for x=(5,-3): % d" < / span > , pred);< / div >
< div class = "line" > < a name = "l00251" > < / a > < span class = "lineno" > 251< / span >   assert(pred == -1);< / div >
< div class = "line" > < a name = "l00252" > < / a > < span class = "lineno" > 252< / span >   printf(< span class = "stringliteral" > " ...passed\n" < / span > );< / div >
< div class = "line" > < a name = "l00253" > < / a > < span class = "lineno" > 253< / span >   < / div >
< div class = "line" > < a name = "l00254" > < / a > < span class = "lineno" > 254< / span >   < span class = "keywordtype" > double< / span > test_x2[] = {5, 8};< / div >
< div class = "line" > < a name = "l00255" > < / a > < span class = "lineno" > 255< / span >   pred = < a class = "code" href = "../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94" > adaline_predict< / a > (& ada, test_x2, NULL);< / div >
< div class = "line" > < a name = "l00256" > < / a > < span class = "lineno" > 256< / span >   printf(< span class = "stringliteral" > " Predict for x=(5, 8): % d" < / span > , pred);< / div >
< div class = "line" > < a name = "l00257" > < / a > < span class = "lineno" > 257< / span >   assert(pred == 1);< / div >
< div class = "line" > < a name = "l00258" > < / a > < span class = "lineno" > 258< / span >   printf(< span class = "stringliteral" > " ...passed\n" < / span > );< / div >
< div class = "line" > < a name = "l00259" > < / a > < span class = "lineno" > 259< / span >   < / div >
< div class = "line" > < a name = "l00260" > < / a > < span class = "lineno" > 260< / span >   < span class = "comment" > // for (int i = 0; i < N; i++)< / span > < / div >
< div class = "line" > < a name = "l00261" > < / a > < span class = "lineno" > 261< / span >   < span class = "comment" > // free(X[i]);< / span > < / div >
< div class = "line" > < a name = "l00262" > < / a > < span class = "lineno" > 262< / span >   free(X);< / div >
< div class = "line" > < a name = "l00263" > < / a > < span class = "lineno" > 263< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665" > delete_adaline< / a > (& ada);< / div >
< div class = "line" > < a name = "l00264" > < / a > < span class = "lineno" > 264< / span >   }< / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2020-07-04 02:15:35 +08:00
< div class = "center" > < div class = "zoom" > < iframe scrolling = "no" frameborder = "0" src = "../../dd/d8c/adaline__learning_8c_ab4ecb3accf5d9e0263087e7265bbe3a9_cgraph.svg" width = "100%" height = "480" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe > < / div >
2020-06-28 23:07:29 +08:00
< / div >
< / div >
< / div >
< / div >
< a id = "a05cc9a0acb524fde727a4d7b4a747ee6" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a05cc9a0acb524fde727a4d7b4a747ee6" > ◆ < / 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  < / td >
< td class = "paramname" > < em > eta< / em > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< 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 >
2020-07-04 02:15:35 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00274" > < / a > < span class = "lineno" > 274< / span >   {< / div >
< div class = "line" > < a name = "l00275" > < / a > < span class = "lineno" > 275< / span >   < span class = "keyword" > struct < / span > < a class = "code" href = "../../d2/daa/structadaline.html" > adaline< / a > ada = < a class = "code" href = "../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b" > new_adaline< / a > (2, < a class = "code" href = "../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2" > eta< / a > ); < span class = "comment" > // 2 features< / span > < / div >
2020-06-29 04:40:24 +08:00
< div class = "line" > < a name = "l00276" > < / a > < span class = "lineno" > 276< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00277" > < / a > < 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 >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00278" > < / a > < span class = "lineno" > 278< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00279" > < / a > < span class = "lineno" > 279< / span >   < span class = "keywordtype" > double< / span > **X = (< span class = "keywordtype" > double< / span > **)malloc(N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *));< / div >
< div class = "line" > < a name = "l00280" > < / a > < span class = "lineno" > 280< / span >   < span class = "keywordtype" > int< / span > *Y = (< span class = "keywordtype" > int< / span > *)malloc(N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > int< / span > )); < span class = "comment" > // corresponding y-values< / span > < / div >
< div class = "line" > < a name = "l00281" > < / a > < span class = "lineno" > 281< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++) X[i] = (< span class = "keywordtype" > double< / span > *)malloc(2 * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ));< / div >
2020-06-29 04:40:24 +08:00
< div class = "line" > < a name = "l00282" > < / a > < span class = "lineno" > 282< / span >   < / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00283" > < / a > < span class = "lineno" > 283< / span >   < span class = "comment" > // generate sample points in the interval< / span > < / div >
< div class = "line" > < a name = "l00284" > < / a > < span class = "lineno" > 284< / span >   < span class = "comment" > // [-range2/100 , (range2-1)/100]< / span > < / div >
< div class = "line" > < a name = "l00285" > < / a > < span class = "lineno" > 285< / span >   < span class = "keywordtype" > int< / span > < a class = "code" href = "../../df/dea/structdata.html" > range< / a > = 500; < span class = "comment" > // sample points full-range< / span > < / div >
< div class = "line" > < a name = "l00286" > < / a > < span class = "lineno" > 286< / span >   < span class = "keywordtype" > int< / span > range2 = < a class = "code" href = "../../df/dea/structdata.html" > range< / a > > > 1; < span class = "comment" > // sample points half-range< / span > < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00287" > < / a > < span class = "lineno" > 287< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++)< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00288" > < / a > < span class = "lineno" > 288< / span >   {< / div >
< div class = "line" > < a name = "l00289" > < / a > < span class = "lineno" > 289< / span >   < span class = "keywordtype" > double< / span > x0 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00290" > < / a > < span class = "lineno" > 290< / span >   < span class = "keywordtype" > double< / span > x1 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00291" > < / a > < span class = "lineno" > 291< / span >   X[i][0] = x0;< / div >
< div class = "line" > < a name = "l00292" > < / a > < span class = "lineno" > 292< / span >   X[i][1] = x1;< / div >
< div class = "line" > < a name = "l00293" > < / a > < span class = "lineno" > 293< / span >   Y[i] = (x0 + 3. * x1) > -1 ? 1 : -1;< / div >
< div class = "line" > < a name = "l00294" > < / a > < span class = "lineno" > 294< / span >   }< / div >
< div class = "line" > < a name = "l00295" > < / a > < span class = "lineno" > 295< / span >   < / div >
< div class = "line" > < a name = "l00296" > < / a > < span class = "lineno" > 296< / span >   printf(< span class = "stringliteral" > " ------- Test 2 -------\n" < / span > );< / div >
< div class = "line" > < a name = "l00297" > < / a > < span class = "lineno" > 297< / span >   printf(< span class = "stringliteral" > " Model before fit: %s" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
< div class = "line" > < a name = "l00298" > < / a > < span class = "lineno" > 298< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00299" > < / a > < span class = "lineno" > 299< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd" > adaline_fit< / a > (& ada, X, Y, N);< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00300" > < / a > < span class = "lineno" > 300< / span >   printf(< span class = "stringliteral" > " Model after fit: %s\n" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
< div class = "line" > < a name = "l00301" > < / a > < span class = "lineno" > 301< / span >   < / div >
< div class = "line" > < a name = "l00302" > < / a > < span class = "lineno" > 302< / span >   < span class = "keywordtype" > int< / span > N_test_cases = 5;< / div >
< div class = "line" > < a name = "l00303" > < / a > < span class = "lineno" > 303< / span >   < span class = "keywordtype" > double< / span > test_x[2];< / div >
< div class = "line" > < a name = "l00304" > < / a > < span class = "lineno" > 304< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N_test_cases; i++)< / div >
< div class = "line" > < a name = "l00305" > < / a > < span class = "lineno" > 305< / span >   {< / div >
< div class = "line" > < a name = "l00306" > < / a > < span class = "lineno" > 306< / span >   < span class = "keywordtype" > double< / span > x0 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00307" > < / a > < span class = "lineno" > 307< / span >   < span class = "keywordtype" > double< / span > x1 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00308" > < / a > < span class = "lineno" > 308< / span >   < / div >
< div class = "line" > < a name = "l00309" > < / a > < span class = "lineno" > 309< / span >   test_x[0] = x0;< / div >
< div class = "line" > < a name = "l00310" > < / a > < span class = "lineno" > 310< / span >   test_x[1] = x1;< / div >
< div class = "line" > < a name = "l00311" > < / a > < span class = "lineno" > 311< / span >   < span class = "keywordtype" > int< / span > pred = < a class = "code" href = "../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94" > adaline_predict< / a > (& ada, test_x, NULL);< / div >
< div class = "line" > < a name = "l00312" > < / a > < span class = "lineno" > 312< / span >   printf(< span class = "stringliteral" > " Predict for x=(% 3.2f,% 3.2f): % d" < / span > , x0, x1, pred);< / div >
< div class = "line" > < a name = "l00313" > < / a > < span class = "lineno" > 313< / span >   < / div >
< div class = "line" > < a name = "l00314" > < / a > < span class = "lineno" > 314< / span >   < span class = "keywordtype" > int< / span > expected_val = (x0 + 3. * x1) > -1 ? 1 : -1;< / div >
< div class = "line" > < a name = "l00315" > < / a > < span class = "lineno" > 315< / span >   assert(pred == expected_val);< / div >
< div class = "line" > < a name = "l00316" > < / a > < span class = "lineno" > 316< / span >   printf(< span class = "stringliteral" > " ...passed\n" < / span > );< / div >
< div class = "line" > < a name = "l00317" > < / a > < span class = "lineno" > 317< / span >   }< / div >
< div class = "line" > < a name = "l00318" > < / a > < span class = "lineno" > 318< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00319" > < / a > < span class = "lineno" > 319< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++) free(X[i]);< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00320" > < / a > < span class = "lineno" > 320< / span >   free(X);< / div >
< div class = "line" > < a name = "l00321" > < / a > < span class = "lineno" > 321< / span >   free(Y);< / div >
< div class = "line" > < a name = "l00322" > < / a > < span class = "lineno" > 322< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665" > delete_adaline< / a > (& ada);< / div >
< div class = "line" > < a name = "l00323" > < / a > < span class = "lineno" > 323< / span >   }< / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2020-07-04 02:15:35 +08:00
< div class = "center" > < div class = "zoom" > < iframe scrolling = "no" frameborder = "0" src = "../../dd/d8c/adaline__learning_8c_a05cc9a0acb524fde727a4d7b4a747ee6_cgraph.svg" width = "100%" height = "480" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe > < / div >
2020-06-28 23:07:29 +08:00
< / div >
< / div >
< / div >
< / div >
< a id = "a3f37b9f073f7e57fd0b39d70718af1b1" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a3f37b9f073f7e57fd0b39d70718af1b1" > ◆ < / 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  < / td >
< td class = "paramname" > < em > eta< / em > < / td > < td > )< / td >
< td > < / td >
< / tr >
< / table >
< / div > < div class = "memdoc" >
2020-06-29 04:40:24 +08:00
< 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< 1\), point lies within the sphere else, outside.< / p >
2020-06-28 23:07:29 +08:00
< 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 >
2020-07-04 02:15:35 +08:00
< div class = "fragment" > < div class = "line" > < a name = "l00337" > < / a > < span class = "lineno" > 337< / span >   {< / div >
< div class = "line" > < a name = "l00338" > < / a > < span class = "lineno" > 338< / span >   < span class = "keyword" > struct < / span > < a class = "code" href = "../../d2/daa/structadaline.html" > adaline< / a > ada = < a class = "code" href = "../../da/d2a/group__adaline.html#gacd88962c5f6341e43cbc69b4a7d3485b" > new_adaline< / a > (6, < a class = "code" href = "../../d2/daa/structadaline.html#a85dbd7cce6195d11ebb388220b96bde2" > eta< / a > ); < span class = "comment" > // 2 features< / span > < / div >
< div class = "line" > < a name = "l00339" > < / a > < span class = "lineno" > 339< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00340" > < / a > < 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 >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00341" > < / a > < span class = "lineno" > 341< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00342" > < / a > < span class = "lineno" > 342< / span >   < span class = "keywordtype" > double< / span > **X = (< span class = "keywordtype" > double< / span > **)malloc(N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > *));< / div >
< div class = "line" > < a name = "l00343" > < / a > < span class = "lineno" > 343< / span >   < span class = "keywordtype" > int< / span > *Y = (< span class = "keywordtype" > int< / span > *)malloc(N * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > int< / span > )); < span class = "comment" > // corresponding y-values< / span > < / div >
< div class = "line" > < a name = "l00344" > < / a > < span class = "lineno" > 344< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++) X[i] = (< span class = "keywordtype" > double< / span > *)malloc(6 * < span class = "keyword" > sizeof< / span > (< span class = "keywordtype" > double< / span > ));< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00345" > < / a > < span class = "lineno" > 345< / span >   < / div >
< div class = "line" > < a name = "l00346" > < / a > < span class = "lineno" > 346< / span >   < span class = "comment" > // generate sample points in the interval< / span > < / div >
< div class = "line" > < a name = "l00347" > < / a > < span class = "lineno" > 347< / span >   < span class = "comment" > // [-range2/100 , (range2-1)/100]< / span > < / div >
< div class = "line" > < a name = "l00348" > < / a > < span class = "lineno" > 348< / span >   < span class = "keywordtype" > int< / span > < a class = "code" href = "../../df/dea/structdata.html" > range< / a > = 200; < span class = "comment" > // sample points full-range< / span > < / div >
< div class = "line" > < a name = "l00349" > < / a > < span class = "lineno" > 349< / span >   < span class = "keywordtype" > int< / span > range2 = < a class = "code" href = "../../df/dea/structdata.html" > range< / a > > > 1; < span class = "comment" > // sample points half-range< / span > < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00350" > < / a > < span class = "lineno" > 350< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++)< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00351" > < / a > < span class = "lineno" > 351< / span >   {< / div >
< div class = "line" > < a name = "l00352" > < / a > < span class = "lineno" > 352< / span >   < span class = "keywordtype" > double< / span > x0 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00353" > < / a > < span class = "lineno" > 353< / span >   < span class = "keywordtype" > double< / span > x1 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00354" > < / a > < span class = "lineno" > 354< / span >   < span class = "keywordtype" > double< / span > x2 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00355" > < / a > < span class = "lineno" > 355< / span >   X[i][0] = x0;< / div >
< div class = "line" > < a name = "l00356" > < / a > < span class = "lineno" > 356< / span >   X[i][1] = x1;< / div >
< div class = "line" > < a name = "l00357" > < / a > < span class = "lineno" > 357< / span >   X[i][2] = x2;< / div >
< div class = "line" > < a name = "l00358" > < / a > < span class = "lineno" > 358< / span >   X[i][3] = x0 * x0;< / div >
< div class = "line" > < a name = "l00359" > < / a > < span class = "lineno" > 359< / span >   X[i][4] = x1 * x1;< / div >
< div class = "line" > < a name = "l00360" > < / a > < span class = "lineno" > 360< / span >   X[i][5] = x2 * x2;< / div >
< div class = "line" > < a name = "l00361" > < / a > < span class = "lineno" > 361< / span >   Y[i] = (x0 * x0 + x1 * x1 + x2 * x2) < = 1 ? 1 : -1;< / div >
< div class = "line" > < a name = "l00362" > < / a > < span class = "lineno" > 362< / span >   }< / div >
< div class = "line" > < a name = "l00363" > < / a > < span class = "lineno" > 363< / span >   < / div >
< div class = "line" > < a name = "l00364" > < / a > < span class = "lineno" > 364< / span >   printf(< span class = "stringliteral" > " ------- Test 3 -------\n" < / span > );< / div >
< div class = "line" > < a name = "l00365" > < / a > < span class = "lineno" > 365< / span >   printf(< span class = "stringliteral" > " Model before fit: %s" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
2020-06-29 04:40:24 +08:00
< div class = "line" > < a name = "l00366" > < / a > < span class = "lineno" > 366< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00367" > < / a > < span class = "lineno" > 367< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#gaa52120912e32d2893fe1c6d78da5befd" > adaline_fit< / a > (& ada, X, Y, N);< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00368" > < / a > < span class = "lineno" > 368< / span >   printf(< span class = "stringliteral" > " Model after fit: %s\n" < / span > , < a class = "code" href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > adaline_get_weights_str< / a > (& ada));< / div >
< div class = "line" > < a name = "l00369" > < / a > < span class = "lineno" > 369< / span >   < / div >
< div class = "line" > < a name = "l00370" > < / a > < span class = "lineno" > 370< / span >   < span class = "keywordtype" > int< / span > N_test_cases = 5;< / div >
< div class = "line" > < a name = "l00371" > < / a > < span class = "lineno" > 371< / span >   < span class = "keywordtype" > double< / span > test_x[6];< / div >
< div class = "line" > < a name = "l00372" > < / a > < span class = "lineno" > 372< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N_test_cases; i++)< / div >
< div class = "line" > < a name = "l00373" > < / a > < span class = "lineno" > 373< / span >   {< / div >
< div class = "line" > < a name = "l00374" > < / a > < span class = "lineno" > 374< / span >   < span class = "keywordtype" > double< / span > x0 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00375" > < / a > < span class = "lineno" > 375< / span >   < span class = "keywordtype" > double< / span > x1 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00376" > < / a > < span class = "lineno" > 376< / span >   < span class = "keywordtype" > double< / span > x2 = ((rand() % < a class = "code" href = "../../df/dea/structdata.html" > range< / a > ) - range2) / 100.f;< / div >
< div class = "line" > < a name = "l00377" > < / a > < span class = "lineno" > 377< / span >   test_x[0] = x0;< / div >
< div class = "line" > < a name = "l00378" > < / a > < span class = "lineno" > 378< / span >   test_x[1] = x1;< / div >
< div class = "line" > < a name = "l00379" > < / a > < span class = "lineno" > 379< / span >   test_x[2] = x2;< / div >
< div class = "line" > < a name = "l00380" > < / a > < span class = "lineno" > 380< / span >   test_x[3] = x0 * x0;< / div >
< div class = "line" > < a name = "l00381" > < / a > < span class = "lineno" > 381< / span >   test_x[4] = x1 * x1;< / div >
< div class = "line" > < a name = "l00382" > < / a > < span class = "lineno" > 382< / span >   test_x[5] = x2 * x2;< / div >
< div class = "line" > < a name = "l00383" > < / a > < span class = "lineno" > 383< / span >   < span class = "keywordtype" > int< / span > pred = < a class = "code" href = "../../da/d2a/group__adaline.html#gac70b578aee679005fd336073969c3d94" > adaline_predict< / a > (& ada, test_x, NULL);< / div >
< div class = "line" > < a name = "l00384" > < / a > < span class = "lineno" > 384< / span >   printf(< span class = "stringliteral" > " Predict for x=(% 3.2f,% 3.2f): % d" < / span > , x0, x1, pred);< / div >
< div class = "line" > < a name = "l00385" > < / a > < span class = "lineno" > 385< / span >   < / div >
< div class = "line" > < a name = "l00386" > < / a > < span class = "lineno" > 386< / span >   < span class = "keywordtype" > int< / span > expected_val = (x0 * x0 + x1 * x1 + x2 * x2) < = 1 ? 1 : -1;< / div >
< div class = "line" > < a name = "l00387" > < / a > < span class = "lineno" > 387< / span >   assert(pred == expected_val);< / div >
< div class = "line" > < a name = "l00388" > < / a > < span class = "lineno" > 388< / span >   printf(< span class = "stringliteral" > " ...passed\n" < / span > );< / div >
< div class = "line" > < a name = "l00389" > < / a > < span class = "lineno" > 389< / span >   }< / div >
< div class = "line" > < a name = "l00390" > < / a > < span class = "lineno" > 390< / span >   < / div >
2020-07-17 04:36:47 +08:00
< div class = "line" > < a name = "l00391" > < / a > < span class = "lineno" > 391< / span >   < span class = "keywordflow" > for< / span > (< span class = "keywordtype" > int< / span > i = 0; i < N; i++) free(X[i]);< / div >
2020-07-04 02:15:35 +08:00
< div class = "line" > < a name = "l00392" > < / a > < span class = "lineno" > 392< / span >   free(X);< / div >
< div class = "line" > < a name = "l00393" > < / a > < span class = "lineno" > 393< / span >   free(Y);< / div >
< div class = "line" > < a name = "l00394" > < / a > < span class = "lineno" > 394< / span >   < a class = "code" href = "../../da/d2a/group__adaline.html#ga6f35caa3084772cc126ac7b20f67f665" > delete_adaline< / a > (& ada);< / div >
< div class = "line" > < a name = "l00395" > < / a > < span class = "lineno" > 395< / span >   }< / div >
2020-06-28 23:07:29 +08:00
< / div > <!-- fragment --> < div class = "dynheader" >
Here is the call graph for this function:< / div >
< div class = "dyncontent" >
2020-07-04 02:15:35 +08:00
< div class = "center" > < div class = "zoom" > < iframe scrolling = "no" frameborder = "0" src = "../../dd/d8c/adaline__learning_8c_a3f37b9f073f7e57fd0b39d70718af1b1_cgraph.svg" width = "100%" height = "480" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe > < / div >
2020-06-28 23:07:29 +08:00
< / div >
< / div >
< / div >
< / div >
< / div > <!-- contents -->
< / div > <!-- doc - content -->
2020-07-04 02:15:35 +08:00
< 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 >
2020-06-28 23:07:29 +08:00
< 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 >
2020-07-04 02:15:35 +08:00
< 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 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_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 = "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 = "agroup__adaline_html_ga251695a79baa885cafdcf6d8ed4ac120" > < div class = "ttname" > < a href = "../../da/d2a/group__adaline.html#ga251695a79baa885cafdcf6d8ed4ac120" > 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 = "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 >
2020-06-28 23:07:29 +08:00
<!-- 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 >
2020-09-03 20:54:15 +08:00
< li class = "footer" > Generated by < a href = "http://www.doxygen.org/index.html" > < img class = "footer" src = "../../doxygen.svg" width = "104" height = "31" alt = "doxygen" / > < / a > 1.8.20 < / li >
2020-06-28 23:07:29 +08:00
< / ul >
< / div >
< / body >
< / html >