[mlpack-svn] r13884 - mlpack/trunk/src/mlpack/bindings/matlab/gmm

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Nov 16 14:00:06 EST 2012


Author: rcurtin
Date: 2012-11-16 14:00:06 -0500 (Fri, 16 Nov 2012)
New Revision: 13884

Removed:
   mlpack/trunk/src/mlpack/bindings/matlab/gmm/Makefile
Modified:
   mlpack/trunk/src/mlpack/bindings/matlab/gmm/gmm.cpp
Log:
Remove unnecessary Makefile, change to appropriate headers, and add header
comment (and tabs to spaces).


Deleted: mlpack/trunk/src/mlpack/bindings/matlab/gmm/Makefile
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/gmm/Makefile	2012-11-16 18:58:31 UTC (rev 13883)
+++ mlpack/trunk/src/mlpack/bindings/matlab/gmm/Makefile	2012-11-16 19:00:06 UTC (rev 13884)
@@ -1,22 +0,0 @@
-gmm: gmm.o
-	g++ -O -pthread -shared  \
--Wl,--version-script,/opt/matlab/2010b/extern/lib/glnxa64/mexFunction.map \
--Wl,--no-undefined -o 'mex_gmm.mexa64' gmm.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 \
--L/usr/lib64 -larmadillo \
-
-gmm.o:
-	g++ -c  \
--I../../build/include \
--I../../build/include/mlpack/methods/gmm \
--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 'gmm.cpp'
-
-clean:
-	rm -f *.o *.mexa64

Modified: mlpack/trunk/src/mlpack/bindings/matlab/gmm/gmm.cpp
===================================================================
--- mlpack/trunk/src/mlpack/bindings/matlab/gmm/gmm.cpp	2012-11-16 18:58:31 UTC (rev 13883)
+++ mlpack/trunk/src/mlpack/bindings/matlab/gmm/gmm.cpp	2012-11-16 19:00:06 UTC (rev 13884)
@@ -1,27 +1,33 @@
+/**
+ * @file gmm.cpp
+ * @author Patrick Mason
+ *
+ * MEX function for MATLAB GMM binding.
+ */
 #include "mex.h"
 
-#include "gmm.hpp"
-#include <iostream>
+#include <mlpack/core.hpp>
+#include <mlpack/methods/gmm/gmm.hpp>
 
 using namespace mlpack;
 using namespace mlpack::gmm;
