124 lines
6.8 KiB
HTML
124 lines
6.8 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: Matrices in mlpack</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
|
|
 <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 Page</span></a></li>
|
|
<li class="current"><a href="pages.html"><span>Related 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><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>
|
|
<!-- 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><!-- top -->
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">Matrices in mlpack </div> </div>
|
|
</div><!--header-->
|
|
<div class="contents">
|
|
<div class="textblock"><h1><a class="anchor" id="matintro"></a>
|
|
Introduction</h1>
|
|
<p>mlpack uses Armadillo matrices for matrix support. Armadillo is a fast C++ matrix library which makes use of advanced template techniques to provide the fastest possible matrix operations.</p>
|
|
<p>Documentation on Armadillo can be found on their website:</p>
|
|
<p><a href="http://arma.sourceforge.net/docs.html">http://arma.sourceforge.net/docs.html</a></p>
|
|
<p>Nonetheless, there are a few further caveats for mlpack Armadillo usage.</p>
|
|
<h1><a class="anchor" id="format"></a>
|
|
Column-major Matrices</h1>
|
|
<p>Armadillo matrices are stored in a column-major format; this means that on disk, each column is located in contiguous memory.</p>
|
|
<p>This means that, for the vast majority of machine learning methods, it is faster to store observations as columns and dimensions as rows. This is counter to most standard machine learning texts!</p>
|
|
<p>Major implications of this are for linear algebra. For instance, the covariance of a matrix is typically</p>
|
|
<p><img class="formulaInl" alt="$ C = X^T X $" src="form_99.png"/></p>
|
|
<p>but for a column-wise matrix, it is</p>
|
|
<p><img class="formulaInl" alt="$ C = X X^T $" src="form_100.png"/></p>
|
|
<p>and this is very important to keep in mind! If your mlpack code is not working, this may be a factor in why.</p>
|
|
<h1><a class="anchor" id="loading"></a>
|
|
Loading Matrices</h1>
|
|
<p>mlpack provides a <a class="el" href="namespacemlpack_1_1data.html#a19805d6585ac8b0be7c4e4b7f081977c" title="Loads a matrix from file, guessing the filetype from the extension. ">data::Load()</a> and <a class="el" href="namespacemlpack_1_1data.html#a16bc794b14db0ab126595b19a32a5bc0" title="Saves a matrix to file, guessing the filetype from the extension. ">data::Save()</a> function, which should be used instead of Armadillo's loading and saving functions.</p>
|
|
<p>Most machine learning data is stored in row-major format; a CSV, for example, will generally have one observation per line and each column will correspond to a dimension.</p>
|
|
<p>The <a class="el" href="namespacemlpack_1_1data.html#a19805d6585ac8b0be7c4e4b7f081977c" title="Loads a matrix from file, guessing the filetype from the extension. ">data::Load()</a> and <a class="el" href="namespacemlpack_1_1data.html#a16bc794b14db0ab126595b19a32a5bc0" title="Saves a matrix to file, guessing the filetype from the extension. ">data::Save()</a> functions transpose the matrix upon loading, meaning that the following CSV:</p>
|
|
<div class="fragment"><div class="line">$ cat data.csv</div><div class="line">3,3,3,3,0</div><div class="line">3,4,4,3,0</div><div class="line">3,4,4,3,0</div><div class="line">3,3,4,3,0</div><div class="line">3,6,4,3,0</div><div class="line">2,4,4,3,0</div><div class="line">2,4,4,1,0</div><div class="line">3,3,3,2,0</div><div class="line">3,4,4,2,0</div><div class="line">3,4,4,2,0</div><div class="line">3,3,4,2,0</div><div class="line">3,6,4,2,0</div><div class="line">2,4,4,2,0</div></div><!-- fragment --><p>is actually loaded with 5 rows and 13 columns, not 13 rows and 5 columns like the CSV is written.</p>
|
|
<p>This is important to remember! </p>
|
|
</div></div><!-- contents -->
|
|
<!-- start footer part -->
|
|
<hr class="footer"/><address class="footer"><small>
|
|
Generated by  <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>
|