fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Dec 9 01:02:52 EST 2011

Author: niche
Date: 2011-12-09 01:02:52 -0500 (Fri, 09 Dec 2011)
New Revision: 10677

Modified:
Log:
made some speed optimizations via manual profiling

===================================================================
@@ -46,39 +46,50 @@
vec v = sort(z);
size_t nPoints = v.n_elem;
+
+  // Apparently slower
+  /*
vec logs = log(v.subvec(m, nPoints - 1) - v.subvec(0, nPoints - 1 - m));
+  //vec val = sum(log(v.subvec(m, nPoints - 1) - v.subvec(0, nPoints - 1 - m)));
return (double) sum(logs);
+  */
+
+  // Apparently faster
+  double sum = 0;
+  u32 range = nPoints - m;
+  for(u32 i = 0; i < range; i++) {
+    sum += log(v(i+m) - v(i));
+  }
+  return sum;
}

mat matXMod;
+
CopyAndPerturb(matXMod, matX);
-
-  double theta;
-  double value;
+
mat matJacobi(2,2);
mat candidateY;

-  double thetaOpt = 0;
-  double valueOpt = 1e99;
+  double theta;
+  vec thetas = linspace<vec>(0, nAngles - 1, nAngles) / ((double) nAngles) * math::pi() / 2;
+  vec values(nAngles);

for(size_t i = 0; i < nAngles; i++) {
-    theta = ((double) i) / ((double) nAngles) * math::pi() / 2;
+    theta = thetas(i);
matJacobi(0,0) = cos(theta);
matJacobi(0,1) = sin(theta);
matJacobi(1,0) = -sin(theta);
matJacobi(1,1) = cos(theta);

candidateY = matXMod * matJacobi;
-    value = Vasicek(candidateY.col(0)) + Vasicek(candidateY.col(1));
-    if(value < valueOpt) {
-      valueOpt = value;
-      thetaOpt = theta;
-    }
+    values(i) = Vasicek(candidateY.col(0)) + Vasicek(candidateY.col(1));
}

-  return thetaOpt;
+  u32 indOpt;
+  double valueOpt = values.min(indOpt);
+  return thetas(indOpt);
}

@@ -90,6 +101,7 @@
// two-dimensional coordinate projections for Radical2D
mat matX = trans(matXT);

+
// if m was not specified, initialize m as recommended in
// (Learned-Miller and Fisher, 2003)
if(m < 1) {
@@ -103,7 +115,7 @@
mat matXWhitened;
mat matWhitening;
WhitenFeatureMajorMatrix(matX, matXWhitened, matWhitening);
-
+
// in the RADICAL code, they do not copy and perturb initially, although the
// paper does. we follow the code as it should match their reported results
// and likely does a better job bouncing out of local optima

===================================================================
@@ -131,11 +131,11 @@
};

-  void WhitenFeatureMajorMatrix(const arma::mat& matX,
-				arma::mat& matXWhitened,
-				arma::mat& matWhitening);
-

+void WhitenFeatureMajorMatrix(const arma::mat& matX,
+			      arma::mat& matXWhitened,
+			      arma::mat& matWhitening);
+
}; // namespace mlpack

===================================================================
@@ -10,7 +10,30 @@
using namespace std;
using namespace arma;

+/*
+void test() {
+  mat X;
+
+  mat Y;
+  mat W;
+
+  //wall_clock timer;
+  //timer.tic();
+  //double n_secs = timer.toc();
+  //cout << "took " << n_secs << " seconds" << endl;
+
+
+}
+*/
+
int main(int argc, char* argv[]) {
+  //test();
+
+  //return 1;
+
size_t nPoints = 1000;
size_t nDims = 2;

@@ -33,9 +56,7 @@

mat Y;
mat W;