Files
mlpack/doc/html/random__acol__init_8hpp_source.html
T

121 lines
17 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.11"/>
<title>mlpack: src/mlpack/methods/amf/init_rules/random_acol_init.hpp Source File</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="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/javascript">
$(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra-stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">mlpack
&#160;<span id="projectnumber">master</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.11 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="namespaces.html"><span>Namespaces</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
<li><a href="globals.html"><span>File&#160;Members</span></a></li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_44a936ef30fc126706c6284a2fc0c990.html">mlpack</a></li><li class="navelem"><a class="el" href="dir_3cfbf900288ec2fe8dd2c2c8482f216e.html">methods</a></li><li class="navelem"><a class="el" href="dir_5d79f627790f2a48f4f1d0c9d0b8c107.html">amf</a></li><li class="navelem"><a class="el" href="dir_874bc73a472bc56857d75119e41021a1.html">init_rules</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">random_acol_init.hpp</div> </div>
</div><!--header-->
<div class="contents">
<a href="random__acol__init_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno"> 1</span>&#160;</div><div class="line"><a name="l00012"></a><span class="lineno"> 12</span>&#160;<span class="preprocessor">#ifndef MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP</span></div><div class="line"><a name="l00013"></a><span class="lineno"> 13</span>&#160;<span class="preprocessor">#define MLPACK_METHODS_LMF_RANDOM_ACOL_INIT_HPP</span></div><div class="line"><a name="l00014"></a><span class="lineno"> 14</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno"> 15</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="prereqs_8hpp.html">mlpack/prereqs.hpp</a>&gt;</span></div><div class="line"><a name="l00016"></a><span class="lineno"> 16</span>&#160;<span class="preprocessor">#include &lt;<a class="code" href="random_8hpp.html">mlpack/core/math/random.hpp</a>&gt;</span></div><div class="line"><a name="l00017"></a><span class="lineno"> 17</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno"> 18</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacemlpack.html">mlpack</a> {</div><div class="line"><a name="l00019"></a><span class="lineno"> 19</span>&#160;<span class="keyword">namespace </span>amf {</div><div class="line"><a name="l00020"></a><span class="lineno"> 20</span>&#160;</div><div class="line"><a name="l00043"></a><span class="lineno"> 43</span>&#160;<span class="keyword">template</span>&lt;<span class="keywordtype">size_t</span> columnsToAverage = 5&gt;</div><div class="line"><a name="l00044"></a><span class="lineno"><a class="line" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html"> 44</a></span>&#160;<span class="keyword">class </span><a class="code" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html">RandomAcolInitialization</a></div><div class="line"><a name="l00045"></a><span class="lineno"> 45</span>&#160;{</div><div class="line"><a name="l00046"></a><span class="lineno"> 46</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00047"></a><span class="lineno"> 47</span>&#160; <span class="comment">// Empty constructor required for the InitializeRule template</span></div><div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a5a66d72ff9270603b9296168527329c9"> 48</a></span>&#160; <a class="code" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a5a66d72ff9270603b9296168527329c9">RandomAcolInitialization</a>()</div><div class="line"><a name="l00049"></a><span class="lineno"> 49</span>&#160; { }</div><div class="line"><a name="l00050"></a><span class="lineno"> 50</span>&#160;</div><div class="line"><a name="l00051"></a><span class="lineno"> 51</span>&#160; <span class="keyword">template</span>&lt;<span class="keyword">typename</span> MatType&gt;</div><div class="line"><a name="l00052"></a><span class="lineno"><a class="line" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#af54f1e4efe3501ded05786889d1e3809"> 52</a></span>&#160; <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#af54f1e4efe3501ded05786889d1e3809">Initialize</a>(<span class="keyword">const</span> MatType&amp; V,</div><div class="line"><a name="l00053"></a><span class="lineno"> 53</span>&#160; <span class="keyword">const</span> <span class="keywordtype">size_t</span> r,</div><div class="line"><a name="l00054"></a><span class="lineno"> 54</span>&#160; arma::mat&amp; W,</div><div class="line"><a name="l00055"></a><span class="lineno"> 55</span>&#160; arma::mat&amp; H)</div><div class="line"><a name="l00056"></a><span class="lineno"> 56</span>&#160; {</div><div class="line"><a name="l00057"></a><span class="lineno"> 57</span>&#160; <span class="keyword">const</span> <span class="keywordtype">size_t</span> n = V.n_rows;</div><div class="line"><a name="l00058"></a><span class="lineno"> 58</span>&#160; <span class="keyword">const</span> <span class="keywordtype">size_t</span> m = V.n_cols;</div><div class="line"><a name="l00059"></a><span class="lineno"> 59</span>&#160;</div><div class="line"><a name="l00060"></a><span class="lineno"> 60</span>&#160; <span class="keywordflow">if</span> (columnsToAverage &gt; m)</div><div class="line"><a name="l00061"></a><span class="lineno"> 61</span>&#160; {</div><div class="line"><a name="l00062"></a><span class="lineno"> 62</span>&#160; <a class="code" href="classmlpack_1_1Log.html#abbf3c5ac36654c0a8f17be3549388b38">Log::Warn</a> &lt;&lt; <span class="stringliteral">&quot;Number of random columns (columnsToAverage) is more than &quot;</span></div><div class="line"><a name="l00063"></a><span class="lineno"> 63</span>&#160; &lt;&lt; <span class="stringliteral">&quot;the number of columns available in the V matrix; weird results &quot;</span></div><div class="line"><a name="l00064"></a><span class="lineno"> 64</span>&#160; &lt;&lt; <span class="stringliteral">&quot;may ensue!&quot;</span> &lt;&lt; std::endl;</div><div class="line"><a name="l00065"></a><span class="lineno"> 65</span>&#160; }</div><div class="line"><a name="l00066"></a><span class="lineno"> 66</span>&#160;</div><div class="line"><a name="l00067"></a><span class="lineno"> 67</span>&#160; W.zeros(n, r);</div><div class="line"><a name="l00068"></a><span class="lineno"> 68</span>&#160;</div><div class="line"><a name="l00069"></a><span class="lineno"> 69</span>&#160; <span class="comment">// Initialize W matrix with random columns.</span></div><div class="line"><a name="l00070"></a><span class="lineno"> 70</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> col = 0; col &lt; r; col++)</div><div class="line"><a name="l00071"></a><span class="lineno"> 71</span>&#160; {</div><div class="line"><a name="l00072"></a><span class="lineno"> 72</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> randCol = 0; randCol &lt; columnsToAverage; randCol++)</div><div class="line"><a name="l00073"></a><span class="lineno"> 73</span>&#160; {</div><div class="line"><a name="l00074"></a><span class="lineno"> 74</span>&#160; <span class="comment">// .col() does not work in this case, as of Armadillo 3.920.</span></div><div class="line"><a name="l00075"></a><span class="lineno"> 75</span>&#160; W.unsafe_col(col) += V.col(<a class="code" href="namespacemlpack_1_1math.html#aad090ac225728d74c1b66bcf52f3ab95">math::RandInt</a>(0, m));</div><div class="line"><a name="l00076"></a><span class="lineno"> 76</span>&#160; }</div><div class="line"><a name="l00077"></a><span class="lineno"> 77</span>&#160; }</div><div class="line"><a name="l00078"></a><span class="lineno"> 78</span>&#160;</div><div class="line"><a name="l00079"></a><span class="lineno"> 79</span>&#160; <span class="comment">// Now divide by p.</span></div><div class="line"><a name="l00080"></a><span class="lineno"> 80</span>&#160; W /= columnsToAverage;</div><div class="line"><a name="l00081"></a><span class="lineno"> 81</span>&#160;</div><div class="line"><a name="l00082"></a><span class="lineno"> 82</span>&#160; <span class="comment">// Initialize H to random values.</span></div><div class="line"><a name="l00083"></a><span class="lineno"> 83</span>&#160; H.randu(r, m);</div><div class="line"><a name="l00084"></a><span class="lineno"> 84</span>&#160; }</div><div class="line"><a name="l00085"></a><span class="lineno"> 85</span>&#160;</div><div class="line"><a name="l00087"></a><span class="lineno"> 87</span>&#160; <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Archive&gt;</div><div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a70e4b426849db310e9cdb228259a63ef"> 88</a></span>&#160; <span class="keywordtype">void</span> <a class="code" href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a70e4b426849db310e9cdb228259a63ef">Serialize</a>(Archive&amp; <span class="comment">/* ar */</span>, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <span class="comment">/* version */</span>) { }</div><div class="line"><a name="l00089"></a><span class="lineno"> 89</span>&#160;};</div><div class="line"><a name="l00090"></a><span class="lineno"> 90</span>&#160;</div><div class="line"><a name="l00091"></a><span class="lineno"> 91</span>&#160;} <span class="comment">// namespace amf</span></div><div class="line"><a name="l00092"></a><span class="lineno"> 92</span>&#160;} <span class="comment">// namespace mlpack</span></div><div class="line"><a name="l00093"></a><span class="lineno"> 93</span>&#160;</div><div class="line"><a name="l00094"></a><span class="lineno"> 94</span>&#160;<span class="preprocessor">#endif</span></div><div class="ttc" id="namespacemlpack_html"><div class="ttname"><a href="namespacemlpack.html">mlpack</a></div><div class="ttdoc">Linear algebra utility functions, generally performed on matrices or vectors. </div><div class="ttdef"><b>Definition:</b> <a href="binarize_8hpp_source.html#l00018">binarize.hpp:18</a></div></div>
<div class="ttc" id="prereqs_8hpp_html"><div class="ttname"><a href="prereqs_8hpp.html">prereqs.hpp</a></div><div class="ttdoc">The core includes that mlpack expects; standard C++ includes and Armadillo. </div></div>
<div class="ttc" id="classmlpack_1_1amf_1_1RandomAcolInitialization_html_af54f1e4efe3501ded05786889d1e3809"><div class="ttname"><a href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#af54f1e4efe3501ded05786889d1e3809">mlpack::amf::RandomAcolInitialization::Initialize</a></div><div class="ttdeci">static void Initialize(const MatType &amp;V, const size_t r, arma::mat &amp;W, arma::mat &amp;H)</div><div class="ttdef"><b>Definition:</b> <a href="random__acol__init_8hpp_source.html#l00052">random_acol_init.hpp:52</a></div></div>
<div class="ttc" id="classmlpack_1_1Log_html_abbf3c5ac36654c0a8f17be3549388b38"><div class="ttname"><a href="classmlpack_1_1Log.html#abbf3c5ac36654c0a8f17be3549388b38">mlpack::Log::Warn</a></div><div class="ttdeci">static MLPACK_EXPORT util::PrefixedOutStream Warn</div><div class="ttdoc">Prints warning messages prefixed with [WARN ]. </div><div class="ttdef"><b>Definition:</b> <a href="log_8hpp_source.html#l00087">log.hpp:87</a></div></div>
<div class="ttc" id="random_8hpp_html"><div class="ttname"><a href="random_8hpp.html">random.hpp</a></div><div class="ttdoc">Miscellaneous math random-related routines. </div></div>
<div class="ttc" id="classmlpack_1_1amf_1_1RandomAcolInitialization_html_a70e4b426849db310e9cdb228259a63ef"><div class="ttname"><a href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a70e4b426849db310e9cdb228259a63ef">mlpack::amf::RandomAcolInitialization::Serialize</a></div><div class="ttdeci">void Serialize(Archive &amp;, const unsigned int)</div><div class="ttdoc">Serialize the object (in this case, there is nothing to serialize). </div><div class="ttdef"><b>Definition:</b> <a href="random__acol__init_8hpp_source.html#l00088">random_acol_init.hpp:88</a></div></div>
<div class="ttc" id="classmlpack_1_1amf_1_1RandomAcolInitialization_html"><div class="ttname"><a href="classmlpack_1_1amf_1_1RandomAcolInitialization.html">mlpack::amf::RandomAcolInitialization</a></div><div class="ttdoc">This class initializes the W matrix of the AMF algorithm by averaging p randomly chosen columns of V...</div><div class="ttdef"><b>Definition:</b> <a href="random__acol__init_8hpp_source.html#l00044">random_acol_init.hpp:44</a></div></div>
<div class="ttc" id="namespacemlpack_1_1math_html_aad090ac225728d74c1b66bcf52f3ab95"><div class="ttname"><a href="namespacemlpack_1_1math.html#aad090ac225728d74c1b66bcf52f3ab95">mlpack::math::RandInt</a></div><div class="ttdeci">int RandInt(const int hiExclusive)</div><div class="ttdoc">Generates a uniform random integer. </div><div class="ttdef"><b>Definition:</b> <a href="random_8hpp_source.html#l00071">random.hpp:71</a></div></div>
<div class="ttc" id="classmlpack_1_1amf_1_1RandomAcolInitialization_html_a5a66d72ff9270603b9296168527329c9"><div class="ttname"><a href="classmlpack_1_1amf_1_1RandomAcolInitialization.html#a5a66d72ff9270603b9296168527329c9">mlpack::amf::RandomAcolInitialization::RandomAcolInitialization</a></div><div class="ttdeci">RandomAcolInitialization()</div><div class="ttdef"><b>Definition:</b> <a href="random__acol__init_8hpp_source.html#l00048">random_acol_init.hpp:48</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.11
</small></address>
</body>
<script type="text/javascript">
var x = document.getElementsByClassName("formulaDsp");
var i;
for (i = 0; i < x.length; i++)
{
x[i].width /= 4;
}
</script>
</html>