File size: 8,248 Bytes
9375c9a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - bottom_up_cluster_abstract.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2015 Davis E. King ([email protected])
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license.
</font><font color='#0000FF'>#undef</font> DLIB_BOTTOM_uP_CLUSTER_ABSTRACT_Hh_
<font color='#0000FF'>#ifdef</font> DLIB_BOTTOM_uP_CLUSTER_ABSTRACT_Hh_
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../matrix.h.html'>../matrix.h</a>"
<font color='#0000FF'>namespace</font> dlib
<b>{</b>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>template</font> <font color='#5555FF'><</font>
<font color='#0000FF'>typename</font> EXP
<font color='#5555FF'>></font>
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='bottom_up_cluster'></a>bottom_up_cluster</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> matrix_exp<font color='#5555FF'><</font>EXP<font color='#5555FF'>></font><font color='#5555FF'>&</font> dists,
std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> labels,
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> min_num_clusters,
<font color='#0000FF'><u>double</u></font> max_dist <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font>::<font color='#BB00BB'>infinity</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
<font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
requires
- dists.nr() == dists.nc()
- min_num_clusters > 0
- dists == trans(dists)
(l.e. dists should be symmetric)
ensures
- Runs a bottom up agglomerative clustering algorithm.
- Interprets dists as a matrix that gives the distances between dists.nr()
items. In particular, we take dists(i,j) to be the distance between the ith
and jth element of some set. This function clusters the elements of this set
into at least min_num_clusters (or dists.nr() if there aren't enough
elements). Additionally, within each cluster, the maximum pairwise distance
between any two cluster elements is <= max_dist.
- returns the number of clusters found.
- #labels.size() == dists.nr()
- for all valid i:
- #labels[i] == the cluster ID of the node with index i (i.e. the node
corresponding to the distances dists(i,*)).
- 0 <= #labels[i] < the number of clusters found
(i.e. cluster IDs are assigned contiguously and start at 0)
!*/</font>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<font color='#0000FF'>struct</font> <b><a name='snl_range'></a>snl_range</b>
<b>{</b>
<font color='#009900'>/*!
WHAT THIS OBJECT REPRESENTS
This object represents an interval on the real number line. It is used
to store the outputs of the segment_number_line() routine defined below.
!*/</font>
<b><a name='snl_range'></a>snl_range</b><font face='Lucida Console'>(</font>
<font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
ensures
- #lower == 0
- #upper == 0
!*/</font>
<b><a name='snl_range'></a>snl_range</b><font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> val
<font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
ensures
- #lower == val
- #upper == val
!*/</font>
<b><a name='snl_range'></a>snl_range</b><font face='Lucida Console'>(</font>
<font color='#0000FF'><u>double</u></font> l,
<font color='#0000FF'><u>double</u></font> u
<font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
requires
- l <= u
ensures
- #lower == l
- #upper == u
!*/</font>
<font color='#0000FF'><u>double</u></font> lower;
<font color='#0000FF'><u>double</u></font> upper;
<font color='#0000FF'><u>double</u></font> <b><a name='width'></a>width</b><font face='Lucida Console'>(</font>
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> upper<font color='#5555FF'>-</font>lower; <b>}</b>
<font color='#009900'>/*!
ensures
- returns the width of this interval on the number line.
!*/</font>
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b><font color='#5555FF'><</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> snl_range<font color='#5555FF'>&</font> item<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> lower <font color='#5555FF'><</font> item.lower; <b>}</b>
<font color='#009900'>/*!
ensures
- provides a total ordering of snl_range objects assuming they are
non-overlapping.
!*/</font>
<b>}</b>;
std::ostream<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'><</font><font color='#5555FF'><</font> <font face='Lucida Console'>(</font>std::ostream<font color='#5555FF'>&</font> out, <font color='#0000FF'>const</font> snl_range<font color='#5555FF'>&</font> item <font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
ensures
- prints item to out in the form [lower,upper].
!*/</font>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
std::vector<font color='#5555FF'><</font>snl_range<font color='#5555FF'>></font> <b><a name='segment_number_line'></a>segment_number_line</b> <font face='Lucida Console'>(</font>
<font color='#0000FF'>const</font> std::vector<font color='#5555FF'><</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>></font><font color='#5555FF'>&</font> x,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> max_range_width
<font face='Lucida Console'>)</font>;
<font color='#009900'>/*!
requires
- max_range_width >= 0
ensures
- Finds a clustering of the values in x and returns the ranges that define the
clustering. This routine uses a combination of bottom up clustering and a
simple greedy scan to try and find the most compact set of ranges that
contain all the values in x.
- This routine has approximately linear runtime.
- Every value in x will be contained inside one of the returned snl_range
objects;
- All returned snl_range object's will have a width() <= max_range_width and
will also be non-overlapping.
!*/</font>
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_BOTTOM_uP_CLUSTER_ABSTRACT_Hh_
</font>
</pre></body></html> |