LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
lsst::ap::cluster::detail::Optics< K, RecordT > Class Template Reference

#include <Optics.h>

Public Member Functions

 Optics (Point< K, boost::shared_ptr< RecordT > > *points, int numPoints, int minNeighbors, double epsilon, double leafExtentThreshold, int pointsPerLeaf)
 
 ~Optics ()
 
template<typename MetricT >
void run (boost::shared_ptr< typename RecordT::Table > table, std::vector< typename RecordT::Catalog > &clusters, MetricT const &metric)
 

Private Types

typedef boost::shared_ptr
< RecordT > 
DataT
 

Private Member Functions

template<typename MetricT >
void expandClusterOrder (int i, MetricT const &metric)
 

Private Attributes

Point< K, DataT > * _points
 
boost::scoped_ptr< KDTree< K,
DataT > > 
_tree
 
boost::scoped_ptr< SeedList< K,
DataT > > 
_seeds
 
boost::scoped_array< double > _distances
 
double _epsilon
 
int _numPoints
 
int _minNeighbors
 
bool _ran
 
lsst::pex::logging::Log _log
 

Detailed Description

template<int K, typename RecordT>
class lsst::ap::cluster::detail::Optics< K, RecordT >

Definition at line 60 of file Optics.h.

Member Typedef Documentation

template<int K, typename RecordT >
typedef boost::shared_ptr<RecordT> lsst::ap::cluster::detail::Optics< K, RecordT >::DataT
private

Definition at line 76 of file Optics.h.

Constructor & Destructor Documentation

template<int K, typename RecordT >
lsst::ap::cluster::detail::Optics< K, RecordT >::Optics ( Point< K, boost::shared_ptr< RecordT > > *  points,
int  numPoints,
int  minNeighbors,
double  epsilon,
double  leafExtentThreshold,
int  pointsPerLeaf 
)

Initializes data structures required by the OPTICS to run over the given set of points.

Definition at line 52 of file Optics.cc.

57  :
58  _points(points),
59  _tree(),
60  _seeds(),
61  _distances(),
62  _epsilon(epsilon),
63  _numPoints(numPoints),
64  _minNeighbors(minNeighbors),
65  _ran(false),
66  _log(lsst::pex::logging::Log::getDefaultLog(), "lsst.ap.cluster.detail")
67 {
68  if (_points == 0) {
69  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
70  "Input point array is null");
71  }
72  if (_numPoints <= 0) {
73  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
74  "Number of input points must be at least 1");
75  }
76  if (_minNeighbors < 0) {
77  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
78  "OPTICS minNeighbors parameter value is negative");
79  }
80  if (_epsilon < 0.0) {
81  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
82  "OPTICS epsilon parameter value is negative");
83  }
84  if (pointsPerLeaf <= 0) {
85  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
86  "K-D tree pointsPerLeaf parameter must be positive");
87  }
88 
89  _log.log(lsst::pex::logging::Log::INFO, "Building k-d tree for sources");
90  boost::scoped_ptr<KDTree<K, DataT> > tree(new KDTree<K, DataT>(
91  points, numPoints, pointsPerLeaf, leafExtentThreshold));
93  "Created k-d tree for %d sources", numPoints);
94 
95  boost::scoped_ptr<SeedList<K, DataT> > seeds(new SeedList<K, DataT>(
96  points, numPoints));
97  boost::scoped_array<double> distances(new double[_minNeighbors]);
98  using std::swap;
99  swap(_tree, tree);
100  swap(_seeds, seeds);
101  swap(_distances, distances);
102 }
void swap(Ellipse< DataT > &a, Ellipse< DataT > &b)
Definition: EllipseTypes.h:90
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:287
void format(int importance, const char *fmt,...)
lsst::pex::logging::Log _log
Definition: Optics.h:86
void log(int importance, const std::string &message, const lsst::daf::base::PropertySet &properties)
static Log & getDefaultLog()
boost::scoped_array< double > _distances
Definition: Optics.h:81
static const int INFO
Definition: Log.h:171
boost::scoped_ptr< KDTree< K, DataT > > _tree
Definition: Optics.h:79
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
boost::scoped_ptr< SeedList< K, DataT > > _seeds
Definition: Optics.h:80
Point< K, DataT > * _points
Definition: Optics.h:78
template<int K, typename RecordT >
lsst::ap::cluster::detail::Optics< K, RecordT >::~Optics ( )

Definition at line 105 of file Optics.cc.

105 { }

Member Function Documentation

template<int K, typename RecordT >
template<typename MetricT >
void lsst::ap::cluster::detail::Optics< K, RecordT >::expandClusterOrder ( int  i,
MetricT const &  metric 
)
private

Definition at line 163 of file Optics.cc.

