mirror of
https://github.com/TheAlgorithms/C
synced 2024-12-12 06:43:58 +03:00
757 lines
70 KiB
HTML
757 lines
70 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/kohonen_som_trace.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"> 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&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&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&dn=expat.txt MIT */
|
|
$(document).ready(function(){initNavTree('d0/d46/kohonen__som__trace_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="#define-members">Macros</a> |
|
|
<a href="#func-members">Functions</a> </div>
|
|
<div class="headertitle"><div class="title">kohonen_som_trace.c File Reference</div></div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
|
|
<p><a href="https://en.wikipedia.org/wiki/Self-organizing_map" target="_blank">Kohonen self organizing map</a> (data tracing)
|
|
<a href="#details">More...</a></p>
|
|
<div class="textblock"><code>#include <math.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 kohonen_som_trace.c:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../da/dfd/kohonen__som__trace_8c__incl.svg" width="331" 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="define-members" name="define-members"></a>
|
|
Macros</h2></td></tr>
|
|
<tr class="memitem:a525335710b53cb064ca56b936120431e"><td class="memItemLeft" align="right" valign="top"><a id="a525335710b53cb064ca56b936120431e" name="a525335710b53cb064ca56b936120431e"></a>
|
|
#define </td><td class="memItemRight" valign="bottom"><b>_USE_MATH_DEFINES</b></td></tr>
|
|
<tr class="memdesc:a525335710b53cb064ca56b936120431e"><td class="mdescLeft"> </td><td class="mdescRight">required for MS Visual C <br /></td></tr>
|
|
<tr class="separator:a525335710b53cb064ca56b936120431e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gaffe776513b24d84b39af8ab0930fef7f"><td class="memItemLeft" align="right" valign="top">
|
|
#define </td><td class="memItemRight" valign="bottom"><b>max</b>(a, b)   (((a) > (b)) ? (a) : (b))</td></tr>
|
|
<tr class="memdesc:gaffe776513b24d84b39af8ab0930fef7f"><td class="mdescLeft"> </td><td class="mdescRight">shorthand for maximum value <br /></td></tr>
|
|
<tr class="separator:gaffe776513b24d84b39af8ab0930fef7f"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gac6afabdc09a49a433ee19d8a9486056d"><td class="memItemLeft" align="right" valign="top">
|
|
#define </td><td class="memItemRight" valign="bottom"><b>min</b>(a, b)   (((a) < (b)) ? (a) : (b))</td></tr>
|
|
<tr class="memdesc:gac6afabdc09a49a433ee19d8a9486056d"><td class="mdescLeft"> </td><td class="mdescRight">shorthand for minimum value <br /></td></tr>
|
|
<tr class="separator:gac6afabdc09a49a433ee19d8a9486056d"><td class="memSeparator" colspan="2"> </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:gaf5ce14f026d6d231bef29161bac2b485"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a> (double a, double b)</td></tr>
|
|
<tr class="memdesc:gaf5ce14f026d6d231bef29161bac2b485"><td class="mdescLeft"> </td><td class="mdescRight">Helper function to generate a random number in a given interval. <a href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">More...</a><br /></td></tr>
|
|
<tr class="separator:gaf5ce14f026d6d231bef29161bac2b485"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga7b84b14e60f47812b581d1f93057c85a"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a> (const char *fname, double **X, int num_points, int num_features)</td></tr>
|
|
<tr class="memdesc:ga7b84b14e60f47812b581d1f93057c85a"><td class="mdescLeft"> </td><td class="mdescRight">Save a given n-dimensional data martix to file. <a href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">More...</a><br /></td></tr>
|
|
<tr class="separator:ga7b84b14e60f47812b581d1f93057c85a"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:ga4a57a413a3cef286a7da6d4666575586"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/dcb/group__kohonen__1d.html#ga4a57a413a3cef286a7da6d4666575586">kohonen_get_min_1d</a> (double const *X, int N, double *val, int *idx)</td></tr>
|
|
<tr class="memdesc:ga4a57a413a3cef286a7da6d4666575586"><td class="mdescLeft"> </td><td class="mdescRight">Get minimum value and index of the value in a vector. <a href="../../d0/dcb/group__kohonen__1d.html#ga4a57a413a3cef286a7da6d4666575586">More...</a><br /></td></tr>
|
|
<tr class="separator:ga4a57a413a3cef286a7da6d4666575586"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gae334493a0917a24736fe5ba82aa6f81f"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/dcb/group__kohonen__1d.html#gae334493a0917a24736fe5ba82aa6f81f">kohonen_update_weights</a> (double const *x, double *const *W, double *D, int num_out, int num_features, double alpha, int R)</td></tr>
|
|
<tr class="memdesc:gae334493a0917a24736fe5ba82aa6f81f"><td class="mdescLeft"> </td><td class="mdescRight">Update weights of the SOM using Kohonen algorithm. <a href="../../d0/dcb/group__kohonen__1d.html#gae334493a0917a24736fe5ba82aa6f81f">More...</a><br /></td></tr>
|
|
<tr class="separator:gae334493a0917a24736fe5ba82aa6f81f"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:gaeaeffbff2be4d5d15b0d4f10f846abde"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a> (double **X, double *const *W, int num_samples, int num_features, int num_out, double alpha_min)</td></tr>
|
|
<tr class="memdesc:gaeaeffbff2be4d5d15b0d4f10f846abde"><td class="mdescLeft"> </td><td class="mdescRight">Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given datset. <a href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">More...</a><br /></td></tr>
|
|
<tr class="separator:gaeaeffbff2be4d5d15b0d4f10f846abde"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a107f00650b8041f77767927073ddddb8"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">test_circle</a> (double *const *<a class="el" href="../../df/dea/structdata.html">data</a>, int N)</td></tr>
|
|
<tr class="memdesc:a107f00650b8041f77767927073ddddb8"><td class="mdescLeft"> </td><td class="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. <a href="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">More...</a><br /></td></tr>
|
|
<tr class="separator:a107f00650b8041f77767927073ddddb8"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a1440a7779ac56f47a3f355ce4a8c7da0"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a> ()</td></tr>
|
|
<tr class="memdesc:a1440a7779ac56f47a3f355ce4a8c7da0"><td class="mdescLeft"> </td><td class="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. <a href="../../d0/d46/kohonen__som__trace_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">More...</a><br /></td></tr>
|
|
<tr class="separator:a1440a7779ac56f47a3f355ce4a8c7da0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:aa2246f940155472084ee461f3685d614"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">test_lamniscate</a> (double *const *<a class="el" href="../../df/dea/structdata.html">data</a>, int N)</td></tr>
|
|
<tr class="memdesc:aa2246f940155472084ee461f3685d614"><td class="mdescLeft"> </td><td class="mdescRight">Creates a random set of points distributed <em>near</em> the locus of the <a href="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono" target="_blank">Lamniscate of Gerono</a>. <a href="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">More...</a><br /></td></tr>
|
|
<tr class="separator:aa2246f940155472084ee461f3685d614"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a0283886819c7c140a023582b7269e2d0"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a> ()</td></tr>
|
|
<tr class="memdesc:a0283886819c7c140a023582b7269e2d0"><td class="mdescLeft"> </td><td class="mdescRight">Test that creates a random set of points distributed <em>near</em> the locus of the <a href="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono" target="_blank">Lamniscate of Gerono</a> and trains an SOM that finds that circular pattern. <a href="../../d0/d46/kohonen__som__trace_8c.html#a0283886819c7c140a023582b7269e2d0">More...</a><br /></td></tr>
|
|
<tr class="separator:a0283886819c7c140a023582b7269e2d0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a41ae16442e3e5b891a58d2e5932a2cd0"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">test_3d_classes</a> (double *const *<a class="el" href="../../df/dea/structdata.html">data</a>, int N)</td></tr>
|
|
<tr class="memdesc:a41ae16442e3e5b891a58d2e5932a2cd0"><td class="mdescLeft"> </td><td class="mdescRight">Creates a random set of points distributed in four clusters in 3D space with centroids at the points. <a href="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">More...</a><br /></td></tr>
|
|
<tr class="separator:a41ae16442e3e5b891a58d2e5932a2cd0"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a6d0455dd5c30adda100e95f0423c786e"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a6d0455dd5c30adda100e95f0423c786e">test3</a> ()</td></tr>
|
|
<tr class="memdesc:a6d0455dd5c30adda100e95f0423c786e"><td class="mdescLeft"> </td><td class="mdescRight">Test that creates a random set of points distributed in six clusters in 3D space. <a href="../../d0/d46/kohonen__som__trace_8c.html#a6d0455dd5c30adda100e95f0423c786e">More...</a><br /></td></tr>
|
|
<tr class="separator:a6d0455dd5c30adda100e95f0423c786e"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a2256c10b16edba377b64a44b6c656908"><td class="memItemLeft" align="right" valign="top">double </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">get_clock_diff</a> (clock_t start_t, clock_t end_t)</td></tr>
|
|
<tr class="memdesc:a2256c10b16edba377b64a44b6c656908"><td class="mdescLeft"> </td><td class="mdescRight">Convert clock cycle difference to time in seconds. <a href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">More...</a><br /></td></tr>
|
|
<tr class="separator:a2256c10b16edba377b64a44b6c656908"><td class="memSeparator" colspan="2"> </td></tr>
|
|
<tr class="memitem:a3c04138a5bfe5d72780bb7e82a18e627"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d0/d46/kohonen__som__trace_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a> (int argc, char **argv)</td></tr>
|
|
<tr class="memdesc:a3c04138a5bfe5d72780bb7e82a18e627"><td class="mdescLeft"> </td><td class="mdescRight">Main function. <a href="../../d0/d46/kohonen__som__trace_8c.html#a3c04138a5bfe5d72780bb7e82a18e627">More...</a><br /></td></tr>
|
|
<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/Self-organizing_map" target="_blank">Kohonen self organizing map</a> (data tracing) </p>
|
|
<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 creates a chain of nodes that resembles the given input shape. </p><dl class="section author"><dt>Author</dt><dd><a href="https://github.com/kvedala" target="_blank">Krishna Vedala</a> </dd></dl>
|
|
<dl class="section see"><dt>See also</dt><dd><a class="el" href="../../d2/df6/kohonen__som__topology_8c.html" title="Kohonen self organizing map (topological map)">kohonen_som_topology.c</a> </dd></dl>
|
|
</div><h2 class="groupheader">Function Documentation</h2>
|
|
<a id="a2256c10b16edba377b64a44b6c656908" name="a2256c10b16edba377b64a44b6c656908"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a2256c10b16edba377b64a44b6c656908">◆ </a></span>get_clock_diff()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">double get_clock_diff </td>
|
|
<td>(</td>
|
|
<td class="paramtype">clock_t </td>
|
|
<td class="paramname"><em>start_t</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">clock_t </td>
|
|
<td class="paramname"><em>end_t</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Convert clock cycle difference to time in seconds. </p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">start_t</td><td>start clock </td></tr>
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">end_t</td><td>end clock </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<dl class="section return"><dt>Returns</dt><dd>time difference in seconds </dd></dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 512</span>{</div>
|
|
<div class="line"><span class="lineno"> 513</span> <span class="keywordflow">return</span> (<span class="keywordtype">double</span>)(end_t - start_t) / (<span class="keywordtype">double</span>)CLOCKS_PER_SEC;</div>
|
|
<div class="line"><span class="lineno"> 514</span>}</div>
|
|
</div><!-- fragment -->
|
|
</div>
|
|
</div>
|
|
<a id="a3c04138a5bfe5d72780bb7e82a18e627" name="a3c04138a5bfe5d72780bb7e82a18e627"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a3c04138a5bfe5d72780bb7e82a18e627">◆ </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 </td>
|
|
<td class="paramname"><em>argc</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">char ** </td>
|
|
<td class="paramname"><em>argv</em> </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"> 518</span>{</div>
|
|
<div class="line"><span class="lineno"> 519</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 520</span> printf(<span class="stringliteral">"Using OpenMP based parallelization\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 521</span><span class="preprocessor">#else</span></div>
|
|
<div class="line"><span class="lineno"> 522</span> printf(<span class="stringliteral">"NOT using OpenMP based parallelization\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 523</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 524</span> clock_t start_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 525</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a>();</div>
|
|
<div class="line"><span class="lineno"> 526</span> clock_t end_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 527</span> printf(<span class="stringliteral">"Test 1 completed in %.4g sec\n"</span>,</div>
|
|
<div class="line"><span class="lineno"> 528</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">get_clock_diff</a>(start_clk, end_clk));</div>
|
|
<div class="line"><span class="lineno"> 529</span> start_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 530</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a>();</div>
|
|
<div class="line"><span class="lineno"> 531</span> end_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 532</span> printf(<span class="stringliteral">"Test 2 completed in %.4g sec\n"</span>,</div>
|
|
<div class="line"><span class="lineno"> 533</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">get_clock_diff</a>(start_clk, end_clk));</div>
|
|
<div class="line"><span class="lineno"> 534</span> start_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 535</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a6d0455dd5c30adda100e95f0423c786e">test3</a>();</div>
|
|
<div class="line"><span class="lineno"> 536</span> end_clk = clock();</div>
|
|
<div class="line"><span class="lineno"> 537</span> printf(<span class="stringliteral">"Test 3 completed in %.4g sec\n"</span>,</div>
|
|
<div class="line"><span class="lineno"> 538</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">get_clock_diff</a>(start_clk, end_clk));</div>
|
|
<div class="line"><span class="lineno"> 539</span> printf(</div>
|
|
<div class="line"><span class="lineno"> 540</span> <span class="stringliteral">"(Note: Calculated times include: creating test sets, training "</span></div>
|
|
<div class="line"><span class="lineno"> 541</span> <span class="stringliteral">"model and writing files to disk.)\n\n"</span>);</div>
|
|
<div class="line"><span class="lineno"> 542</span> <span class="keywordflow">return</span> 0;</div>
|
|
<div class="line"><span class="lineno"> 543</span>}</div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a0283886819c7c140a023582b7269e2d0"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#a0283886819c7c140a023582b7269e2d0">test2</a></div><div class="ttdeci">void test2()</div><div class="ttdoc">Test that creates a random set of points distributed near the locus of the Lamniscate of Gerono and t...</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:358</div></div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a1440a7779ac56f47a3f355ce4a8c7da0"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#a1440a7779ac56f47a3f355ce4a8c7da0">test1</a></div><div class="ttdeci">void test1()</div><div class="ttdoc">Test that creates a random set of points distributed near the circumference of a circle and trains an...</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:261</div></div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a2256c10b16edba377b64a44b6c656908"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#a2256c10b16edba377b64a44b6c656908">get_clock_diff</a></div><div class="ttdeci">double get_clock_diff(clock_t start_t, clock_t end_t)</div><div class="ttdoc">Convert clock cycle difference to time in seconds.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:511</div></div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a6d0455dd5c30adda100e95f0423c786e"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_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 six clusters in 3D space.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:462</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="../../d0/d46/kohonen__som__trace_8c_a3c04138a5bfe5d72780bb7e82a18e627_cgraph.svg" width="100%" height="578"><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="a1440a7779ac56f47a3f355ce4a8c7da0" name="a1440a7779ac56f47a3f355ce4a8c7da0"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a1440a7779ac56f47a3f355ce4a8c7da0">◆ </a></span>test1()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test1 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<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 <a href="https://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">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 <a href="https:://gnuplot.info" target="_blank">gnuplot</a> using the following snippet </p><div class="fragment"><div class="line">set datafile separator ','</div>
|
|
<div class="line">plot "test1.csv" title "original", \</div>
|
|
<div class="line"> "w11.csv" title "w1", \</div>
|
|
<div class="line"> "w12.csv" title "w2"</div>
|
|
</div><!-- fragment --><p> <img src="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test1.svg" alt="Sample execution
|
|
output" style="pointer-events: none;" class="inline"/> </p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 262</span>{</div>
|
|
<div class="line"><span class="lineno"> 263</span> <span class="keywordtype">int</span> j, N = 500;</div>
|
|
<div class="line"><span class="lineno"> 264</span> <span class="keywordtype">int</span> features = 2;</div>
|
|
<div class="line"><span class="lineno"> 265</span> <span class="keywordtype">int</span> num_out = 50;</div>
|
|
<div class="line"><span class="lineno"> 266</span> </div>
|
|
<div class="line"><span class="lineno"> 267</span> <span class="comment">// 2D space, hence size = number of rows * 2</span></div>
|
|
<div class="line"><span class="lineno"> 268</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"> 269</span> </div>
|
|
<div class="line"><span class="lineno"> 270</span> <span class="comment">// number of clusters nodes * 2</span></div>
|
|
<div class="line"><span class="lineno"> 271</span> <span class="keywordtype">double</span> **W = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(num_out * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
|
|
<div class="line"><span class="lineno"> 272</span> </div>
|
|
<div class="line"><span class="lineno"> 273</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++) <span class="comment">// loop till max(N, num_out)</span></div>
|
|
<div class="line"><span class="lineno"> 274</span> {</div>
|
|
<div class="line"><span class="lineno"> 275</span> <span class="keywordflow">if</span> (i < N) <span class="comment">// only add new arrays if i < N</span></div>
|
|
<div class="line"><span class="lineno"> 276</span> X[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 277</span> <span class="keywordflow">if</span> (i < num_out) <span class="comment">// only add new arrays if i < num_out</span></div>
|
|
<div class="line"><span class="lineno"> 278</span> {</div>
|
|
<div class="line"><span class="lineno"> 279</span> W[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 280</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 281</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 282</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 283</span> <span class="comment">// preallocate with random initial weights</span></div>
|
|
<div class="line"><span class="lineno"> 284</span> <span class="keywordflow">for</span> (j = 0; j < features; j++) W[i][j] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(-1, 1);</div>
|
|
<div class="line"><span class="lineno"> 285</span> }</div>
|
|
<div class="line"><span class="lineno"> 286</span> }</div>
|
|
<div class="line"><span class="lineno"> 287</span> </div>
|
|
<div class="line"><span class="lineno"> 288</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">test_circle</a>(X, N); <span class="comment">// create test data around circumference of a circle</span></div>
|
|
<div class="line"><span class="lineno"> 289</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"test1.csv"</span>, X, N, features); <span class="comment">// save test data points</span></div>
|
|
<div class="line"><span class="lineno"> 290</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w11.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 291</span> features); <span class="comment">// save initial random weights</span></div>
|
|
<div class="line"><span class="lineno"> 292</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a>(X, W, N, features, num_out, 0.1); <span class="comment">// train the SOM</span></div>
|
|
<div class="line"><span class="lineno"> 293</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w12.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 294</span> features); <span class="comment">// save the resultant weights</span></div>
|
|
<div class="line"><span class="lineno"> 295</span> </div>
|
|
<div class="line"><span class="lineno"> 296</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++)</div>
|
|
<div class="line"><span class="lineno"> 297</span> {</div>
|
|
<div class="line"><span class="lineno"> 298</span> <span class="keywordflow">if</span> (i < N)</div>
|
|
<div class="line"><span class="lineno"> 299</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X[i]);</div>
|
|
<div class="line"><span class="lineno"> 300</span> <span class="keywordflow">if</span> (i < num_out)</div>
|
|
<div class="line"><span class="lineno"> 301</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(W[i]);</div>
|
|
<div class="line"><span class="lineno"> 302</span> }</div>
|
|
<div class="line"><span class="lineno"> 303</span>}</div>
|
|
<div class="ttc" id="agroup__kohonen__1d_html_ga7b84b14e60f47812b581d1f93057c85a"><div class="ttname"><a href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a></div><div class="ttdeci">int save_nd_data(const char *fname, double **X, int num_points, int num_features)</div><div class="ttdoc">Save a given n-dimensional data martix to file.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:70</div></div>
|
|
<div class="ttc" id="agroup__kohonen__1d_html_gaeaeffbff2be4d5d15b0d4f10f846abde"><div class="ttname"><a href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a></div><div class="ttdeci">void kohonen_som_tracer(double **X, double *const *W, int num_samples, int num_features, int num_out, double alpha_min)</div><div class="ttdoc">Apply incremental algorithm with updating neighborhood and learning rates on all samples in the given...</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:179</div></div>
|
|
<div class="ttc" id="agroup__kohonen__1d_html_gaf5ce14f026d6d231bef29161bac2b485"><div class="ttname"><a href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a></div><div class="ttdeci">double _random(double a, double b)</div><div class="ttdoc">Helper function to generate a random number in a given interval.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:54</div></div>
|
|
<div class="ttc" id="agroup__kohonen__1d_html_gaffe776513b24d84b39af8ab0930fef7f"><div class="ttname"><a href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a></div><div class="ttdeci">#define max(a, b)</div><div class="ttdoc">shorthand for maximum value</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:32</div></div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a107f00650b8041f77767927073ddddb8"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#a107f00650b8041f77767927073ddddb8">test_circle</a></div><div class="ttdeci">void test_circle(double *const *data, int N)</div><div class="ttdoc">Creates a random set of points distributed near the circumference of a circle and trains an SOM that ...</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:223</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><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_a1440a7779ac56f47a3f355ce4a8c7da0_cgraph.svg" width="663" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a0283886819c7c140a023582b7269e2d0" name="a0283886819c7c140a023582b7269e2d0"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a0283886819c7c140a023582b7269e2d0">◆ </a></span>test2()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test2 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test that creates a random set of points distributed <em>near</em> the locus of the <a href="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono" target="_blank">Lamniscate of Gerono</a> and trains an SOM that finds that circular pattern. </p>
|
|
<p >The following <a href="https://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">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 <a href="https:://gnuplot.info" target="_blank">gnuplot</a> using the following snippet </p><div class="fragment"><div class="line">set datafile separator ','</div>
|
|
<div class="line">plot "test2.csv" title "original", \</div>
|
|
<div class="line"> "w21.csv" title "w1", \</div>
|
|
<div class="line"> "w22.csv" title "w2"</div>
|
|
</div><!-- fragment --><p> <img src="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test2.svg" alt="Sample execution
|
|
output" style="pointer-events: none;" class="inline"/> </p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 359</span>{</div>
|
|
<div class="line"><span class="lineno"> 360</span> <span class="keywordtype">int</span> j, N = 500;</div>
|
|
<div class="line"><span class="lineno"> 361</span> <span class="keywordtype">int</span> features = 2;</div>
|
|
<div class="line"><span class="lineno"> 362</span> <span class="keywordtype">int</span> num_out = 20;</div>
|
|
<div class="line"><span class="lineno"> 363</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"> 364</span> <span class="keywordtype">double</span> **W = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(num_out * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
|
|
<div class="line"><span class="lineno"> 365</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++)</div>
|
|
<div class="line"><span class="lineno"> 366</span> {</div>
|
|
<div class="line"><span class="lineno"> 367</span> <span class="keywordflow">if</span> (i < N) <span class="comment">// only add new arrays if i < N</span></div>
|
|
<div class="line"><span class="lineno"> 368</span> X[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 369</span> <span class="keywordflow">if</span> (i < num_out) <span class="comment">// only add new arrays if i < num_out</span></div>
|
|
<div class="line"><span class="lineno"> 370</span> {</div>
|
|
<div class="line"><span class="lineno"> 371</span> W[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 372</span> </div>
|
|
<div class="line"><span class="lineno"> 373</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 374</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 375</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 376</span> <span class="comment">// preallocate with random initial weights</span></div>
|
|
<div class="line"><span class="lineno"> 377</span> <span class="keywordflow">for</span> (j = 0; j < features; j++) W[i][j] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(-1, 1);</div>
|
|
<div class="line"><span class="lineno"> 378</span> }</div>
|
|
<div class="line"><span class="lineno"> 379</span> }</div>
|
|
<div class="line"><span class="lineno"> 380</span> </div>
|
|
<div class="line"><span class="lineno"> 381</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">test_lamniscate</a>(X, N); <span class="comment">// create test data around the lamniscate</span></div>
|
|
<div class="line"><span class="lineno"> 382</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"test2.csv"</span>, X, N, features); <span class="comment">// save test data points</span></div>
|
|
<div class="line"><span class="lineno"> 383</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w21.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 384</span> features); <span class="comment">// save initial random weights</span></div>
|
|
<div class="line"><span class="lineno"> 385</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a>(X, W, N, features, num_out, 0.01); <span class="comment">// train the SOM</span></div>
|
|
<div class="line"><span class="lineno"> 386</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w22.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 387</span> features); <span class="comment">// save the resultant weights</span></div>
|
|
<div class="line"><span class="lineno"> 388</span> </div>
|
|
<div class="line"><span class="lineno"> 389</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++)</div>
|
|
<div class="line"><span class="lineno"> 390</span> {</div>
|
|
<div class="line"><span class="lineno"> 391</span> <span class="keywordflow">if</span> (i < N)</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[i]);</div>
|
|
<div class="line"><span class="lineno"> 393</span> <span class="keywordflow">if</span> (i < num_out)</div>
|
|
<div class="line"><span class="lineno"> 394</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(W[i]);</div>
|
|
<div class="line"><span class="lineno"> 395</span> }</div>
|
|
<div class="line"><span class="lineno"> 396</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X);</div>
|
|
<div class="line"><span class="lineno"> 397</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(W);</div>
|
|
<div class="line"><span class="lineno"> 398</span>}</div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_aa2246f940155472084ee461f3685d614"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#aa2246f940155472084ee461f3685d614">test_lamniscate</a></div><div class="ttdeci">void test_lamniscate(double *const *data, int N)</div><div class="ttdoc">Creates a random set of points distributed near the locus of the Lamniscate of Gerono.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:319</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_a0283886819c7c140a023582b7269e2d0_cgraph.svg" width="663" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a6d0455dd5c30adda100e95f0423c786e" name="a6d0455dd5c30adda100e95f0423c786e"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a6d0455dd5c30adda100e95f0423c786e">◆ </a></span>test3()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test3 </td>
|
|
<td>(</td>
|
|
<td class="paramname"></td><td>)</td>
|
|
<td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Test that creates a random set of points distributed in six clusters in 3D space. </p>
|
|
<p >The following <a href="https://en.wikipedia.org/wiki/Comma-separated_values" target="_blank">CSV</a> files are created to validate the execution:</p><ul>
|
|
<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 <a href="https:://gnuplot.info" target="_blank">gnuplot</a> using the following snippet </p><div class="fragment"><div class="line">set datafile separator ','</div>
|
|
<div class="line">plot "test3.csv" title "original", \</div>
|
|
<div class="line"> "w31.csv" title "w1", \</div>
|
|
<div class="line"> "w32.csv" title "w2"</div>
|
|
</div><!-- fragment --><p> <img src="https://raw.githubusercontent.com/TheAlgorithms/C/docs/images/machine_learning/kohonen/test3.svg" alt="Sample execution
|
|
output" style="pointer-events: none;" class="inline"/> </p>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 463</span>{</div>
|
|
<div class="line"><span class="lineno"> 464</span> <span class="keywordtype">int</span> j, N = 200;</div>
|
|
<div class="line"><span class="lineno"> 465</span> <span class="keywordtype">int</span> features = 3;</div>
|
|
<div class="line"><span class="lineno"> 466</span> <span class="keywordtype">int</span> num_out = 20;</div>
|
|
<div class="line"><span class="lineno"> 467</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"> 468</span> <span class="keywordtype">double</span> **W = (<span class="keywordtype">double</span> **)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(num_out * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span> *));</div>
|
|
<div class="line"><span class="lineno"> 469</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++)</div>
|
|
<div class="line"><span class="lineno"> 470</span> {</div>
|
|
<div class="line"><span class="lineno"> 471</span> <span class="keywordflow">if</span> (i < N) <span class="comment">// only add new arrays if i < N</span></div>
|
|
<div class="line"><span class="lineno"> 472</span> X[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 473</span> <span class="keywordflow">if</span> (i < num_out) <span class="comment">// only add new arrays if i < num_out</span></div>
|
|
<div class="line"><span class="lineno"> 474</span> {</div>
|
|
<div class="line"><span class="lineno"> 475</span> W[i] = (<span class="keywordtype">double</span> *)<a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(features * <span class="keyword">sizeof</span>(<span class="keywordtype">double</span>));</div>
|
|
<div class="line"><span class="lineno"> 476</span> </div>
|
|
<div class="line"><span class="lineno"> 477</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 478</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 479</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 480</span> <span class="comment">// preallocate with random initial weights</span></div>
|
|
<div class="line"><span class="lineno"> 481</span> <span class="keywordflow">for</span> (j = 0; j < features; j++) W[i][j] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(-1, 1);</div>
|
|
<div class="line"><span class="lineno"> 482</span> }</div>
|
|
<div class="line"><span class="lineno"> 483</span> }</div>
|
|
<div class="line"><span class="lineno"> 484</span> </div>
|
|
<div class="line"><span class="lineno"> 485</span> <a class="code hl_function" href="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">test_3d_classes</a>(X, N); <span class="comment">// create test data around the lamniscate</span></div>
|
|
<div class="line"><span class="lineno"> 486</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"test3.csv"</span>, X, N, features); <span class="comment">// save test data points</span></div>
|
|
<div class="line"><span class="lineno"> 487</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w31.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 488</span> features); <span class="comment">// save initial random weights</span></div>
|
|
<div class="line"><span class="lineno"> 489</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaeaeffbff2be4d5d15b0d4f10f846abde">kohonen_som_tracer</a>(X, W, N, features, num_out, 0.01); <span class="comment">// train the SOM</span></div>
|
|
<div class="line"><span class="lineno"> 490</span> <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#ga7b84b14e60f47812b581d1f93057c85a">save_nd_data</a>(<span class="stringliteral">"w32.csv"</span>, W, num_out,</div>
|
|
<div class="line"><span class="lineno"> 491</span> features); <span class="comment">// save the resultant weights</span></div>
|
|
<div class="line"><span class="lineno"> 492</span> </div>
|
|
<div class="line"><span class="lineno"> 493</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code hl_define" href="../../d0/dcb/group__kohonen__1d.html#gaffe776513b24d84b39af8ab0930fef7f">max</a>(num_out, N); i++)</div>
|
|
<div class="line"><span class="lineno"> 494</span> {</div>
|
|
<div class="line"><span class="lineno"> 495</span> <span class="keywordflow">if</span> (i < N)</div>
|
|
<div class="line"><span class="lineno"> 496</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X[i]);</div>
|
|
<div class="line"><span class="lineno"> 497</span> <span class="keywordflow">if</span> (i < num_out)</div>
|
|
<div class="line"><span class="lineno"> 498</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(W[i]);</div>
|
|
<div class="line"><span class="lineno"> 499</span> }</div>
|
|
<div class="line"><span class="lineno"> 500</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(X);</div>
|
|
<div class="line"><span class="lineno"> 501</span> <a class="code hl_define" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(W);</div>
|
|
<div class="line"><span class="lineno"> 502</span>}</div>
|
|
<div class="ttc" id="akohonen__som__trace_8c_html_a41ae16442e3e5b891a58d2e5932a2cd0"><div class="ttname"><a href="../../d0/d46/kohonen__som__trace_8c.html#a41ae16442e3e5b891a58d2e5932a2cd0">test_3d_classes</a></div><div class="ttdeci">void test_3d_classes(double *const *data, int N)</div><div class="ttdoc">Creates a random set of points distributed in four clusters in 3D space with centroids at the points.</div><div class="ttdef"><b>Definition:</b> kohonen_som_trace.c:410</div></div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_a6d0455dd5c30adda100e95f0423c786e_cgraph.svg" width="663" height="187"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a41ae16442e3e5b891a58d2e5932a2cd0" name="a41ae16442e3e5b891a58d2e5932a2cd0"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a41ae16442e3e5b891a58d2e5932a2cd0">◆ </a></span>test_3d_classes()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_3d_classes </td>
|
|
<td>(</td>
|
|
<td class="paramtype">double *const * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>N</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Creates a random set of points distributed in four clusters in 3D space with centroids at the points. </p>
|
|
<ul>
|
|
<li>\((0,5, 0.5, 0.5)\)</li>
|
|
<li>\((0,5,-0.5, -0.5)\)</li>
|
|
<li>\((-0,5, 0.5, 0.5)\)</li>
|
|
<li>\((-0,5,-0.5, -0.5)\)</li>
|
|
</ul>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramdir">[out]</td><td class="paramname">data</td><td>matrix to store data in </td></tr>
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td>number of points required </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 411</span>{</div>
|
|
<div class="line"><span class="lineno"> 412</span> <span class="keyword">const</span> <span class="keywordtype">double</span> R = 0.1; <span class="comment">// radius of cluster</span></div>
|
|
<div class="line"><span class="lineno"> 413</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 414</span> <span class="keyword">const</span> <span class="keywordtype">int</span> num_classes = 4;</div>
|
|
<div class="line"><span class="lineno"> 415</span> <span class="keyword">const</span> <span class="keywordtype">double</span> centres[][3] = {</div>
|
|
<div class="line"><span class="lineno"> 416</span> <span class="comment">// centres of each class cluster</span></div>
|
|
<div class="line"><span class="lineno"> 417</span> {.5, .5, .5}, <span class="comment">// centre of class 1</span></div>
|
|
<div class="line"><span class="lineno"> 418</span> {.5, -.5, -.5}, <span class="comment">// centre of class 2</span></div>
|
|
<div class="line"><span class="lineno"> 419</span> {-.5, .5, .5}, <span class="comment">// centre of class 3</span></div>
|
|
<div class="line"><span class="lineno"> 420</span> {-.5, -.5 - .5} <span class="comment">// centre of class 4</span></div>
|
|
<div class="line"><span class="lineno"> 421</span> };</div>
|
|
<div class="line"><span class="lineno"> 422</span> </div>
|
|
<div class="line"><span class="lineno"> 423</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 424</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 425</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 426</span> <span class="keywordflow">for</span> (i = 0; i < N; i++)</div>
|
|
<div class="line"><span class="lineno"> 427</span> {</div>
|
|
<div class="line"><span class="lineno"> 428</span> <span class="keywordtype">int</span> <span class="keyword">class </span>=</div>
|
|
<div class="line"><span class="lineno"> 429</span> rand() % num_classes; <span class="comment">// select a random class for the point</span></div>
|
|
<div class="line"><span class="lineno"> 430</span> </div>
|
|
<div class="line"><span class="lineno"> 431</span> <span class="comment">// create random coordinates (x,y,z) around the centre of the class</span></div>
|
|
<div class="line"><span class="lineno"> 432</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][0] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(centres[<span class="keyword">class</span>][0] - R, centres[<span class="keyword">class</span>][0] + R);</div>
|
|
<div class="line"><span class="lineno"> 433</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][1] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(centres[<span class="keyword">class</span>][1] - R, centres[<span class="keyword">class</span>][1] + R);</div>
|
|
<div class="line"><span class="lineno"> 434</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][2] = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(centres[<span class="keyword">class</span>][2] - R, centres[<span class="keyword">class</span>][2] + R);</div>
|
|
<div class="line"><span class="lineno"> 435</span> </div>
|
|
<div class="line"><span class="lineno"> 436</span> <span class="comment">/* The follosing can also be used</span></div>
|
|
<div class="line"><span class="lineno"> 437</span><span class="comment"> for (int j = 0; j < 3; j++)</span></div>
|
|
<div class="line"><span class="lineno"> 438</span><span class="comment"> data[i][j] = _random(centres[class][j] - R, centres[class][j] + R);</span></div>
|
|
<div class="line"><span class="lineno"> 439</span><span class="comment"> */</span></div>
|
|
<div class="line"><span class="lineno"> 440</span> }</div>
|
|
<div class="line"><span class="lineno"> 441</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"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_a41ae16442e3e5b891a58d2e5932a2cd0_cgraph.svg" width="248" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="a107f00650b8041f77767927073ddddb8" name="a107f00650b8041f77767927073ddddb8"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#a107f00650b8041f77767927073ddddb8">◆ </a></span>test_circle()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_circle </td>
|
|
<td>(</td>
|
|
<td class="paramtype">double *const * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>N</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>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 generating function is </p><p class="formulaDsp">
|
|
\begin{eqnarray*}
|
|
r &\in& [1-\delta r, 1+\delta r)\\
|
|
\theta &\in& [0, 2\pi)\\
|
|
x &=& r\cos\theta\\
|
|
y &=& r\sin\theta
|
|
\end{eqnarray*}
|
|
</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramdir">[out]</td><td class="paramname">data</td><td>matrix to store data in </td></tr>
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td>number of points required </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 224</span>{</div>
|
|
<div class="line"><span class="lineno"> 225</span> <span class="keyword">const</span> <span class="keywordtype">double</span> R = 0.75, dr = 0.3;</div>
|
|
<div class="line"><span class="lineno"> 226</span> <span class="keywordtype">double</span> a_t = 0., b_t = 2.f * M_PI; <span class="comment">// theta random between 0 and 2*pi</span></div>
|
|
<div class="line"><span class="lineno"> 227</span> <span class="keywordtype">double</span> a_r = R - dr, b_r = R + dr; <span class="comment">// radius random between R-dr and R+dr</span></div>
|
|
<div class="line"><span class="lineno"> 228</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 229</span> </div>
|
|
<div class="line"><span class="lineno"> 230</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 231</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 232</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 233</span> <span class="keywordflow">for</span> (i = 0; i < N; i++)</div>
|
|
<div class="line"><span class="lineno"> 234</span> {</div>
|
|
<div class="line"><span class="lineno"> 235</span> <span class="keywordtype">double</span> r = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(a_r, b_r); <span class="comment">// random radius</span></div>
|
|
<div class="line"><span class="lineno"> 236</span> <span class="keywordtype">double</span> theta = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(a_t, b_t); <span class="comment">// random theta</span></div>
|
|
<div class="line"><span class="lineno"> 237</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][0] = r * cos(theta); <span class="comment">// convert from polar to cartesian</span></div>
|
|
<div class="line"><span class="lineno"> 238</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][1] = r * sin(theta);</div>
|
|
<div class="line"><span class="lineno"> 239</span> }</div>
|
|
<div class="line"><span class="lineno"> 240</span>}</div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_a107f00650b8041f77767927073ddddb8_cgraph.svg" width="214" height="36"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
<a id="aa2246f940155472084ee461f3685d614" name="aa2246f940155472084ee461f3685d614"></a>
|
|
<h2 class="memtitle"><span class="permalink"><a href="#aa2246f940155472084ee461f3685d614">◆ </a></span>test_lamniscate()</h2>
|
|
|
|
<div class="memitem">
|
|
<div class="memproto">
|
|
<table class="memname">
|
|
<tr>
|
|
<td class="memname">void test_lamniscate </td>
|
|
<td>(</td>
|
|
<td class="paramtype">double *const * </td>
|
|
<td class="paramname"><em>data</em>, </td>
|
|
</tr>
|
|
<tr>
|
|
<td class="paramkey"></td>
|
|
<td></td>
|
|
<td class="paramtype">int </td>
|
|
<td class="paramname"><em>N</em> </td>
|
|
</tr>
|
|
<tr>
|
|
<td></td>
|
|
<td>)</td>
|
|
<td></td><td></td>
|
|
</tr>
|
|
</table>
|
|
</div><div class="memdoc">
|
|
|
|
<p>Creates a random set of points distributed <em>near</em> the locus of the <a href="https://en.wikipedia.org/wiki/Lemniscate_of_Gerono" target="_blank">Lamniscate of Gerono</a>. </p>
|
|
<p class="formulaDsp">
|
|
\begin{eqnarray*}
|
|
\delta r &=& 0.2\\
|
|
\delta x &\in& [-\delta r, \delta r)\\
|
|
\delta y &\in& [-\delta r, \delta r)\\
|
|
\theta &\in& [0, \pi)\\
|
|
x &=& \delta x + \cos\theta\\
|
|
y &=& \delta y + \frac{\sin(2\theta)}{2}
|
|
\end{eqnarray*}
|
|
</p>
|
|
<dl class="params"><dt>Parameters</dt><dd>
|
|
<table class="params">
|
|
<tr><td class="paramdir">[out]</td><td class="paramname">data</td><td>matrix to store data in </td></tr>
|
|
<tr><td class="paramdir">[in]</td><td class="paramname">N</td><td>number of points required </td></tr>
|
|
</table>
|
|
</dd>
|
|
</dl>
|
|
<div class="fragment"><div class="line"><span class="lineno"> 320</span>{</div>
|
|
<div class="line"><span class="lineno"> 321</span> <span class="keyword">const</span> <span class="keywordtype">double</span> dr = 0.2;</div>
|
|
<div class="line"><span class="lineno"> 322</span> <span class="keywordtype">int</span> i;</div>
|
|
<div class="line"><span class="lineno"> 323</span> </div>
|
|
<div class="line"><span class="lineno"> 324</span><span class="preprocessor">#ifdef _OPENMP</span></div>
|
|
<div class="line"><span class="lineno"> 325</span><span class="preprocessor">#pragma omp for</span></div>
|
|
<div class="line"><span class="lineno"> 326</span><span class="preprocessor">#endif</span></div>
|
|
<div class="line"><span class="lineno"> 327</span> <span class="keywordflow">for</span> (i = 0; i < N; i++)</div>
|
|
<div class="line"><span class="lineno"> 328</span> {</div>
|
|
<div class="line"><span class="lineno"> 329</span> <span class="keywordtype">double</span> dx = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(-dr, dr); <span class="comment">// random change in x</span></div>
|
|
<div class="line"><span class="lineno"> 330</span> <span class="keywordtype">double</span> dy = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(-dr, dr); <span class="comment">// random change in y</span></div>
|
|
<div class="line"><span class="lineno"> 331</span> <span class="keywordtype">double</span> theta = <a class="code hl_function" href="../../d0/dcb/group__kohonen__1d.html#gaf5ce14f026d6d231bef29161bac2b485">_random</a>(0, M_PI); <span class="comment">// random theta</span></div>
|
|
<div class="line"><span class="lineno"> 332</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][0] = dx + cos(theta); <span class="comment">// convert from polar to cartesian</span></div>
|
|
<div class="line"><span class="lineno"> 333</span> <a class="code hl_struct" href="../../df/dea/structdata.html">data</a>[i][1] = dy + sin(2. * theta) / 2.f;</div>
|
|
<div class="line"><span class="lineno"> 334</span> }</div>
|
|
<div class="line"><span class="lineno"> 335</span>}</div>
|
|
</div><!-- fragment --><div class="dynheader">
|
|
Here is the call graph for this function:</div>
|
|
<div class="dyncontent">
|
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d0/d46/kohonen__som__trace_8c_aa2246f940155472084ee461f3685d614_cgraph.svg" width="246" height="36"><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><!-- 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="../../d0/d46/kohonen__som__trace_8c.html">kohonen_som_trace.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>
|