[mlpack-svn] r11419 - mlpack/trunk/src/mlpack/core/optimizers/lrsdp
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Feb 7 00:56:20 EST 2012
Author: rcurtin
Date: 2012-02-07 00:56:20 -0500 (Tue, 07 Feb 2012)
New Revision: 11419
Modified:
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp
Log:
Allow two modes of constraint matrices. Not yet documented.
Modified: mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-06 23:58:58 UTC (rev 11418)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-07 05:56:20 UTC (rev 11419)
@@ -18,6 +18,8 @@
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
@@ -29,7 +31,8 @@
*/
LRSDP(const size_t numConstraints,
const size_t rank,
- const size_t rows);
+ const size_t rows,
+ const arma::mat& coordinates);
/**
* Optimize the LRSDP and return the final objective value. The given
@@ -78,10 +81,15 @@
arma::mat& C() { return c; }
//! Return the vector of A matrices (which correspond to the constraints).
- const std::vector<arma::mat> A() const { return a; }
+ const std::vector<arma::mat>& A() const { return a; }
//! Modify the veector of A matrices (which correspond to the constraints).
std::vector<arma::mat>& A() { return a; }
+ //! Return the vector of modes for the A matrices.
+ const arma::uvec& AModes() const { return aModes; }
+ //! Modify the vector of modes for the A matrices.
+ arma::uvec& AModes() { return aModes; }
+
//! Return the vector of B values.
const arma::vec& B() const { return b; }
//! Modify the vector of B values.
@@ -93,6 +101,8 @@
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.
+
// Initial point.
arma::mat initialPoint;
};
Modified: mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp 2012-02-06 23:58:58 UTC (rev 11418)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp 2012-02-07 05:56:20 UTC (rev 11419)
@@ -17,6 +17,8 @@
namespace mlpack {
namespace optimization {
+LRSDP::LRSDP(const arma::mat& initialPoint) : initialPoint(initialPoint) { }
+
double LRSDP::Optimize(arma::mat& coordinates)
{
// Create the Augmented Lagrangian function.
@@ -41,7 +43,17 @@
double LRSDP::EvaluateConstraint(const size_t index,
const arma::mat& coordinates) const
{
- return trace(a[index] * (coordinates * trans(coordinates))) - b[index];
+ arma::mat rrt = coordinates * trans(coordinates);
+ if (aModes[index] == 0)
+ return trace(a[index] * rrt) - b[index];
+ else
+ {
+ double value = -b[index];
+ for (size_t i = 0; i < a[index].n_rows; ++i)
+ value += rrt(a[index](i, 0), a[index](i, 1));
+
+ return value;
+ }
}
void LRSDP::GradientConstraint(const size_t /*index*/,
@@ -53,7 +65,6 @@
const arma::mat& LRSDP::GetInitialPoint()
{
- initialPoint.ones(70, 34);
return initialPoint;
}
@@ -76,7 +87,20 @@
for (size_t i = 0; i < function.B().n_elem; ++i)
{
// Take the trace subtracted by the b_i.
- double constraint = trace(function.A()[i] * rrt) - function.B()[i];
+ double constraint = -function.B()[i];
+
+ if (function.AModes()[i] == 0)
+ {
+ constraint += trace(function.A()[i] * rrt);
+ }
+ else
+ {
+ for (size_t j = 0; j < function.A()[i].n_rows; ++j)
+ {
+ constraint += rrt(function.A()[i](j, 0), function.A()[i](j, 1));
+ }
+ }
+
objective -= (lambda[i] * constraint);
objective += (sigma / 2) * std::pow(constraint, 2.0);
}
@@ -93,13 +117,39 @@
// with
// S' = C - sum_{i = 1}^{m} y'_i A_i
// y'_i = y_i - sigma * (Trace(A_i * (R R^T)) - b_i)
+ arma::mat rrt = coordinates * trans(coordinates);
arma::mat s = function.C();
for (size_t i = 0; i < function.B().n_elem; ++i)
{
- double y = lambda[i] - sigma * (trace(function.A()[i] *
- (coordinates * trans(coordinates))) - function.B()[i]);
- s -= (y * function.A()[i]);
+ double constraint = -function.B()[i];
+
+ if (function.AModes()[i] == 0)
+ {
+ constraint += trace(function.A()[i] * rrt);
+ }
+ else
+ {
+ for (size_t j = 0; j < function.A()[i].n_rows; ++j)
+ {
+ constraint += rrt(function.A()[i](j, 0), function.A()[i](j, 1));
+ }
+ }
+
+ double y = lambda[i] - sigma * constraint;
+
+ if (function.AModes()[i] == 0)
+ {
+ s -= (y * function.A()[i]);
+ }
+ else
+ {
+ // We only need to subtract the entries which could be modified.
+ for (size_t j = 0; j < function.A()[i].n_rows; ++j)
+ {
+ s(function.A()[i](j, 0), function.A()[i](j, 1)) -= y;
+ }
+ }
}
gradient = 2 * s * coordinates;
More information about the mlpack-svn
mailing list