Files
mlpack/doc/html/rstutorial.html
T

186 lines
28 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: RangeSearch tutorial (mlpack_range_search)</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 class="current"><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><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">RangeSearch tutorial (mlpack_range_search) </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="intro_rstut"></a>
Introduction</h1>
<p>Range search is a simple machine learning task which aims to find all the neighbors of a point that fall into a certain range of distances. In this setting, we have a <b>query</b> and a <b>reference</b> dataset. Given a certain range, for each point in the <b>query</b> dataset, we wish to know all points in the <b>reference</b> dataset which have distances within that given range to the given query point.</p>
<p>Alternately, if the query and reference datasets are the same, the problem can be stated more simply: for each point in the dataset, we wish to know all points which have distance in the given range to that point.</p>
<p><b>mlpack</b> provides:</p>
<ul>
<li>a <a class="el" href="rstutorial.html#cli_rstut">simple command-line executable</a> to run range search</li>
<li>a <a class="el" href="rstutorial.html#rs_rstut">simple C++ interface</a> to perform range search</li>
<li>a <a class="el" href="rstutorial.html#rs_ext_rstut">generic, extensible, and powerful C++ class (RangeSearch)</a> for complex usage</li>
</ul>
<h1><a class="anchor" id="toc_rstut"></a>
Table of Contents</h1>
<p>A list of all the sections this tutorial contains.</p>
<ul>
<li><a class="el" href="rstutorial.html#intro_rstut">Introduction</a></li>
<li><a class="el" href="rstutorial.html#toc_rstut">Table of Contents</a></li>
<li><a class="el" href="rstutorial.html#cli_rstut">The 'mlpack_range_search' command-line executable</a><ul>
<li><a class="el" href="rstutorial.html#cli_ex1_rstut">One dataset, points with distance &lt;= 0.01</a></li>
<li><a class="el" href="rstutorial.html#cli_ex2_rstut">Query and reference dataset, range [1.0, 1.5]</a></li>
<li><a class="el" href="rstutorial.html#cli_ex3_rstut">One dataset, range [0.7 0.8], leaf size of 15 points</a></li>
</ul>
</li>
<li><a class="el" href="rstutorial.html#rs_rstut">The 'RangeSearch' class</a><ul>
<li><a class="el" href="rstutorial.html#rs_ex1_rstut">Distance less than 2.0 on a single dataset</a></li>
<li><a class="el" href="rstutorial.html#rs_ex2_rstut">Range [3.0, 4.0] on a query and reference dataset</a></li>
<li><a class="el" href="rstutorial.html#rs_ex3_rstut">Naive (exhaustive) search for distance greater than 5.0 on one dataset</a></li>
</ul>
</li>
<li><a class="el" href="rstutorial.html#rs_ext_rstut">The extensible 'RangeSearch' class</a><ul>
<li><a class="el" href="rstutorial.html#metric_type_doc_rstut">MetricType policy class</a></li>
<li><a class="el" href="rstutorial.html#mat_type_doc_rstut">MatType policy class</a></li>
<li><a class="el" href="rstutorial.html#tree_type_doc_rstut">TreeType policy class</a></li>
</ul>
</li>
<li><a class="el" href="rstutorial.html#further_doc_rstut">Further documentation</a></li>
</ul>
<h1><a class="anchor" id="cli_rstut"></a>
The 'mlpack_range_search' command-line executable</h1>
<p><b>mlpack</b> provides an executable, <code>mlpack_range_search</code>, which can be used to perform range searches quickly and simply from the command-line. This program will perform the range search and place the resulting neighbor index list into one file and their corresponding distances into another file. These files are organized such that the first row corresponds to the neighbors (or distances) of the first query point, and the second row corresponds to the neighbors (or distances) of the second query point, and so forth. The neighbors of a specific point are not arranged in any specific order.</p>
<p>Because a range search may return different numbers of points (including zero), the output file is technically not a valid CSV and may not be loadable by other programs. Therefore, if you need the results in a certain format, it may be better to use the <a class="el" href="rstutorial.html#rs_rstut">C++ interface</a> to manually export the data in the preferred format.</p>
<p>Below are several examples of simple usage (and the resultant output). The '-v' option is used so that output is given. Further documentation on each individual option can be found by typing</p>
<div class="fragment"><div class="line">$ mlpack_range_search --help</div></div><!-- fragment --><h2><a class="anchor" id="cli_ex1_rstut"></a>
One dataset, points with distance &lt;= 0.01</h2>
<div class="fragment"><div class="line">$ mlpack_range_search -r dataset.csv -n neighbors_out.csv -d distances_out.csv \</div><div class="line">&gt; -U 0.076 -v</div><div class="line">[INFO ] Loading <span class="stringliteral">&#39;dataset.csv&#39;</span> as CSV data. Size is 3 x 1000.</div><div class="line">[INFO ] Loaded reference data from <span class="stringliteral">&#39;dataset.csv&#39;</span> (3x1000).</div><div class="line">[INFO ] Building reference tree...</div><div class="line">[INFO ] Tree built.</div><div class="line">[INFO ] Search <span class="keywordflow">for</span> points in the range [0, 0.076] with dual-tree kd-tree</div><div class="line">search...</div><div class="line">[INFO ] Search complete.</div><div class="line">[INFO ]</div><div class="line">[INFO ] Execution parameters:</div><div class="line">[INFO ] distances_file: distances_out.csv</div><div class="line">[INFO ] help: <span class="keyword">false</span></div><div class="line">[INFO ] info: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] input_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] leaf_size: 20</div><div class="line">[INFO ] max: 0.01</div><div class="line">[INFO ] min: 0</div><div class="line">[INFO ] naive: <span class="keyword">false</span></div><div class="line">[INFO ] neighbors_file: neighbors_out.csv</div><div class="line">[INFO ] output_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] query_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] random_basis: <span class="keyword">false</span></div><div class="line">[INFO ] reference_file: dataset.csv</div><div class="line">[INFO ] seed: 0</div><div class="line">[INFO ] single_mode: <span class="keyword">false</span></div><div class="line">[INFO ] tree_type: kd</div><div class="line">[INFO ] verbose: <span class="keyword">true</span></div><div class="line">[INFO ] version: <span class="keyword">false</span></div><div class="line">[INFO ]</div><div class="line">[INFO ] Program timers:</div><div class="line">[INFO ] loading_data: 0.005201s</div><div class="line">[INFO ] range_search/computing_neighbors: 0.017110s</div><div class="line">[INFO ] total_time: 0.033313s</div><div class="line">[INFO ] tree_building: 0.002500s</div></div><!-- fragment --><p>Convenient program timers are given for different parts of the calculation at the bottom of the output, as well as the parameters the simulation was run with. Now, if we look at the output files:</p>
<div class="fragment"><div class="line">$ head neighbors_out.csv</div><div class="line">862</div><div class="line">703</div><div class="line"></div><div class="line">397, 277, 319</div><div class="line">840</div><div class="line">732</div><div class="line"></div><div class="line">361</div><div class="line">547, 695</div><div class="line">113, 982, 689</div><div class="line"></div><div class="line">$ head distances_out.csv</div><div class="line">0.0598608</div><div class="line">0.0753264</div><div class="line"></div><div class="line">0.0207941, 0.0759762, 0.0471072</div><div class="line">0.0708221</div><div class="line">0.0568806</div><div class="line"></div><div class="line">0.0700532</div><div class="line">0.0529565, 0.0550988</div><div class="line">0.0447142, 0.0399286, 0.0734605</div></div><!-- fragment --><p>We can see that only point 862 is within distance 0.076 of point 0. We can also see that point 2 has no points within a distance of 0.076 &ndash; that line is empty.</p>
<h2><a class="anchor" id="cli_ex2_rstut"></a>
Query and reference dataset, range [1.0, 1.5]</h2>
<div class="fragment"><div class="line">$ mlpack_range_search -q query_dataset.csv -r reference_dataset.csv -n \</div><div class="line">&gt; neighbors_out.csv -d distances_out.csv -L 1.0 -U 1.5 -v</div><div class="line">[INFO ] Loading <span class="stringliteral">&#39;reference_dataset.csv&#39;</span> as CSV data. Size is 3 x 1000.</div><div class="line">[INFO ] Loaded reference data from <span class="stringliteral">&#39;reference_dataset.csv&#39;</span> (3x1000).</div><div class="line">[INFO ] Building reference tree...</div><div class="line">[INFO ] Tree built.</div><div class="line">[INFO ] Loading <span class="stringliteral">&#39;query_dataset.csv&#39;</span> as CSV data. Size is 3 x 50.</div><div class="line">[INFO ] Loaded query data from <span class="stringliteral">&#39;query_dataset.csv&#39;</span> (3x50).</div><div class="line">[INFO ] Search <span class="keywordflow">for</span> points in the range [1, 1.5] with dual-tree kd-tree search...</div><div class="line">[INFO ] Building query tree...</div><div class="line">[INFO ] Tree built.</div><div class="line">[INFO ] Search complete.</div><div class="line">[INFO ]</div><div class="line">[INFO ] Execution parameters:</div><div class="line">[INFO ] distances_file: distances_out.csv</div><div class="line">[INFO ] help: <span class="keyword">false</span></div><div class="line">[INFO ] info: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] input_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] leaf_size: 20</div><div class="line">[INFO ] max: 1.5</div><div class="line">[INFO ] min: 1</div><div class="line">[INFO ] naive: <span class="keyword">false</span></div><div class="line">[INFO ] neighbors_file: neighbors_out.csv</div><div class="line">[INFO ] output_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] query_file: query_dataset.csv</div><div class="line">[INFO ] random_basis: <span class="keyword">false</span></div><div class="line">[INFO ] reference_file: reference_dataset.csv</div><div class="line">[INFO ] seed: 0</div><div class="line">[INFO ] single_mode: <span class="keyword">false</span></div><div class="line">[INFO ] tree_type: kd</div><div class="line">[INFO ] verbose: <span class="keyword">true</span></div><div class="line">[INFO ] version: <span class="keyword">false</span></div><div class="line">[INFO ]</div><div class="line">[INFO ] Program timers:</div><div class="line">[INFO ] loading_data: 0.006199s</div><div class="line">[INFO ] range_search/computing_neighbors: 0.024427s</div><div class="line">[INFO ] total_time: 0.045403s</div><div class="line">[INFO ] tree_building: 0.003979s</div></div><!-- fragment --><h2><a class="anchor" id="cli_ex3_rstut"></a>
One dataset, range [0.7 0.8], leaf size of 15 points</h2>
<p>The <b>mlpack</b> implementation of range search is a dual-tree algorithm; when <img class="formulaInl" alt="$kd$" src="form_117.png"/>-trees are used, the leaf size of the tree can be changed. Depending on the characteristics of the dataset, a larger or smaller leaf size can provide faster computation. The leaf size is modifiable through the command-line interface, as shown below.</p>
<div class="fragment"><div class="line">$ mlpack_range_search -r dataset.csv -n neighbors_out.csv -d distances_out.csv \</div><div class="line">&gt; -L 0.7 -U 0.8 -l 15 -v</div><div class="line">[INFO ] Loading <span class="stringliteral">&#39;dataset.csv&#39;</span> as CSV data. Size is 3 x 1000.</div><div class="line">[INFO ] Loaded reference data from <span class="stringliteral">&#39;dataset.csv&#39;</span> (3x1000).</div><div class="line">[INFO ] Building reference tree...</div><div class="line">[INFO ] Tree built.</div><div class="line">[INFO ] Search <span class="keywordflow">for</span> points in the range [0.7, 0.8] with dual-tree kd-tree</div><div class="line">search...</div><div class="line">[INFO ] Search complete.</div><div class="line">[INFO ]</div><div class="line">[INFO ] Execution parameters:</div><div class="line">[INFO ] distances_file: distances_out.csv</div><div class="line">[INFO ] help: <span class="keyword">false</span></div><div class="line">[INFO ] info: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] input_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] leaf_size: 15</div><div class="line">[INFO ] max: 0.8</div><div class="line">[INFO ] min: 0.7</div><div class="line">[INFO ] naive: <span class="keyword">false</span></div><div class="line">[INFO ] neighbors_file: neighbors_out.csv</div><div class="line">[INFO ] output_model_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] query_file: <span class="stringliteral">&quot;&quot;</span></div><div class="line">[INFO ] random_basis: <span class="keyword">false</span></div><div class="line">[INFO ] reference_file: dataset.csv</div><div class="line">[INFO ] seed: 0</div><div class="line">[INFO ] single_mode: <span class="keyword">false</span></div><div class="line">[INFO ] tree_type: kd</div><div class="line">[INFO ] verbose: <span class="keyword">true</span></div><div class="line">[INFO ] version: <span class="keyword">false</span></div><div class="line">[INFO ]</div><div class="line">[INFO ] Program timers:</div><div class="line">[INFO ] loading_data: 0.006298s</div><div class="line">[INFO ] range_search/computing_neighbors: 0.411041s</div><div class="line">[INFO ] total_time: 0.539931s</div><div class="line">[INFO ] tree_building: 0.004695s</div></div><!-- fragment --><p>Further documentation on options should be found by using the &ndash;help option.</p>
<h1><a class="anchor" id="rs_rstut"></a>
The 'RangeSearch' class</h1>
<p>The 'RangeSearch' class is an extensible template class which allows a high level of flexibility. However, all of the template arguments have default parameters, allowing a user to simply use 'RangeSearch&lt;&gt;' for simple usage without worrying about the exact necessary template parameters.</p>
<p>The class bears many similarities to the <a class="el" href="nstutorial.html">NeighborSearch</a> class; usage generally consists of calling the constructor with one or two datasets, and then calling the 'Search()' method to perform the actual range search.</p>
<p>The 'Search()' method stores the results in two vector-of-vector objects. This is necessary because each query point may have a different number of neighbors in the specified distance range. The structure of those two objects is very similar to the output files &ndash;neighbors_file and &ndash;distances_file for the CLI interface (see above). A handful of examples of simple usage of the RangeSearch class are given below.</p>
<h2><a class="anchor" id="rs_ex1_rstut"></a>
Distance less than 2.0 on a single dataset</h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="range__search_8hpp.html">mlpack/methods/range_search/range_search.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacemlpack_1_1range.html">mlpack::range</a>;</div><div class="line"></div><div class="line"><span class="comment">// Our dataset matrix, which is column-major.</span></div><div class="line"><span class="keyword">extern</span> arma::mat data;</div><div class="line"></div><div class="line"><a class="code" href="classmlpack_1_1range_1_1RangeSearch.html">RangeSearch&lt;&gt;</a> a(data);</div><div class="line"></div><div class="line"><span class="comment">// The vector-of-vector objects we will store output in.</span></div><div class="line">std::vector&lt;std::vector&lt;size_t&gt; &gt; resultingNeighbors;</div><div class="line">std::vector&lt;std::vector&lt;double&gt; &gt; resultingDistances;</div><div class="line"></div><div class="line"><span class="comment">// The range we will use.</span></div><div class="line"><a class="code" href="namespacemlpack_1_1math.html#a927179bb8d2d0fb6164df385ab51cbce">math::Range</a> r(0.0, 2.0); <span class="comment">// [0.0, 2.0].</span></div><div class="line"></div><div class="line">a.Search(r, resultingNeighbors, resultingDistances);</div></div><!-- fragment --><p>The output of the search is stored in resultingNeighbors and resultingDistances.</p>
<h2><a class="anchor" id="rs_ex2_rstut"></a>
Range [3.0, 4.0] on a query and reference dataset</h2>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="range__search_8hpp.html">mlpack/methods/range_search/range_search.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacemlpack_1_1range.html">mlpack::range</a>;</div><div class="line"></div><div class="line"><span class="comment">// Our dataset matrices, which are column-major.</span></div><div class="line"><span class="keyword">extern</span> arma::mat queryData, referenceData;</div><div class="line"></div><div class="line"><a class="code" href="classmlpack_1_1range_1_1RangeSearch.html">RangeSearch&lt;&gt;</a> a(referenceData);</div><div class="line"></div><div class="line"><span class="comment">// The vector-of-vector objects we will store output in.</span></div><div class="line">std::vector&lt;std::vector&lt;size_t&gt; &gt; resultingNeighbors;</div><div class="line">std::vector&lt;std::vector&lt;double&gt; &gt; resultingDistances;</div><div class="line"></div><div class="line"><span class="comment">// The range we will use.</span></div><div class="line"><a class="code" href="namespacemlpack_1_1math.html#a927179bb8d2d0fb6164df385ab51cbce">math::Range</a> r(3.0, 4.0); <span class="comment">// [3.0, 4.0].</span></div><div class="line"></div><div class="line">a.Search(queryData, r, resultingNeighbors, resultingDistances);</div></div><!-- fragment --><h2><a class="anchor" id="rs_ex3_rstut"></a>
Naive (exhaustive) search for distance greater than 5.0 on one dataset</h2>
<p>This example uses the O(n^2) naive search (not the tree-based search).</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &lt;<a class="code" href="range__search_8hpp.html">mlpack/methods/range_search/range_search.hpp</a>&gt;</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span><a class="code" href="namespacemlpack_1_1range.html">mlpack::range</a>;</div><div class="line"></div><div class="line"><span class="comment">// Our dataset matrix, which is column-major.</span></div><div class="line"><span class="keyword">extern</span> arma::mat dataset;</div><div class="line"></div><div class="line"><span class="comment">// The &#39;true&#39; option indicates that we will use naive calculation.</span></div><div class="line"><a class="code" href="classmlpack_1_1range_1_1RangeSearch.html">RangeSearch&lt;&gt;</a> a(dataset, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"><span class="comment">// The vector-of-vector objects we will store output in.</span></div><div class="line">std::vector&lt;std::vector&lt;size_t&gt; &gt; resultingNeighbors;</div><div class="line">std::vector&lt;std::vector&lt;double&gt; &gt; resultingDistances;</div><div class="line"></div><div class="line"><span class="comment">// The range we will use. The upper bound is DBL_MAX.</span></div><div class="line"><a class="code" href="namespacemlpack_1_1math.html#a927179bb8d2d0fb6164df385ab51cbce">math::Range</a> r(5.0, DBL_MAX); <span class="comment">// [5.0, inf).</span></div><div class="line"></div><div class="line">a.Search(r, resultingNeighbors, resultingDistances);</div></div><!-- fragment --><p>Needless to say, naive search can be very slow...</p>
<h1><a class="anchor" id="rs_ext_rstut"></a>
The extensible 'RangeSearch' class</h1>
<p>Similar to the <a class="el" href="nstutorial.html">NeighborSearch class</a>, the RangeSearch class is very extensible, having the following template arguments:</p>
<div class="fragment"><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> MetricType = <a class="code" href="namespacemlpack_1_1metric.html#a012695bde5dbf7ded7f7a180b5f3f512">metric::EuclideanDistance</a>,</div><div class="line"> <span class="keyword">typename</span> MatType = arma::mat,</div><div class="line"> <span class="keyword">template</span>&lt;<span class="keyword">typename</span> TreeMetricType,</div><div class="line"> <span class="keyword">typename</span> TreeStatType,</div><div class="line"> <span class="keyword">typename</span> TreeMatType&gt; <span class="keyword">class </span>TreeType = <a class="code" href="namespacemlpack_1_1tree.html#a562474c3dca60a6ac3c5168ae88bc028">tree::KDTree</a>&gt;</div><div class="line"><span class="keyword">class </span>RangeSearch;</div></div><!-- fragment --><p>By choosing different components for each of these template classes, a very arbitrary range searching object can be constructed.</p>
<h2><a class="anchor" id="metric_type_doc_rstut"></a>
MetricType policy class</h2>
<p>The MetricType policy class allows the range search to take place in any arbitrary metric space. The <a class="el" href="classmlpack_1_1metric_1_1LMetric.html" title="The L_p metric for arbitrary integer p, with an option to take the root. ">mlpack::metric::LMetric</a> class is a good example implementation. A MetricType class must provide the following functions:</p>
<div class="fragment"><div class="line"><span class="comment">// Empty constructor is required.</span></div><div class="line">MetricType();</div><div class="line"></div><div class="line"><span class="comment">// Compute the distance between two points.</span></div><div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> VecType&gt;</div><div class="line"><span class="keywordtype">double</span> Evaluate(<span class="keyword">const</span> VecType&amp; a, <span class="keyword">const</span> VecType&amp; b);</div></div><!-- fragment --><p>Internally, the RangeSearch class keeps an instantiated MetricType class (which can be given in the constructor). This is useful for a metric like the Mahalanobis distance (<a class="el" href="classmlpack_1_1metric_1_1MahalanobisDistance.html" title="The Mahalanobis distance, which is essentially a stretched Euclidean distance. ">mlpack::metric::MahalanobisDistance</a>), which must store state (the covariance matrix). Therefore, you can write a non-static MetricType class and use it seamlessly with RangeSearch.</p>
<h2><a class="anchor" id="mat_type_doc_rstut"></a>
MatType policy class</h2>
<p>The MatType template parameter specifies the type of data matrix used. This type must implement the same operations as an Armadillo matrix, and so standard choices are <code>arma::mat</code> and <code>arma::sp_mat</code>.</p>
<h2><a class="anchor" id="tree_type_doc_rstut"></a>
TreeType policy class</h2>
<p>The RangeSearch class also allows a custom tree to be used. The TreeType policy is also used elsewhere in mlpack and is documented more thoroughly <a class="el" href="trees.html">here</a>.</p>
<p>Typical choices might include <a class="el" href="namespacemlpack_1_1tree.html#a562474c3dca60a6ac3c5168ae88bc028" title="The standard midpoint-split kd-tree. ">mlpack::tree::KDTree</a> (the default), <a class="el" href="namespacemlpack_1_1tree.html#abc9c69ba447c575b235eff25f14d99c7" title="A midpoint-split ball tree. ">mlpack::tree::BallTree</a>, <a class="el" href="namespacemlpack_1_1tree.html#a1a47efe6afda858544988d1f7927477c" title="An implementation of the R tree that satisfies the TreeType policy API. ">mlpack::tree::RTree</a>, <a class="el" href="namespacemlpack_1_1tree.html#a4e25f4921d1b4ca77a30bf82d5366da5" title="The R*-tree, a more recent variant of the R tree. ">mlpack::tree::RStarTree</a>, or <a class="el" href="namespacemlpack_1_1tree.html#a97bb6c0e6c1be359a95c89d21b1afd42" title="The standard cover tree, as detailed in the original cover tree paper: ">mlpack::tree::StandardCoverTree</a>. Below is an example that uses the RangeSearch class with an R-tree:</p>
<div class="fragment"><div class="line"><span class="comment">// Construct a RangeSearch object with ball bounds.</span></div><div class="line">RangeSearch&lt;</div><div class="line"> <a class="code" href="namespacemlpack_1_1metric.html#a012695bde5dbf7ded7f7a180b5f3f512">metric::EuclideanDistance</a>,</div><div class="line"> arma::mat,</div><div class="line"> <a class="code" href="namespacemlpack_1_1tree.html#a1a47efe6afda858544988d1f7927477c">tree::RTree</a></div><div class="line">&gt; rangeSearch(dataset);</div></div><!-- fragment --><p>For further information on trees, including how to write your own tree for use with RangeSearch and other mlpack methods, see the <a class="el" href="trees.html">TreeType policy documentation</a>.</p>
<h1><a class="anchor" id="further_doc_rstut"></a>
Further documentation</h1>
<p>For further documentation on the RangeSearch class, consult the <a class="el" href="classmlpack_1_1range_1_1RangeSearch.html">complete API documentation</a>. </p>
</div></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>