[mlpack-svn] r13879 - mlpack/trunk/src/mlpack/bindings/matlab/allkfn

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Nov 16 13:25:02 EST 2012


Author: rcurtin
Date: 2012-11-16 13:25:01 -0500 (Fri, 16 Nov 2012)
New Revision: 13879

Removed:
   mlpack/trunk/src/mlpack/bindings/matlab/allkfn/Makefile
   mlpack/trunk/src/mlpack/bindings/matlab/allkfn/test.m
Modified:
   mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.cpp
   mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.m
Log:
Update AllkFN binding documentation to how it should eventually be.


Deleted: mlpack/trunk/src/mlpack/bindings/matlab/allkfn/Makefile
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/allkfn/Makefile	2012-11-16 18:17:03 UTC (rev 13878)
+++ mlpack/trunk/src/mlpack/bindings/matlab/allkfn/Makefile	2012-11-16 18:25:01 UTC (rev 13879)
@@ -1,18 +0,0 @@
-allkfn: allkfn.o
-	g++ -O -pthread -shared  \
--Wl,--version-script,/opt/matlab/2010b/extern/lib/glnxa64/mexFunction.map \
--Wl,--no-undefined -o 'mex_allkfn.mexa64' allkfn.o \
--L../../../build/lib -lmlpack \
--Wl,-rpath-link,/opt/matlab/2010b/bin/glnxa64 \
--L/opt/matlab/2010b/bin/glnxa64 -lmx -lmex -lmat -lm \
--Wl,-rpath=/net/hu19/pmason8/mlpack/trunk/build/lib \
-
-allkfn.o:
-	g++ -c  \
--I../../../build/include \
--I../../../build/include/mlpack/methods/neighbor_search \
--I/usr/include/libxml2 \
--I/opt/matlab/2010b/extern/include \
--DMATLAB_MEX_FILE \
--ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread \
--DMX_COMPAT_32 -O -DNDEBUG 'allkfn.cpp' \

Modified: mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.cpp
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.cpp	2012-11-16 18:17:03 UTC (rev 13878)
+++ mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.cpp	2012-11-16 18:25:01 UTC (rev 13879)
@@ -1,3 +1,9 @@
+/**
+ * @file allkfn.cpp
+ * @author Patrick Mason
+ *
+ * MEX function for MATLAB All-kFN binding.
+ */
 #include "mex.h"
 
 #include <mlpack/core.hpp>
@@ -13,83 +19,28 @@
 using namespace mlpack::neighbor;
 using namespace mlpack::tree;
 
-/*
-// Information about the program itself.
-PROGRAM_INFO("All K-Furthest-Neighbors",
-    "This program will calculate the all k-furthest-neighbors of a set of "
-    "points. You may specify a separate set of reference points and query "
-    "points, or just a reference set which will be used as both the reference "
-    "and query set."
-    "\n\n"
-    "For example, the following will calculate the 5 furthest neighbors of each"
-    "point in 'input.csv' and store the distances in 'distances.csv' and the "
-    "neighbors in the file 'neighbors.csv':"
-    "\n\n"
-    "$ allkfn --k=5 --reference_file=input.csv --distances_file=distances.csv\n"
-    "  --neighbors_file=neighbors.csv"
-    "\n\n"
-    "The output files are organized such that row i and column j in the "
-    "neighbors output file corresponds to the index of the point in the "
-    "reference set which is the i'th furthest neighbor from the point in the "
-    "query set with index j.  Row i and column j in the distances output file "
-    "corresponds to the distance between those two points.");
-
-// Define our input parameters that this program will take.
-PARAM_STRING_REQ("reference_file", "File containing the reference dataset.",
-    "r");
-PARAM_INT_REQ("k", "Number of furthest neighbors to find.", "k");
-PARAM_STRING_REQ("distances_file", "File to output distances into.", "d");
-PARAM_STRING_REQ("neighbors_file", "File to output neighbors into.", "n");
-
-PARAM_STRING("query_file", "File containing query points (optional).", "q", "");
-
-PARAM_INT("leaf_size", "Leaf size for tree building.", "l", 20);
-PARAM_FLAG("naive", "If true, O(n^2) naive mode is used for computation.", "N");
-PARAM_FLAG("single_mode", "If true, single-tree search is used (as opposed to "
-    "dual-tree search.", "s");
-*/
-
 void mexFunction(int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
 {
-  // checking inputs
-	if (nrhs != 6) 
+  // Check the inputs.
+  if (nrhs != 6)
   {
     mexErrMsgTxt("Expecting seven arguments.");
   }
 
-  if (nlhs != 2) 
+  if (nlhs != 2)
   {
     mexErrMsgTxt("Two outputs required.");
   }
 
-	/*
-  // Give CLI the command line parameters the user passed in.
-  CLI::ParseCommandLine(argc, argv);
-
-  // Get all the parameters.
-  string referenceFile = CLI::GetParam<string>("reference_file");
-
-  string distancesFile = CLI::GetParam<string>("distances_file");
-  string neighborsFile = CLI::GetParam<string>("neighbors_file");
-
-  int lsInt = CLI::GetParam<int>("leaf_size");
-
-  size_t k = CLI::GetParam<int>("k");
-
-  bool naive = CLI::HasParam("naive");
-  bool singleMode = CLI::HasParam("single_mode");
-	*/
-
-	// getting the dimensions of the reference matrix
   size_t numPoints = mxGetN(prhs[0]);
   size_t numDimensions = mxGetM(prhs[0]);
 
-	// feeding the referenceData matrix
+  // Create the reference matrix.
 	arma::mat referenceData(numDimensions, numPoints);
-	// setting the values. 
+	// setting the values.
   double * mexDataPoints = mxGetPr(prhs[0]);
-  for (int i = 0, n = numPoints * numDimensions; i < n; ++i) 
+  for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
   {
     referenceData(i) = mexDataPoints[i];
   }
@@ -105,11 +56,11 @@
 
 	// single mode?
 	bool singleMode = (mxGetScalar(prhs[5]) == 1.0);
-	
+
 	// the query matrix
 	double * mexQueryPoints = mxGetPr(prhs[2]);
-	arma::mat queryData; 
-	bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0)); 
+	arma::mat queryData;
+	bool hasQueryData = ((mxGetM(prhs[2]) != 0) && (mxGetN(prhs[2]) != 0));
 
   //arma::mat referenceData;
   //arma::mat queryData; // So it doesn't go out of scope.
@@ -164,12 +115,12 @@
   //f (CLI::GetParam<string>("query_file") != "")
 	if (hasQueryData)
   {
-		// setting the values. 
+		// setting the values.
   	mexDataPoints = mxGetPr(prhs[2]);
   	numPoints = mxGetN(prhs[2]);
   	numDimensions = mxGetM(prhs[2]);
 		queryData = arma::mat(numDimensions, numPoints);
-  	for (int i = 0, n = numPoints * numDimensions; i < n; ++i) 
+  	for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
   	{
    		queryData(i) = mexDataPoints[i];
   	}
@@ -239,12 +190,12 @@
 
   // setting the values
   double * out = mxGetPr(plhs[0]);
-  for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i) 
+  for (int i = 0, n = distances.n_rows * distances.n_cols; i < n; ++i)
   {
     out[i] = distances(i);
   }
   out = mxGetPr(plhs[1]);
-  for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i) 
+  for (int i = 0, n = neighbors.n_rows * neighbors.n_cols; i < n; ++i)
   {
     out[i] = neighbors(i);
   }

Modified: mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.m
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.m	2012-11-16 18:17:03 UTC (rev 13878)
+++ mlpack/trunk/src/mlpack/bindings/matlab/allkfn/allkfn.m	2012-11-16 18:25:01 UTC (rev 13879)
@@ -1,24 +1,39 @@
-function [distances neighbors] = allkfn(dataPoints, k, varargin)
-%All K-Furthest-Neighbors
+function [distances, neighbors] = allkfn(dataPoints, k, varargin)
+% [distances, neighbors] = allkfn(dataPoints, k, varargin)
 %
-%  This program will calculate the all k-furthest-neighbors of a set of points.
-%  You may specify a separate set of reference points and query points, or just a
-%  reference set which will be used as both the reference and query set.
-%  
-%  For example, the following will calculate the 5 furthest neighbors of
-%  eachpoint in 'input.csv' and store the distances in 'distances.csv' and the
-%  neighbors in the file 'neighbors.csv':
-%  
-%  $ allkfn --k=5 --reference_file=input.csv --distances_file=distances.csv
-%    --neighbors_file=neighbors.csv
-%  
-%  The output files are organized such that row i and column j in the neighbors
-%  output file corresponds to the index of the point in the reference set which
-%  is the i'th furthest neighbor from the point in the query set with index j. 
-%  Row i and column j in the distances output file corresponds to the distance
-%  between those two points.
+% Calculate the all k-furthest-neighbors of a set of points.  You may specify a
+% separate set of reference points and query points, or just a reference set
+% which will be used as both the reference and query set.
+%
+% The output matrices are organized such that row i and column j in the
+% neighbors matrix corresponds to the index of the point in the reference set
+% which is the i'th furthest neighbor from the point in the query set with index
+% j.  Row i and column j in the distances output matrix corresponds to the
+% distance between those two points.
+%
+% Parameters:
+%
+% dataPoints - The reference set of data points.  Columns are assumed to
+%              represent dimensions, with rows representing separate points.
+% k          - The number of furthest neighbors to find.
+%
+% Optional parameters (i.e. allkfn(..., 'parameter', value, ...)):
+%
+% 'queryPoints' - An optional set of query points, if the reference and query
+%                 sets are different.  Columns are assumed to represent
+%                 dimensions, with rows representing separate points.
+% 'leafSize'    - Leaf size in the kd-tree.  Defaults to 20.
+% 'method'      - Algorithm to use.  'naive' uses naive O(n^2) computation;
+%                 'single' uses single-tree traversal; 'dual' uses the standard
+%                 dual-tree traversal.  Defaults to 'dual'.
+%
+% Examples:
+%
+% [distances, neighbors] = allkfn(dataPoints, 5);
+% [distances, neighbors] = allkfn(dataPoints, 5, 'method', 'single');
+% [distances, neighbors] = allkfn(dataPoints, 5, 'queryPoints', queryPoints);
 
-% a parser for the inputs
+% A parser for the inputs.
 p = inputParser;
 p.addParamValue('queryPoints', zeros(0), @ismatrix);
 p.addParamValue('leafSize', 20, @isscalar);

Deleted: mlpack/trunk/src/mlpack/bindings/matlab/allkfn/test.m
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/allkfn/test.m	2012-11-16 18:17:03 UTC (rev 13878)
+++ mlpack/trunk/src/mlpack/bindings/matlab/allkfn/test.m	2012-11-16 18:25:01 UTC (rev 13879)
@@ -1,7 +0,0 @@
-dataPoints = [0, 0; 1, 1; 3, 3; 0.5, 0; 1000, 0; 1001, 0];
-queryPoints = [2,4; 7, 11];
-k=2;
-
-% running the emst computation with mlpack
-[distances neighbors] = allkfn(dataPoints, k, 'leafSize', 10)
-




More information about the mlpack-svn mailing list