[mlpack-git] master: Inline alphahat into alpha (4501dea)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Mon Feb 2 15:16:49 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/bb6e5c56aab07e6449d86021246b52a9e323f3a0...bd6cb33f8d8270b02a84e81e38727679bb6c319a

>---------------------------------------------------------------

commit 4501deab874b268aedd313dfdcb4d6898fb03c4d
Author: Stephen Tu <tu.stephenl at gmail.com>
Date:   Wed Jan 28 18:34:03 2015 -0800

    Inline alphahat into alpha


>---------------------------------------------------------------

4501deab874b268aedd313dfdcb4d6898fb03c4d
 .../core/optimizers/sdp/primal_dual_impl.hpp       | 35 ++++++++++++----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/mlpack/core/optimizers/sdp/primal_dual_impl.hpp b/src/mlpack/core/optimizers/sdp/primal_dual_impl.hpp
index 98eca00..58c0a83 100644
--- a/src/mlpack/core/optimizers/sdp/primal_dual_impl.hpp
+++ b/src/mlpack/core/optimizers/sdp/primal_dual_impl.hpp
@@ -92,27 +92,32 @@ PrimalDualSolver<SDPType>::PrimalDualSolver(const SDPType& sdp,
 }
 
 /**
- * alphahat = sup{ alphahat : A + dA is psd }
+ * Compute
+ *
+ *     alpha = min(1, tau * alphahat(A, dA))
+ *
+ * where
+ *
+ *     alphahat = sup{ alphahat : A + dA is psd }
+ *
+ * See (2.18) of [AHO98] for more details.
  */
 static inline double
-AlphaHat(const arma::mat& A, const arma::mat& dA)
+Alpha(const arma::mat& A, const arma::mat& dA, double tau)
 {
-  // note: arma::chol(A) returns an upper triangular matrix (instead of the
-  // usual lower triangular)
-  const arma::mat L = arma::chol(A).t();
+  // On Armadillo < 4.500, the "lower" option isn't available.
+#if (ARMA_VERSION_MAJOR < 4) || \
+    ((ARMA_VERSION_MAJOR == 4) && (ARMA_VERSION_MINOR < 500))
+  const arma::mat L = arma::chol(A).t(); // This is less efficient.
+#else
+  const arma::mat L = arma::chol(A, "lower");
+#endif
   const arma::mat Linv = arma::inv(arma::trimatl(L));
+  // TODO(stephentu): We only want the top eigenvalue, we should
+  // be able to do better than full eigen-decomposition.
   const arma::vec evals = arma::eig_sym(-Linv * dA * Linv.t());
   const double alphahatinv = evals(evals.n_elem - 1);
-  return 1. / alphahatinv;
-}
-
-/**
- * alpha = min(1, tau * alphahat(A, dA))
- */
-static inline double
-Alpha(const arma::mat& A, const arma::mat& dA, double tau)
-{
-  double alphahat = AlphaHat(A, dA);
+  double alphahat = 1. / alphahatinv;
   if (alphahat < 0.)
     // dA is PSD already
     alphahat = 1.;



More information about the mlpack-git mailing list