164 {
165  // find epsilon neighborhood of point i
166  int range = _tree->inRange(_points[i].coords, _epsilon, metric);
167  // compute core-distance
168  int n = 0;
169  int j = range;
170  while (j != -1) {
171  Point<K, DataT> * p = _points + j;
172  if (j != i) {
173  double d = p->dist;
174  if (n < _minNeighbors) {
175  _distances[n++] = d;
176  std::push_heap(_distances.get(), _distances.get() + n);
177  } else if (_distances[0] > d) {
178  std::pop_heap(_distances.get(), _distances.get() + n);
179  _distances[n - 1] = d;
180  std::push_heap(_distances.get(), _distances.get() + n);
181  }
182  }
183  j = p->next;
184  }
185  if (n == _minNeighbors) {
186  // point i is a core-object. Update reachability-distance of all
187  // points in the epsilon-neighborhood of point i.
188  double coreDist = _distances[0];
189  j = range;
190  while (j != -1) {
191  Point<K, DataT> * p = _points + j;
192  if (p->state != Point<K, DataT>::PROCESSED) {
193  _seeds->update(j, std::max(coreDist, p->dist));
194  }
195  j = p->next;
196  }
197  }
198 }
int d
Definition: KDTree.cc:89
boost::scoped_array< double > _distances
Definition: Optics.h:81
double max
Definition: attributes.cc:218
boost::scoped_ptr< KDTree< K, DataT > > _tree
Definition: Optics.h:79
boost::scoped_ptr< SeedList< K, DataT > > _seeds
Definition: Optics.h:80
Point< K, DataT > * _points
Definition: Optics.h:78
template<int K, typename RecordT >
template<typename MetricT >
void lsst::ap::cluster::detail::Optics< K, RecordT >::run ( boost::shared_ptr< typename RecordT::Table >  table,
std::vector< typename RecordT::Catalog > &  clusters,
MetricT const &  metric 
)

Runs the OPTICS algorithm, appending clusters to clusters. This method may only be called once for a given Optics instance.

Definition at line 112 of file Optics.cc.

115 {
116  if (_ran) {
117  throw LSST_EXCEPT(lsst::pex::exceptions::LogicError,
118  "OPTICS has already been run");
119  }
120  typename RecordT::Catalog cluster(table);
121  size_t const s = clusters.size();
122  int scanFrom = 0;
123 
124  _log.log(lsst::pex::logging::Log::INFO, "Clustering sources using OPTICS");
125  _ran = true;
126 
127  while (true) {
128  int i;
129  if (_seeds->empty()) {
130  // find next unprocessed point
131  for (i = scanFrom; i < _numPoints; ++i) {
132  if (_points[i].state == Point<K, DataT>::UNPROCESSED) {
133  scanFrom = i + 1;
134  break;
135  }
136  }
137  if (i == _numPoints) {
138  break;
139  }
140  _points[i].state = Point<K, DataT>::PROCESSED;
141  expandClusterOrder(i, metric);
142  if (cluster.size() > 0) {
143  // clusters of size 1 are generated for noise sources
144  clusters.push_back(cluster);
145  cluster.clear();
146  }
147  cluster.push_back(_points[i].data);
148  } else {
149  // expand cluster around seed with smallest reachability-distance
150  i = _seeds->pop();
151  expandClusterOrder(i, metric);
152  assert(_points[i].reach != std::numeric_limits<double>::infinity());
153  cluster.push_back(_points[i].data);
154  }
155  }
156  clusters.push_back(cluster);
157  _log.format(lsst::pex::logging::Log::INFO, "Produced %d clusters",
158  static_cast<int>(clusters.size() - s));
159 }
std::vector< SourceCatalog > const cluster(SourceCatalog const &sources, ClusteringControl const &control)
Definition: clustering.cc:578
void format(int importance, const char *fmt,...)
lsst::pex::logging::Log _log
Definition: Optics.h:86
void log(int importance, const std::string &message, const lsst::daf::base::PropertySet &properties)
static const int INFO
Definition: Log.h:171
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
void expandClusterOrder(int i, MetricT const &metric)
Definition: Optics.cc:163
boost::scoped_ptr< SeedList< K, DataT > > _seeds
Definition: Optics.h:80
Point< K, DataT > * _points
Definition: Optics.h:78

Member Data Documentation

template<int K, typename RecordT >
boost::scoped_array<double> lsst::ap::cluster::detail::Optics< K, RecordT >::_distances
private

Definition at line 81 of file Optics.h.

template<int K, typename RecordT >
double lsst::ap::cluster::detail::Optics< K, RecordT >::_epsilon
private

Definition at line 82 of file Optics.h.

template<int K, typename RecordT >
lsst::pex::logging::Log lsst::ap::cluster::detail::Optics< K, RecordT >::_log
private

Definition at line 86 of file Optics.h.

template<int K, typename RecordT >
int lsst::ap::cluster::detail::Optics< K, RecordT >::_minNeighbors
private

Definition at line 84 of file Optics.h.

template<int K, typename RecordT >
int lsst::ap::cluster::detail::Optics< K, RecordT >::_numPoints
private

Definition at line 83 of file Optics.h.

template<int K, typename RecordT >
Point<K, DataT>* lsst::ap::cluster::detail::Optics< K, RecordT >::_points
private

Definition at line 78 of file Optics.h.

template<int K, typename RecordT >
bool lsst::ap::cluster::detail::Optics< K, RecordT >::_ran
private

Definition at line 85 of file Optics.h.

template<int K, typename RecordT >
boost::scoped_ptr<SeedList<K, DataT> > lsst::ap::cluster::detail::Optics< K, RecordT >::_seeds
private

Definition at line 80 of file Optics.h.

template<int K, typename RecordT >
boost::scoped_ptr<KDTree<K, DataT> > lsst::ap::cluster::detail::Optics< K, RecordT >::_tree
private

Definition at line 79 of file Optics.h.


The documentation for this class was generated from the following files: