[mlpack-svn] r11476 - mlpack/trunk/src/mlpack/core/optimizers/lrsdp
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Sun Feb 12 01:29:54 EST 2012
Author: rcurtin
Date: 2012-02-12 01:29:53 -0500 (Sun, 12 Feb 2012)
New Revision: 11476
Modified:
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp
Log:
Refactor LRSDP API for ease of usage.
Modified: mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-12 06:29:30 UTC (rev 11475)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-12 06:29:53 UTC (rev 11476)
@@ -9,6 +9,7 @@
#define __MLPACK_CORE_OPTIMIZERS_LRSDP_LRSDP_HPP
#include <mlpack/core.hpp>
+#include <mlpack/core/optimizers/aug_lagrangian/aug_lagrangian.hpp>
namespace mlpack {
namespace optimization {
@@ -16,10 +17,6 @@
class LRSDP
{
public:
- LRSDP() { }
-
- LRSDP(const arma::mat& initialPoint);
-
/**
* Create an LRSDP to be optimized. The solution will end up being a matrix
* of size (rank) x (rows). To construct each constraint and the objective
@@ -30,18 +27,28 @@
* @param rows Number of rows in the solution.
*/
LRSDP(const size_t numConstraints,
- const size_t rank,
- const size_t rows,
- const arma::mat& coordinates);
+ const arma::mat& initialPoint);
/**
+ * Create an LRSDP to be optimized, passing in an already-created
+ * AugLagrangian object. The given initial point should be set to the size
+ * (rows) x (rank), where (rank) is the reduced rank of the problem.
+ *
+ * @param numConstraints Number of constraints in the problem.
+ * @param initialPoint Initial point of the optimization.
+ * @param auglag Pre-initialized AugLagrangian<LRSDP> object.
+ */
+ LRSDP(const size_t numConstraints,
+ const arma::mat& initialPoint,
+ AugLagrangian<LRSDP>& augLagrangian);
+
+ /**
* Optimize the LRSDP and return the final objective value. The given
* coordinates will be modified to contain the final solution.
*
* @param coordinates Starting coordinates for the optimization.
*/
double Optimize(arma::mat& coordinates);
-// AugLagrangian<LRSDP> auglag);
/**
* Evaluate the objective function of the LRSDP (no constraints) at the given
@@ -95,16 +102,32 @@
//! Modify the vector of B values.
arma::vec& B() { return b; }
+ //! Return the augmented Lagrangian object.
+ const AugLagrangian<LRSDP>& AugLag() const { return augLag; }
+ //! Modify the augmented Lagrangian object.
+ AugLagrangian<LRSDP>& AugLag() { return augLag; }
+
private:
// Should probably use sparse matrices for some of these.
- arma::mat c; // For objective function.
- std::vector<arma::mat> a; // A_i for each constraint.
- arma::vec b; // b_i for each constraint.
- arma::uvec aModes; // 1 if entries in matrix, 0 for normal.
+ //! For objective function.
+ arma::mat c;
+ //! A_i for each constraint.
+ std::vector<arma::mat> a;
+ //1 b_i for each constraint.
+ arma::vec b;
- // Initial point.
+ //! 1 if entries in matrix, 0 for normal.
+ arma::uvec aModes;
+
+ //! Initial point.
arma::mat initialPoint;
+
+ //! Internal AugLagrangian object, if one was not passed at construction time.
+ AugLagrangian<LRSDP> augLagInternal;
+
+ //! The AugLagrangian object which will be used for optimization.
+ AugLagrangian<LRSDP>& augLag;
};
}; // namespace optimization
Modified: mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp 2012-02-12 06:29:30 UTC (rev 11475)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp 2012-02-12 06:29:53 UTC (rev 11476)
@@ -11,24 +11,31 @@
// In case it hasn't already been included.
#include "lrsdp.hpp"
-// Augmented Lagrangian solver.
-#include "../aug_lagrangian/aug_lagrangian.hpp"
-
namespace mlpack {
namespace optimization {
-LRSDP::LRSDP(const arma::mat& initialPoint) : initialPoint(initialPoint) { }
+LRSDP::LRSDP(const size_t numConstraints,
+ const arma::mat& initialPoint) :
+ b(numConstraints),
+ initialPoint(initialPoint),
+ augLagInternal(*this),
+ augLag(augLagInternal)
+{ }
+LRSDP::LRSDP(const size_t numConstraints,
+ const arma::mat& initialPoint,
+ AugLagrangian<LRSDP>& augLag) :
+ b(numConstraints),
+ initialPoint(initialPoint),
+ augLagInternal(*this),
+ augLag(augLag)
+{ }
+
double LRSDP::Optimize(arma::mat& coordinates)
{
- // Create the Augmented Lagrangian function.
- AugLagrangian<LRSDP> auglag(*this);
+ augLag.Sigma() = 20;
+ augLag.Optimize(coordinates, 1000);
- // A kludge for now until we have a better option to implement.
- auglag.LBFGS().MaxIterations() = 1000;
-
- auglag.Optimize(coordinates);
-
return Evaluate(coordinates);
}
More information about the mlpack-svn
mailing list