[mlpack-svn] r11349 - in mlpack/trunk/src/mlpack/core/optimizers: aug_lagrangian lbfgs lrsdp
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Feb 2 16:36:26 EST 2012
Author: rcurtin
Date: 2012-02-02 16:36:25 -0500 (Thu, 02 Feb 2012)
New Revision: 11349
Modified:
mlpack/trunk/src/mlpack/core/optimizers/aug_lagrangian/aug_lagrangian_impl.hpp
mlpack/trunk/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp
Log:
Temporary work check-in so I can work from elsewhere.
Modified: mlpack/trunk/src/mlpack/core/optimizers/aug_lagrangian/aug_lagrangian_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/aug_lagrangian/aug_lagrangian_impl.hpp 2012-02-02 21:35:58 UTC (rev 11348)
+++ mlpack/trunk/src/mlpack/core/optimizers/aug_lagrangian/aug_lagrangian_impl.hpp 2012-02-02 21:36:25 UTC (rev 11349)
@@ -33,7 +33,7 @@
arma::vec lambda(function.NumConstraints());
lambda.ones();
lambda *= -1;
- lambda[0] = -double(coordinates.n_cols);
+ lambda[0] = -0.70 * double(coordinates.n_cols);
double penalty_threshold = DBL_MAX; // Ensure we update lambda immediately.
// Track the last objective to compare for convergence.
@@ -96,8 +96,8 @@
for (size_t i = 0; i < function.NumConstraints(); ++i)
{
- arma::mat tmpgrad;
- function.GradientConstraint(i, coordinates, tmpgrad);
+// arma::mat tmpgrad;
+// function.GradientConstraint(i, coordinates, tmpgrad);
// Log::Debug << "Gradient of constraint " << i << " is " << std::endl;
// Log::Debug << tmpgrad << std::endl;
}
Modified: mlpack/trunk/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp 2012-02-02 21:35:58 UTC (rev 11348)
+++ mlpack/trunk/src/mlpack/core/optimizers/lbfgs/lbfgs_impl.hpp 2012-02-02 21:36:25 UTC (rev 11349)
@@ -353,9 +353,12 @@
for (size_t itNum = 0; optimizeUntilConvergence || (itNum != numIterations);
itNum++)
{
- Log::Info << "L-BFGS iteration " << itNum << "; objective " <<
+ Log::Debug << "L-BFGS iteration " << itNum << "; objective " <<
function.Evaluate(iterate) << "." << std::endl;
+// Log::Debug << "Coordinates " << std::endl << iterate << std::endl;
+// Log::Debug << "Gradient " << std::endl << gradient << std::endl;
+
// Break when the norm of the gradient becomes too small.
if (GradientNormTooSmall(gradient))
{
Modified: mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-02 21:35:58 UTC (rev 11348)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp 2012-02-02 21:36:25 UTC (rev 11349)
@@ -16,20 +16,31 @@
class LRSDP
{
public:
- LRSDP();
+ LRSDP() { }
- bool Optimize(arma::mat& coordinates)
+ double Optimize(arma::mat& coordinates);
// AugLagrangian<LRSDP> auglag);
-// double Evaluate(const arma::mat& coordinates) const;
+ double Evaluate(const arma::mat& coordinates) const;
-// void Gradient(const arma::mat& coordinates, arma::mat& gradient) const;
+ void Gradient(const arma::mat& coordinates, arma::mat& gradient) const;
+ double EvaluateConstraint(const size_t index,
+ const arma::mat& coordinates) const;
+
+ void GradientConstraint(const size_t index,
+ const arma::mat& coordinates,
+ arma::mat& gradient) const;
+
+ size_t NumConstraints() const { return b.n_elem; }
+
+ const arma::mat& GetInitialPoint();
+
const arma::mat& C() const { return c; }
arma::mat& C() { return c; }
const std::vector<arma::mat> A() const { return a; }
- arma::mat& A() { return a; }
+ std::vector<arma::mat>& A() { return a; }
const arma::vec& B() const { return b; }
arma::vec& B() { return b; }
@@ -39,6 +50,9 @@
arma::mat c; // For objective function.
std::vector<arma::mat> a; // A_i for each constraint.
arma::vec b; // b_i for each constraint.
+
+ // Initial point.
+ arma::mat initialPoint;
};
}; // 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-02 21:35:58 UTC (rev 11348)
+++ mlpack/trunk/src/mlpack/core/optimizers/lrsdp/lrsdp_impl.hpp 2012-02-02 21:36:25 UTC (rev 11349)
@@ -17,17 +17,19 @@
namespace mlpack {
namespace optimization {
-bool LRSDP::Optimize(arma::mat& coordinates)
+double LRSDP::Optimize(arma::mat& coordinates)
{
// Create the Augmented Lagrangian function.
AugLagrangian<LRSDP> auglag(*this);
auglag.Optimize(coordinates);
+
+ return Evaluate(coordinates);
}
double LRSDP::Evaluate(const arma::mat& coordinates) const
{
- Log::Fatal << "LRSDP::Evaluate() called! Uh-oh..." << std::endl;
+ return -accu(coordinates * trans(coordinates));
}
void LRSDP::Gradient(const arma::mat& coordinates, arma::mat& gradient) const
@@ -35,6 +37,25 @@
Log::Fatal << "LRSDP::Gradient() called! Uh-oh..." << std::endl;
}
+double LRSDP::EvaluateConstraint(const size_t index,
+ const arma::mat& coordinates) const
+{
+ return trace(a[index] * (coordinates * trans(coordinates))) - b[index];
+}
+
+void LRSDP::GradientConstraint(const size_t index,
+ const arma::mat& coordinates,
+ arma::mat& gradient) const
+{
+ Log::Fatal << "LRSDP::GradientConstraint() called! Uh-oh..." << std::endl;
+}
+
+const arma::mat& LRSDP::GetInitialPoint()
+{
+ initialPoint.ones(2, 2);
+ return initialPoint;
+}
+
// Custom specializations of the AugmentedLagrangianFunction for the LRSDP case.
template<>
double AugLagrangianFunction<LRSDP>::Evaluate(const arma::mat& coordinates)
@@ -63,8 +84,8 @@
}
template<>
-double AugLagrangianFunction<LRSDP>::Gradient(const arma::mat& coordinates,
- arma::mat& gradient) const
+void AugLagrangianFunction<LRSDP>::Gradient(const arma::mat& coordinates,
+ arma::mat& gradient) const
{
// We can calculate the gradient in a smart way.
// L'(R, y, s) = 2 * S' * R
More information about the mlpack-svn
mailing list