[mlpack-git] master: expose SDP object directly for LRSDPFunction (1fff6ff)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Mon Feb 2 15:16:45 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/bb6e5c56aab07e6449d86021246b52a9e323f3a0...bd6cb33f8d8270b02a84e81e38727679bb6c319a
>---------------------------------------------------------------
commit 1fff6ff536e79bd8b4550bb63dc6ce5d53f11a7f
Author: Stephen Tu <tu.stephenl at gmail.com>
Date: Wed Jan 28 18:26:24 2015 -0800
expose SDP object directly for LRSDPFunction
>---------------------------------------------------------------
1fff6ff536e79bd8b4550bb63dc6ce5d53f11a7f
src/mlpack/core/optimizers/sdp/lrsdp.hpp | 20 +++++------
src/mlpack/core/optimizers/sdp/lrsdp_function.hpp | 42 +++-------------------
.../core/optimizers/sdp/lrsdp_function_impl.hpp | 34 +++++++++---------
3 files changed, 31 insertions(+), 65 deletions(-)
diff --git a/src/mlpack/core/optimizers/sdp/lrsdp.hpp b/src/mlpack/core/optimizers/sdp/lrsdp.hpp
index 52f2f78..511f635 100644
--- a/src/mlpack/core/optimizers/sdp/lrsdp.hpp
+++ b/src/mlpack/core/optimizers/sdp/lrsdp.hpp
@@ -46,36 +46,36 @@ class LRSDP
double Optimize(arma::mat& coordinates);
//! Return the objective function matrix (c).
- const typename SDPType::objective_matrix_type& C() const { return function.C(); }
+ const typename SDPType::objective_matrix_type& C() const { return function.SDP().C(); }
//! Modify the objective function matrix (c).
- typename SDPType::objective_matrix_type& C() { return function.C(); }
+ typename SDPType::objective_matrix_type& C() { return function.SDP().C(); }
//! Return the vector of sparse A matrices (which correspond to the sparse
// constraints).
- const std::vector<arma::sp_mat>& SparseA() const { return function.SparseA(); }
+ const std::vector<arma::sp_mat>& SparseA() const { return function.SDP().SparseA(); }
//! Modify the veector of sparse A matrices (which correspond to the sparse
// constraints).
- std::vector<arma::sp_mat>& SparseA() { return function.SparseA(); }
+ std::vector<arma::sp_mat>& SparseA() { return function.SDP().SparseA(); }
//! Return the vector of dense A matrices (which correspond to the dense
// constraints).
- const std::vector<arma::mat>& DenseA() const { return function.DenseA(); }
+ const std::vector<arma::mat>& DenseA() const { return function.SDP().DenseA(); }
//! Modify the veector of dense A matrices (which correspond to the dense
// constraints).
- std::vector<arma::mat>& DenseA() { return function.DenseA(); }
+ std::vector<arma::mat>& DenseA() { return function.SDP().DenseA(); }
//! Return the vector of sparse B values.
- const arma::vec& SparseB() const { return function.SparseB(); }
+ const arma::vec& SparseB() const { return function.SDP().SparseB(); }
//! Modify the vector of sparse B values.
- arma::vec& SparseB() { return function.SparseB(); }
+ arma::vec& SparseB() { return function.SDP().SparseB(); }
//! Return the vector of dense B values.
- const arma::vec& DenseB() const { return function.DenseB(); }
+ const arma::vec& DenseB() const { return function.SDP().DenseB(); }
//! Modify the vector of dense B values.
- arma::vec& DenseB() { return function.DenseB(); }
+ arma::vec& DenseB() { return function.SDP().DenseB(); }
//! Return the function to be optimized.
const LRSDPFunction<SDPType>& Function() const { return function; }
diff --git a/src/mlpack/core/optimizers/sdp/lrsdp_function.hpp b/src/mlpack/core/optimizers/sdp/lrsdp_function.hpp
index 1f86410..27bde5a 100644
--- a/src/mlpack/core/optimizers/sdp/lrsdp_function.hpp
+++ b/src/mlpack/core/optimizers/sdp/lrsdp_function.hpp
@@ -72,51 +72,17 @@ class LRSDPFunction
const arma::mat& coordinates,
arma::mat& gradient) const;
- //! Get the number of sparse constraints in the LRSDP.
- size_t NumSparseConstraints() const { return sdp.NumSparseConstraints(); }
-
- //! Get the number of dense constraints in the LRSDP.
- size_t NumDenseConstraints() const { return sdp.NumDenseConstraints(); }
-
//! Get the total number of constraints in the LRSDP.
size_t NumConstraints() const { return sdp.NumConstraints(); }
//! Get the initial point of the LRSDP.
const arma::mat& GetInitialPoint() const { return initialPoint; }
- size_t N() const { return sdp.N(); }
-
- //! Return the objective function matrix (C).
- const typename SDPType::objective_matrix_type& C() const { return sdp.C(); }
-
- //! Modify the objective function matrix (C).
- typename SDPType::objective_matrix_type& C() { return sdp.C(); }
-
- //! Return the vector of sparse A matrices (which correspond to the sparse
- // constraints).
- const std::vector<arma::sp_mat>& SparseA() const { return sdp.SparseA(); }
-
- //! Modify the veector of sparse A matrices (which correspond to the sparse
- // constraints).
- std::vector<arma::sp_mat>& SparseA() { return sdp.SparseA(); }
-
- //! Return the vector of dense A matrices (which correspond to the dense
- // constraints).
- const std::vector<arma::mat>& DenseA() const { return sdp.DenseA(); }
-
- //! Modify the veector of dense A matrices (which correspond to the dense
- // constraints).
- std::vector<arma::mat>& DenseA() { return sdp.DenseA(); }
-
- //! Return the vector of sparse B values.
- const arma::vec& SparseB() const { return sdp.SparseB(); }
- //! Modify the vector of sparse B values.
- arma::vec& SparseB() { return sdp.SparseB(); }
+ //! Return the SDP object representing the problem.
+ const SDPType& SDP() const { return sdp; }
- //! Return the vector of dense B values.
- const arma::vec& DenseB() const { return sdp.DenseB(); }
- //! Modify the vector of dense B values.
- arma::vec& DenseB() { return sdp.DenseB(); }
+ //! Modify the SDP object representing the problem.
+ SDPType& SDP() { return sdp; }
//! Return string representation of object.
std::string ToString() const;
diff --git a/src/mlpack/core/optimizers/sdp/lrsdp_function_impl.hpp b/src/mlpack/core/optimizers/sdp/lrsdp_function_impl.hpp
index 674eac9..bda7128 100644
--- a/src/mlpack/core/optimizers/sdp/lrsdp_function_impl.hpp
+++ b/src/mlpack/core/optimizers/sdp/lrsdp_function_impl.hpp
@@ -43,7 +43,7 @@ template <typename SDPType>
double LRSDPFunction<SDPType>::Evaluate(const arma::mat& coordinates) const
{
const arma::mat rrt = coordinates * trans(coordinates);
- return accu(C() % rrt);
+ return accu(SDP().C() % rrt);
}
template <typename SDPType>
@@ -59,10 +59,10 @@ double LRSDPFunction<SDPType>::EvaluateConstraint(const size_t index,
const arma::mat& coordinates) const
{
const arma::mat rrt = coordinates * trans(coordinates);
- if (index < NumSparseConstraints())
- return accu(SparseA()[index] % rrt) - SparseB()[index];
- const size_t index1 = index - NumSparseConstraints();
- return accu(DenseA()[index1] % rrt) - DenseB()[index1];
+ if (index < SDP().NumSparseConstraints())
+ return accu(SDP().SparseA()[index] % rrt) - SDP().SparseB()[index];
+ const size_t index1 = index - SDP().NumSparseConstraints();
+ return accu(SDP().DenseA()[index1] % rrt) - SDP().DenseB()[index1];
}
template <typename SDPType>
@@ -80,11 +80,11 @@ std::string LRSDPFunction<SDPType>::ToString() const
{
std::ostringstream convert;
convert << "LRSDPFunction [" << this << "]" << std::endl;
- convert << " Number of constraints: " << NumConstraints() << std::endl;
- convert << " Problem size: n=" << GetInitialPoint().n_rows << ", r="
+ convert << " Number of constraints: " << SDP().NumConstraints() << std::endl;
+ convert << " Problem size: n=" << initialPoint.n_rows << ", r="
<< initialPoint.n_cols << std::endl;
- convert << " Sparse Constraint b_i values: " << SparseB().t();
- convert << " Dense Constraint b_i values: " << DenseB().t();
+ convert << " Sparse Constraint b_i values: " << SDP().SparseB().t();
+ convert << " Dense Constraint b_i values: " << SDP().DenseB().t();
return convert.str();
}
@@ -150,13 +150,13 @@ EvaluateImpl(const LRSDPFunction<SDPType>& function,
//
// Similarly for the constraints, taking A*R first should be more efficient
const arma::mat rrt = coordinates * trans(coordinates);
- double objective = accu(function.C() % rrt);
+ double objective = accu(function.SDP().C() % rrt);
// Now each constraint.
- UpdateObjective(objective, rrt, function.SparseA(), function.SparseB(),
+ UpdateObjective(objective, rrt, function.SDP().SparseA(), function.SDP().SparseB(),
lambda, 0, sigma);
- UpdateObjective(objective, rrt, function.DenseA(), function.DenseB(), lambda,
- function.NumSparseConstraints(), sigma);
+ UpdateObjective(objective, rrt, function.SDP().DenseA(), function.SDP().DenseB(), lambda,
+ function.SDP().NumSparseConstraints(), sigma);
return objective;
}
@@ -175,14 +175,14 @@ GradientImpl(const LRSDPFunction<SDPType>& function,
// S' = C - sum_{i = 1}^{m} y'_i A_i
// y'_i = y_i - sigma * (Trace(A_i * (R R^T)) - b_i)
const arma::mat rrt = coordinates * trans(coordinates);
- arma::mat s(function.C());
+ arma::mat s(function.SDP().C());
UpdateGradient(
- s, rrt, function.SparseA(), function.SparseB(),
+ s, rrt, function.SDP().SparseA(), function.SDP().SparseB(),
lambda, 0, sigma);
UpdateGradient(
- s, rrt, function.DenseA(), function.DenseB(),
- lambda, function.NumSparseConstraints(), sigma);
+ s, rrt, function.SDP().DenseA(), function.SDP().DenseB(),
+ lambda, function.SDP().NumSparseConstraints(), sigma);
gradient = 2 * s * coordinates;
}
More information about the mlpack-git
mailing list