queso-0.53.0
Functions | Variables
ann_sample.cpp File Reference
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <ANN/ANN.h>
Include dependency graph for ann_sample.cpp:

Go to the source code of this file.

Functions

void getArgs (int argc, char **argv)
 
bool readPt (istream &in, ANNpoint p)
 
void printPt (ostream &out, ANNpoint p)
 
int main (int argc, char **argv)
 

Variables

int k = 1
 
int dim = 2
 
double eps = 0
 
int maxPts = 1000
 
istream * dataIn = NULL
 
istream * queryIn = NULL
 

Function Documentation

void getArgs ( int  argc,
char **  argv 
)
int main ( int  argc,
char **  argv 
)

Definition at line 78 of file ann_sample.cpp.

References annAllocPt(), annAllocPts(), annClose(), ANNkd_tree::annkSearch(), dataIn, dim, eps, getArgs(), k, maxPts, printPt(), queryIn, and readPt().

79 {
80  int nPts; // actual number of data points
81  ANNpointArray dataPts; // data points
82  ANNpoint queryPt; // query point
83  ANNidxArray nnIdx; // near neighbor indices
84  ANNdistArray dists; // near neighbor distances
85  ANNkd_tree* kdTree; // search structure
86 
87  getArgs(argc, argv); // read command-line arguments
88 
89  queryPt = annAllocPt(dim); // allocate query point
90  dataPts = annAllocPts(maxPts, dim); // allocate data points
91  nnIdx = new ANNidx[k]; // allocate near neigh indices
92  dists = new ANNdist[k]; // allocate near neighbor dists
93 
94  nPts = 0; // read data points
95 
96  cout << "Data Points:\n";
97  while (nPts < maxPts && readPt(*dataIn, dataPts[nPts])) {
98  printPt(cout, dataPts[nPts]);
99  nPts++;
100  }
101 
102  kdTree = new ANNkd_tree( // build search structure
103  dataPts, // the data points
104  nPts, // number of points
105  dim); // dimension of space
106 
107  while (readPt(*queryIn, queryPt)) { // read query points
108  cout << "Query point: "; // echo query point
109  printPt(cout, queryPt);
110 
111  kdTree->annkSearch( // search
112  queryPt, // query point
113  k, // number of near neighbors
114  nnIdx, // nearest neighbors (returned)
115  dists, // distance (returned)
116  eps); // error bound
117 
118  cout << "\tNN:\tIndex\tDistance\n";
119  for (int i = 0; i < k; i++) { // print summary
120  dists[i] = sqrt(dists[i]); // unsquare distance
121  cout << "\t" << i << "\t" << nnIdx[i] << "\t" << dists[i] << "\n";
122  }
123  }
124  delete [] nnIdx; // clean things up
125  delete [] dists;
126  delete kdTree;
127  annClose(); // done with ANN
128 
129  return EXIT_SUCCESS;
130 }
istream * dataIn
Definition: ann_sample.cpp:58
void annkSearch(ANNpoint q, int k, ANNidxArray nn_idx, ANNdistArray dd, double eps=0.0)
Definition: kd_search.cpp:89
double eps
Definition: ann_sample.cpp:55
void getArgs(int argc, char **argv)
Definition: ann2fig.cpp:146
bool readPt(istream &in, ANNpoint p)
Definition: ann_sample.cpp:61
ANNdist * ANNdistArray
Definition: ANN.h:377
DLL_API void annClose()
Definition: kd_tree.cpp:221
DLL_API ANNpoint annAllocPt(int dim, ANNcoord c=0)
Definition: ANN.cpp:110
ANNpoint * ANNpointArray
Definition: ANN.h:376
int ANNidx
Definition: ANN.h:175
void printPt(ostream &out, ANNpoint p)
Definition: ann_sample.cpp:69
ANNcoord * ANNpoint
Definition: ANN.h:375
double ANNdist
Definition: ANN.h:159
istream * queryIn
Definition: ann_sample.cpp:59
int dim
Definition: ann2fig.cpp:81
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
int k
Definition: ann_sample.cpp:53
ANNidx * ANNidxArray
Definition: ANN.h:378
int maxPts
Definition: ann_sample.cpp:56
void printPt ( ostream &  out,
ANNpoint  p 
)

Definition at line 69 of file ann_sample.cpp.

References dim.

Referenced by main().

70 {
71  out << "(" << p[0];
72  for (int i = 1; i < dim; i++) {
73  out << ", " << p[i];
74  }
75  out << ")\n";
76 }
int dim
Definition: ann2fig.cpp:81
bool readPt ( istream &  in,
ANNpoint  p 
)

Definition at line 61 of file ann_sample.cpp.

References dim.

Referenced by main().

62 {
63  for (int i = 0; i < dim; i++) {
64  if(!(in >> p[i])) return false;
65  }
66  return true;
67 }
int dim
Definition: ann2fig.cpp:81

Variable Documentation

istream* dataIn = NULL
int dim = 2

Definition at line 54 of file ann_sample.cpp.

double eps = 0

Definition at line 55 of file ann_sample.cpp.

Referenced by main().

int k = 1

Definition at line 53 of file ann_sample.cpp.

Referenced by ANNbruteForce::annkFRSearch(), ANNkd_tree::annkFRSearch(), ANNkd_tree::annkPriSearch(), ANNbruteForce::annkSearch(), ANNkd_tree::annkSearch(), annMedianSplit(), QUESO::ComputeCovCorrBetweenScalarSequences(), QUESO::ComputeCovCorrMatricesBetweenVectorRvs(), QUESO::ComputeCovCorrMatricesBetweenVectorSequences(), QUESO::ComputeSubGaussian2dKde(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_u(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_u_hat_u_asterisk(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_uw(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_w(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_w_hat_u_asterisk(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula1_for_Sigma_w_hat_w_asterisk(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula2_for_Sigma_v(), QUESO::GpmsaComputerModel< S_V, S_M, D_V, D_M, P_V, P_M, Q_V, Q_M >::fillR_formula2_for_Sigma_v_hat_v_asterisk(), QUESO::ArrayOfSequences< V, M >::gaussianKDE(), QUESO::SampledScalarCdf< T >::inverse(), QUESO::GslMatrix::largestEigen(), QUESO::GPMSAEmulator< V, M >::lnValue(), main(), QUESO::GslMatrix::mpiSum(), QUESO::operator*(), QUESO::ScalarSequence< T >::parallelMerge(), QUESO::GslMatrix::smallestEigen(), QUESO::SubF1F2Gaussian2dKdeIntegral(), QUESO::ScalarSequence< T >::subGaussian1dKde(), QUESO::ScalarSequence< T >::unifiedGaussian1dKde(), QUESO::LagrangePolynomial1D1DFunction::value(), and QUESO::LagrangeBasis1D1DFunction::value().

int maxPts = 1000

Definition at line 56 of file ann_sample.cpp.

Referenced by annMaxPtsVisit(), and main().

istream* queryIn = NULL

Definition at line 59 of file ann_sample.cpp.

Referenced by main().


Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5