[mlpack-git] master: Inline alphahat into alpha (b29b5ae)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:14:34 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit b29b5aef77aebc15241eae0ea172a7534eac1bfd
Author: Stephen Tu <tu.stephenl at gmail.com>
Date: Wed Jan 28 18:34:03 2015 -0800
Inline alphahat into alpha
>---------------------------------------------------------------
b29b5aef77aebc15241eae0ea172a7534eac1bfd
.../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