-using namespace mlpack::utilities;
+using namespace mlpack::util;
 
 void mexFunction(int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
 {
   // argument checks
-  if (nrhs != 3) 
+  if (nrhs != 3)
   {
     mexErrMsgTxt("Expecting three inputs.");
   }
 
-  if (nlhs != 1) 
+  if (nlhs != 1)
   {
     mexErrMsgTxt("Output required.");
   }
 
-	size_t seed = (size_t) mxGetScalar(prhs[2]);
+  size_t seed = (size_t) mxGetScalar(prhs[2]);
   // Check parameters and load data.
   if (seed != 0)
     math::RandomSeed(seed);
@@ -33,15 +39,15 @@
   size_t numPoints = mxGetN(prhs[0]);
   size_t numDimensions = mxGetM(prhs[0]);
   arma::mat dataPoints(numDimensions, numPoints);
-  for (int i = 0, n = numPoints * numDimensions; i < n; ++i) 
+  for (int i = 0, n = numPoints * numDimensions; i < n; ++i)
   {
     dataPoints(i) = mexDataPoints[i];
   }
 
-	int gaussians = (int) mxGetScalar(prhs[1]);
+  int gaussians = (int) mxGetScalar(prhs[1]);
   if (gaussians <= 0)
   {
-		std::stringstream ss;
+    std::stringstream ss;
     ss << "Invalid number of Gaussians (" << gaussians << "); must "
         "be greater than or equal to 1." << std::endl;
     mexErrMsgTxt(ss.str().c_str());
@@ -66,58 +72,58 @@
 
   plhs[0] =  mxCreateStructArray(ndim, dims, 3, fieldNames);
 
-	// dimensionality
+  // dimensionality
   mxArray * field_value;
-	field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
-	*mxGetPr(field_value) = numDimensions;
+  field_value = mxCreateDoubleMatrix(1, 1, mxREAL);
+  *mxGetPr(field_value) = numDimensions;
   mxSetFieldByNumber(plhs[0], 0, 0, field_value);
 
-	// mixture weights
-	field_value = mxCreateDoubleMatrix(gmm.Weights().size(), 1, mxREAL);
-	double * values = mxGetPr(field_value);
-	for (int i=0; i<gmm.Weights().size(); ++i)
-	{
-		values[i] = gmm.Weights()[i];
-	}
+  // mixture weights
+  field_value = mxCreateDoubleMatrix(gmm.Weights().size(), 1, mxREAL);
+  double * values = mxGetPr(field_value);
+  for (int i=0; i<gmm.Weights().size(); ++i)
+  {
+    values[i] = gmm.Weights()[i];
+  }
   mxSetFieldByNumber(plhs[0], 0, 1, field_value);
-  
-	// gaussian mean/variances
-	const char * gaussianNames[2] = {
+
+  // gaussian mean/variances
+  const char * gaussianNames[2] = {
     "mean"
     , "covariance"
   };
-	ndim = 1;
+  ndim = 1;
   dims[0] = gmm.Gaussians();
 
-	field_value = mxCreateStructArray(ndim, dims, 2, gaussianNames);
-	for (int i=0; i<gmm.Gaussians(); ++i)
-	{
-		mxArray * tmp;
-		double * values;
-	
-		// setting the mean
-		arma::mat mean = gmm.Means()[i];
-		tmp = mxCreateDoubleMatrix(numDimensions, 1, mxREAL);
-		values = mxGetPr(tmp);
-		for (int j = 0; j < numDimensions; ++j)
-		{
-			values[j] = mean(j);
-		}
-		// note: SetField does not copy the data structure.
-		// mxDuplicateArray does the necessary copying.
-		mxSetFieldByNumber(field_value, i, 0, mxDuplicateArray(tmp));
-		mxDestroyArray(tmp);
+  field_value = mxCreateStructArray(ndim, dims, 2, gaussianNames);
+  for (int i=0; i<gmm.Gaussians(); ++i)
+  {
+    mxArray * tmp;
+    double * values;
 
-		// setting the covariance matrix
-		arma::mat covariance = gmm.Covariances()[i];
-		tmp = mxCreateDoubleMatrix(numDimensions, numDimensions, mxREAL);
-		values = mxGetPr(tmp);
-		for (int j = 0; j < numDimensions * numDimensions; ++j)
-		{
-			values[j] = covariance(j);
-		}
-		mxSetFieldByNumber(field_value, i, 1, mxDuplicateArray(tmp));
-		mxDestroyArray(tmp);
-	}
-	mxSetFieldByNumber(plhs[0], 0, 2, field_value);
+    // setting the mean
+    arma::mat mean = gmm.Means()[i];
+    tmp = mxCreateDoubleMatrix(numDimensions, 1, mxREAL);
+    values = mxGetPr(tmp);
+    for (int j = 0; j < numDimensions; ++j)
+    {
+      values[j] = mean(j);
+    }
+    // note: SetField does not copy the data structure.
+    // mxDuplicateArray does the necessary copying.
+    mxSetFieldByNumber(field_value, i, 0, mxDuplicateArray(tmp));
+    mxDestroyArray(tmp);
+
+    // setting the covariance matrix
+    arma::mat covariance = gmm.Covariances()[i];
+    tmp = mxCreateDoubleMatrix(numDimensions, numDimensions, mxREAL);
+    values = mxGetPr(tmp);
+    for (int j = 0; j < numDimensions * numDimensions; ++j)
+    {
+      values[j] = covariance(j);
+    }
+    mxSetFieldByNumber(field_value, i, 1, mxDuplicateArray(tmp));
+    mxDestroyArray(tmp);
+  }
+  mxSetFieldByNumber(plhs[0], 0, 2, field_value);
 }




More information about the mlpack-svn mailing list