Include dependency graph for kohonen_som_trace.c:</div>
<divclass="dyncontent">
<divclass="center"><iframescrolling="no"frameborder="0"src="../../da/dfd/kohonen__som__trace_8c__incl.svg"width="331"height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<trclass="memitem:af5ce14f026d6d231bef29161bac2b485"><tdclass="memItemLeft"align="right"valign="top">double </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a> (double a, double b)</td></tr>
<trclass="memdesc:af5ce14f026d6d231bef29161bac2b485"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Helper function to generate a random number in a given interval. <ahref="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">More...</a><br/></td></tr>
<trclass="memitem:a7b84b14e60f47812b581d1f93057c85a"><tdclass="memItemLeft"align="right"valign="top">int </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">save_nd_data</a> (const char *fname, double **X, int num_points, int num_features)</td></tr>
<trclass="memdesc:a7b84b14e60f47812b581d1f93057c85a"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Save a given n-dimensional data martix to file. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">More...</a><br/></td></tr>
<trclass="memitem:a0a292ebd954c568934b1fd06666d27e6"><tdclass="memItemLeft"align="right"valign="top">void </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../d0/d46/kohonen__som__trace_8c.html#a0a292ebd954c568934b1fd06666d27e6">get_min_1d</a> (double const *X, int <aclass="el"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>, double *val, int *idx)</td></tr>
<trclass="memdesc:a0a292ebd954c568934b1fd06666d27e6"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Get minimum value and index of the value in a vector. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a0a292ebd954c568934b1fd06666d27e6">More...</a><br/></td></tr>
<trclass="memdesc:a9c98203f55242ff7a8f45a6370840e66"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Update weights of the SOM using Kohonen algorithm. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a9c98203f55242ff7a8f45a6370840e66">More...</a><br/></td></tr>
<trclass="memitem:aeaeffbff2be4d5d15b0d4f10f846abde"><tdclass="memItemLeft"align="right"valign="top">void </td><tdclass="memItemRight"valign="bottom"><aclass="el"href="../../d0/d46/kohonen__som__trace_8c.html#aeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a> (double **X, double *const *W, int num_samples, int num_features, int num_out, double alpha_min)</td></tr>
<trclass="memdesc:aeaeffbff2be4d5d15b0d4f10f846abde"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given datset. <ahref="../../d0/d46/kohonen__som__trace_8c.html#aeaeffbff2be4d5d15b0d4f10f846abde">More...</a><br/></td></tr>
<trclass="memdesc:a107f00650b8041f77767927073ddddb8"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a random set of points distributed <em>near</em> the circumference of a circle and trains an SOM that finds that circular pattern. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">More...</a><br/></td></tr>
<trclass="memdesc:a1440a7779ac56f47a3f355ce4a8c7da0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Test that creates a random set of points distributed <em>near</em> the circumference of a circle and trains an SOM that finds that circular pattern. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">More...</a><br/></td></tr>
<trclass="memdesc:aa2246f940155472084ee461f3685d614"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a random set of points distributed <em>near</em> the locus of the <ahref="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono">Lamniscate of Gerono</a>. <ahref="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">More...</a><br/></td></tr>
<trclass="memdesc:a0283886819c7c140a023582b7269e2d0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Test that creates a random set of points distributed <em>near</em> the locus of the <ahref="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono">Lamniscate of Gerono</a> and trains an SOM that finds that circular pattern. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a0283886819c7c140a023582b7269e2d0">More...</a><br/></td></tr>
<trclass="memdesc:a41ae16442e3e5b891a58d2e5932a2cd0"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Creates a random set of points distributed in four clusters in 3D space with centroids at the points. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">More...</a><br/></td></tr>
<trclass="memdesc:a6d0455dd5c30adda100e95f0423c786e"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Test that creates a random set of points distributed in six clusters in 3D space. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a6d0455dd5c30adda100e95f0423c786e">More...</a><br/></td></tr>
<trclass="memdesc:a2256c10b16edba377b64a44b6c656908"><tdclass="mdescLeft"> </td><tdclass="mdescRight">Convert clock cycle difference to time in seconds. <ahref="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">More...</a><br/></td></tr>
<p>This example implements a powerful self organizing map algorithm. The algorithm creates a connected network of weights that closely follows the given data points. This this creates a chain of nodes that resembles the given input shape. </p><dlclass="section see"><dt>See also</dt><dd><aclass="el"href="../../d2/df6/kohonen__som__topology_8c.html"title="Kohonen self organizing map (topological map)">kohonen_som_topology.c</a></dd></dl>
<divclass="line"><aname="l00102"></a><spanclass="lineno"> 102</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; i++) <spanclass="comment">// check each value</span></div>
<divclass="line"><aname="l00104"></a><spanclass="lineno"> 104</span> <spanclass="keywordflow">if</span> (X[i] < val[0]) <spanclass="comment">// if a lower value is found</span></div>
<divclass="line"><aname="l00105"></a><spanclass="lineno"> 105</span>  { <spanclass="comment">// save the value and its index</span></div>
<divclass="line"><aname="l00183"></a><spanclass="lineno"> 183</span> <spanclass="comment">// Loop for each sample pattern in the data set</span></div>
<divclass="line"><aname="l00187"></a><spanclass="lineno"> 187</span> <spanclass="comment">// update weights for the current input pattern sample</span></div>
<divclass="line"><aname="l00191"></a><spanclass="lineno"> 191</span> <spanclass="comment">// every 10th iteration, reduce the neighborhood range</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_aeaeffbff2be4d5d15b0d4f10f846abde_cgraph.svg"width="452"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aname="l00076"></a><spanclass="lineno"> 76</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i < num_points; i++) <spanclass="comment">// for each point in the array</span></div>
<divclass="line"><aname="l00078"></a><spanclass="lineno"> 78</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> j = 0; j < num_features; j++) <spanclass="comment">// for each feature in the array</span></div>
<divclass="line"><aname="l00080"></a><spanclass="lineno"> 80</span>  fprintf(fp, <spanclass="stringliteral">"%.4g"</span>, X[i][j]); <spanclass="comment">// print the feature value</span></div>
<divclass="line"><aname="l00081"></a><spanclass="lineno"> 81</span> <spanclass="keywordflow">if</span> (j < num_features - 1) <spanclass="comment">// if not the last feature</span></div>
<divclass="line"><aname="l00084"></a><spanclass="lineno"> 84</span> <spanclass="keywordflow">if</span> (i < num_points - 1) <spanclass="comment">// if not the last row</span></div>
<divclass="line"><aname="l00085"></a><spanclass="lineno"> 85</span>  fprintf(fp, <spanclass="stringliteral">"\n"</span>); <spanclass="comment">// start a new line</span></div>
<p>Test that creates a random set of points distributed <em>near</em> the circumference of a circle and trains an SOM that finds that circular pattern. </p>
<p>The following <ahref="https://en.wikipedia.org/wiki/Comma-separated_values">CSV</a> files are created to validate the execution:</p><ul>
<li><code>test1.csv</code>: random test samples points with a circular pattern</li>
<li><code>w11.csv</code>: initial random map</li>
<li><code>w12.csv</code>: trained SOM map</li>
</ul>
<p>The outputs can be readily plotted in <ahref="https:://gnuplot.info">gnuplot</a> using the following snippet </p><divclass="fragment"><divclass="line">set datafile separator ','</div>
<divclass="line">plot "test1.csv" title "original", \</div>
<divclass="line">"w11.csv" title "w1", \</div>
<divclass="line">"w12.csv" title "w2"</div>
</div><!-- fragment --><p><imgsrc="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test1.svg"alt="Sampleexecution
<divclass="line"><aname="l00262"></a><spanclass="lineno"> 262</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++) <spanclass="comment">// loop till max(N, num_out)</span></div>
<divclass="line"><aname="l00264"></a><spanclass="lineno"> 264</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>) <spanclass="comment">// only add new arrays if i < N</span></div>
<divclass="line"><aname="l00266"></a><spanclass="lineno"> 266</span> <spanclass="keywordflow">if</span> (i < num_out) <spanclass="comment">// only add new arrays if i < num_out</span></div>
<divclass="line"><aname="l00277"></a><spanclass="lineno"> 277</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">test_circle</a>(X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); <spanclass="comment">// create test data around circumference of a circle</span></div>
<divclass="line"><aname="l00278"></a><spanclass="lineno"> 278</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<spanclass="stringliteral">"test1.csv"</span>, X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>, features); <spanclass="comment">// save test data points</span></div>
<divclass="line"><aname="l00285"></a><spanclass="lineno"> 285</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++)</div>
<divclass="line"><aname="l00287"></a><spanclass="lineno"> 287</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>)</div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a1440a7779ac56f47a3f355ce4a8c7da0_cgraph.svg"width="551"height="190"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<p>Test that creates a random set of points distributed <em>near</em> the locus of the <ahref="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono">Lamniscate of Gerono</a> and trains an SOM that finds that circular pattern. </p>
<p>The following <ahref="https://en.wikipedia.org/wiki/Comma-separated_values">CSV</a> files are created to validate the execution:</p><ul>
<li><code>test2.csv</code>: random test samples points with a lamniscate pattern</li>
<li><code>w21.csv</code>: initial random map</li>
<li><code>w22.csv</code>: trained SOM map</li>
</ul>
<p>The outputs can be readily plotted in <ahref="https:://gnuplot.info">gnuplot</a> using the following snippet </p><divclass="fragment"><divclass="line">set datafile separator ','</div>
<divclass="line">plot "test2.csv" title "original", \</div>
<divclass="line">"w21.csv" title "w1", \</div>
<divclass="line">"w22.csv" title "w2"</div>
</div><!-- fragment --><p><imgsrc="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test2.svg"alt="Sampleexecution
<divclass="line"><aname="l00354"></a><spanclass="lineno"> 354</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++)</div>
<divclass="line"><aname="l00356"></a><spanclass="lineno"> 356</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>) <spanclass="comment">// only add new arrays if i < N</span></div>
<divclass="line"><aname="l00358"></a><spanclass="lineno"> 358</span> <spanclass="keywordflow">if</span> (i < num_out) <spanclass="comment">// only add new arrays if i < num_out</span></div>
<divclass="line"><aname="l00370"></a><spanclass="lineno"> 370</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">test_lamniscate</a>(X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); <spanclass="comment">// create test data around the lamniscate</span></div>
<divclass="line"><aname="l00371"></a><spanclass="lineno"> 371</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<spanclass="stringliteral">"test2.csv"</span>, X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>, features); <spanclass="comment">// save test data points</span></div>
<divclass="line"><aname="l00378"></a><spanclass="lineno"> 378</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++)</div>
<divclass="line"><aname="l00380"></a><spanclass="lineno"> 380</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>)</div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a0283886819c7c140a023582b7269e2d0_cgraph.svg"width="551"height="190"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<li><code>test3.csv</code>: random test samples points with a circular pattern</li>
<li><code>w31.csv</code>: initial random map</li>
<li><code>w32.csv</code>: trained SOM map</li>
</ul>
<p>The outputs can be readily plotted in <ahref="https:://gnuplot.info">gnuplot</a> using the following snippet </p><divclass="fragment"><divclass="line">set datafile separator ','</div>
<divclass="line">plot "test3.csv" title "original", \</div>
<divclass="line">"w31.csv" title "w1", \</div>
<divclass="line">"w32.csv" title "w2"</div>
</div><!-- fragment --><p><imgsrc="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test3.svg"alt="Sampleexecution
<divclass="line"><aname="l00458"></a><spanclass="lineno"> 458</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++)</div>
<divclass="line"><aname="l00460"></a><spanclass="lineno"> 460</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>) <spanclass="comment">// only add new arrays if i < N</span></div>
<divclass="line"><aname="l00462"></a><spanclass="lineno"> 462</span> <spanclass="keywordflow">if</span> (i < num_out) <spanclass="comment">// only add new arrays if i < num_out</span></div>
<divclass="line"><aname="l00474"></a><spanclass="lineno"> 474</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">test_3d_classes</a>(X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); <spanclass="comment">// create test data around the lamniscate</span></div>
<divclass="line"><aname="l00475"></a><spanclass="lineno"> 475</span> <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<spanclass="stringliteral">"test3.csv"</span>, X, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>, features); <spanclass="comment">// save test data points</span></div>
<divclass="line"><aname="l00482"></a><spanclass="lineno"> 482</span> <spanclass="keywordflow">for</span> (<spanclass="keywordtype">int</span> i = 0; i <<aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a>(num_out, <aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>); i++)</div>
<divclass="line"><aname="l00484"></a><spanclass="lineno"> 484</span> <spanclass="keywordflow">if</span> (i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>)</div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a6d0455dd5c30adda100e95f0423c786e_cgraph.svg"width="551"height="190"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aname="l00401"></a><spanclass="lineno"> 401</span> <spanclass="keyword">const</span><spanclass="keywordtype">double</span> R = 0.1; <spanclass="comment">// radius of cluster</span></div>
<divclass="line"><aname="l00415"></a><spanclass="lineno"> 415</span> <spanclass="keywordflow">for</span> (i = 0; i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; i++)</div>
<divclass="line"><aname="l00418"></a><spanclass="lineno"> 418</span>  rand() % num_classes; <spanclass="comment">// select a random class for the point</span></div>
<divclass="line"><aname="l00420"></a><spanclass="lineno"> 420</span> <spanclass="comment">// create random coordinates (x,y,z) around the centre of the class</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a41ae16442e3e5b891a58d2e5932a2cd0_cgraph.svg"width="248"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aname="l00214"></a><spanclass="lineno"> 214</span> <spanclass="keyword">const</span><spanclass="keywordtype">double</span> R = 0.75, dr = 0.3;</div>
<divclass="line"><aname="l00215"></a><spanclass="lineno"> 215</span> <spanclass="keywordtype">double</span> a_t = 0., b_t = 2.f * M_PI; <spanclass="comment">// theta random between 0 and 2*pi</span></div>
<divclass="line"><aname="l00216"></a><spanclass="lineno"> 216</span> <spanclass="keywordtype">double</span> a_r = R - dr, b_r = R + dr; <spanclass="comment">// radius random between R-dr and R+dr</span></div>
<divclass="line"><aname="l00222"></a><spanclass="lineno"> 222</span> <spanclass="keywordflow">for</span> (i = 0; i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; i++)</div>
<divclass="line"><aname="l00224"></a><spanclass="lineno"> 224</span> <spanclass="keywordtype">double</span> r = <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a>(a_r, b_r); <spanclass="comment">// random radius</span></div>
<divclass="line"><aname="l00225"></a><spanclass="lineno"> 225</span> <spanclass="keywordtype">double</span> theta = <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a>(a_t, b_t); <spanclass="comment">// random theta</span></div>
<divclass="line"><aname="l00226"></a><spanclass="lineno"> 226</span> <aclass="code"href="../../df/dea/structdata.html">data</a>[i][0] = r * cos(theta); <spanclass="comment">// convert from polar to cartesian</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a107f00650b8041f77767927073ddddb8_cgraph.svg"width="214"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<p>Creates a random set of points distributed <em>near</em> the locus of the <ahref="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono">Lamniscate of Gerono</a>. </p>
<divclass="line"><aname="l00310"></a><spanclass="lineno"> 310</span> <spanclass="keyword">const</span><spanclass="keywordtype">double</span> dr = 0.2;</div>
<divclass="line"><aname="l00316"></a><spanclass="lineno"> 316</span> <spanclass="keywordflow">for</span> (i = 0; i <<aclass="code"href="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a>; i++)</div>
<divclass="line"><aname="l00318"></a><spanclass="lineno"> 318</span> <spanclass="keywordtype">double</span> dx = <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a>(-dr, dr); <spanclass="comment">// random change in x</span></div>
<divclass="line"><aname="l00319"></a><spanclass="lineno"> 319</span> <spanclass="keywordtype">double</span> dy = <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a>(-dr, dr); <spanclass="comment">// random change in y</span></div>
<divclass="line"><aname="l00320"></a><spanclass="lineno"> 320</span> <spanclass="keywordtype">double</span> theta = <aclass="code"href="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a>(0, M_PI); <spanclass="comment">// random theta</span></div>
<divclass="line"><aname="l00321"></a><spanclass="lineno"> 321</span> <aclass="code"href="../../df/dea/structdata.html">data</a>[i][0] = dx + cos(theta); <spanclass="comment">// convert from polar to cartesian</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_aa2246f940155472084ee461f3685d614_cgraph.svg"width="246"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="line"><aname="l00135"></a><spanclass="lineno"> 135</span> <spanclass="comment">// compute Euclidian distance of each output</span></div>
<divclass="line"><aname="l00136"></a><spanclass="lineno"> 136</span> <spanclass="comment">// point from the current sample</span></div>
<divclass="line"><aname="l00137"></a><spanclass="lineno"> 137</span> <spanclass="keywordflow">for</span> (k = 0; k < num_features; k++)</div>
<divclass="line"><aname="l00151"></a><spanclass="lineno"> 151</span> <spanclass="comment">// step 3b: update the weights of nodes in the</span></div>
<divclass="line"><aname="l00157"></a><spanclass="lineno"> 157</span> <spanclass="keywordflow">for</span> (k = 0; k < num_features; k++)</div>
<divclass="line"><aname="l00158"></a><spanclass="lineno"> 158</span> <spanclass="comment">// update weights of nodes in the neighborhood</span></div>
<divclass="center"><iframescrolling="no"frameborder="0"src="../../d0/d46/kohonen__som__trace_8c_a9c98203f55242ff7a8f45a6370840e66_cgraph.svg"width="262"height="38"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
<divclass="ttc"id="akohonen__som__trace_8c_html_a7b84b14e60f47812b581d1f93057c85a"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#a7b84b14e60f47812b581d1f93057c85a">save_nd_data</a></div><divclass="ttdeci">int save_nd_data(const char *fname, double **X, int num_points, int num_features)</div><divclass="ttdoc">Save a given n-dimensional data martix to file.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:64</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_affe776513b24d84b39af8ab0930fef7f"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#affe776513b24d84b39af8ab0930fef7f">max</a></div><divclass="ttdeci">#define max(a, b)</div><divclass="ttdoc">shorthand for maximum value</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:26</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_a107f00650b8041f77767927073ddddb8"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">test_circle</a></div><divclass="ttdeci">void test_circle(double *const *data, int N)</div><divclass="ttdoc">Creates a random set of points distributed near the circumference of a circle and trains an SOM that ...</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:212</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_aeaeffbff2be4d5d15b0d4f10f846abde"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#aeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a></div><divclass="ttdeci">void kohonen_som_tracer(double **X, double *const *W, int num_samples, int num_features, int num_out, double alpha_min)</div><divclass="ttdoc">Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given...</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:173</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_a9c98203f55242ff7a8f45a6370840e66"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#a9c98203f55242ff7a8f45a6370840e66">update_weights</a></div><divclass="ttdeci">void update_weights(double const *x, double *const *W, double *D, int num_out, int num_features, double alpha, int R)</div><divclass="ttdoc">Update weights of the SOM using Kohonen algorithm.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:123</div></div>
<divclass="ttc"id="aproblem__13_2sol1_8c_html_a0240ac851181b84ac374872dc5434ee4"><divclass="ttname"><ahref="../../db/d01/problem__13_2sol1_8c.html#a0240ac851181b84ac374872dc5434ee4">N</a></div><divclass="ttdeci">#define N</div><divclass="ttdoc">number of digits of the large number</div><divclass="ttdef"><b>Definition:</b> sol1.c:109</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_a0a292ebd954c568934b1fd06666d27e6"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#a0a292ebd954c568934b1fd06666d27e6">get_min_1d</a></div><divclass="ttdeci">void get_min_1d(double const *X, int N, double *val, int *idx)</div><divclass="ttdoc">Get minimum value and index of the value in a vector.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:98</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_af5ce14f026d6d231bef29161bac2b485"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#af5ce14f026d6d231bef29161bac2b485">_random</a></div><divclass="ttdeci">double _random(double a, double b)</div><divclass="ttdoc">Helper function to generate a random number in a given interval.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:48</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_aa2246f940155472084ee461f3685d614"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">test_lamniscate</a></div><divclass="ttdeci">void test_lamniscate(double *const *data, int N)</div><divclass="ttdoc">Creates a random set of points distributed near the locus of the Lamniscate of Gerono.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:308</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_ac6afabdc09a49a433ee19d8a9486056d"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#ac6afabdc09a49a433ee19d8a9486056d">min</a></div><divclass="ttdeci">#define min(a, b)</div><divclass="ttdoc">shorthand for minimum value</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:30</div></div>
<divclass="ttc"id="akohonen__som__trace_8c_html_a41ae16442e3e5b891a58d2e5932a2cd0"><divclass="ttname"><ahref="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">test_3d_classes</a></div><divclass="ttdeci">void test_3d_classes(double *const *data, int N)</div><divclass="ttdoc">Creates a random set of points distributed in four clusters in 3D space with centroids at the points.</div><divclass="ttdef"><b>Definition:</b> kohonen_som_trace.c:399</div></div>