[mlpack-svn] master: Rename variables to be consistent with rest of codebase (599f551)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Wed Dec 31 16:02:12 EST 2014
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/8c13d5c6d16fadd1fe4dfb2230adfaa0268e95dd...5c67a7f75ba446321f794b63b861dc35f37dcd11
>---------------------------------------------------------------
commit 599f55162d23ad90242fb640962fb726665d634f
Author: Stephen Tu <stephent at berkeley.edu>
Date: Tue Dec 23 10:17:47 2014 +0800
Rename variables to be consistent with rest of codebase
>---------------------------------------------------------------
599f55162d23ad90242fb640962fb726665d634f
src/mlpack/core/optimizers/lrsdp/lrsdp.hpp | 32 ++++++-------
.../core/optimizers/lrsdp/lrsdp_function.cpp | 36 +++++++-------
.../core/optimizers/lrsdp/lrsdp_function.hpp | 56 +++++++++++-----------
src/mlpack/tests/lrsdp_test.cpp | 16 +++----
4 files changed, 70 insertions(+), 70 deletions(-)
diff --git a/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp b/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
index b34999d..5f97fc8 100644
--- a/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
+++ b/src/mlpack/core/optimizers/lrsdp/lrsdp.hpp
@@ -44,43 +44,43 @@ class LRSDP
*/
double Optimize(arma::mat& coordinates);
- //! Return the sparse objective function matrix (C_sparse).
- const arma::sp_mat& C_sparse() const { return function.C_sparse(); }
+ //! Return the sparse objective function matrix (sparseC).
+ const arma::sp_mat& SparseC() const { return function.SparseC(); }
- //! Modify the sparse objective function matrix (C_sparse).
- arma::sp_mat& C_sparse() { return function.C_sparse(); }
+ //! Modify the sparse objective function matrix (sparseC).
+ arma::sp_mat& SparseC() { return function.SparseC(); }
- //! Return the dense objective function matrix (C_dense).
- const arma::mat& C_dense() const { return function.C_dense(); }
+ //! Return the dense objective function matrix (denseC).
+ const arma::mat& DenseC() const { return function.DenseC(); }
- //! Modify the dense objective function matrix (C_dense).
- arma::mat& C_dense() { return function.C_dense(); }
+ //! Modify the dense objective function matrix (denseC).
+ arma::mat& DenseC() { return function.DenseC(); }
//! Return the vector of sparse A matrices (which correspond to the sparse
// constraints).
- const std::vector<arma::sp_mat>& A_sparse() const { return function.A_sparse(); }
+ const std::vector<arma::sp_mat>& SparseA() const { return function.SparseA(); }
//! Modify the veector of sparse A matrices (which correspond to the sparse
// constraints).
- std::vector<arma::sp_mat>& A_sparse() { return function.A_sparse(); }
+ std::vector<arma::sp_mat>& SparseA() { return function.SparseA(); }
//! Return the vector of dense A matrices (which correspond to the dense
// constraints).
- const std::vector<arma::mat>& A_dense() const { return function.A_dense(); }
+ const std::vector<arma::mat>& DenseA() const { return function.DenseA(); }
//! Modify the veector of dense A matrices (which correspond to the dense
// constraints).
- std::vector<arma::mat>& A_dense() { return function.A_dense(); }
+ std::vector<arma::mat>& DenseA() { return function.DenseA(); }
//! Return the vector of sparse B values.
- const arma::vec& B_sparse() const { return function.B_sparse(); }
+ const arma::vec& SparseB() const { return function.SparseB(); }
//! Modify the vector of sparse B values.
- arma::vec& B_sparse() { return function.B_sparse(); }
+ arma::vec& SparseB() { return function.SparseB(); }
//! Return the vector of dense B values.
- const arma::vec& B_dense() const { return function.B_dense(); }
+ const arma::vec& DenseB() const { return function.DenseB(); }
//! Modify the vector of dense B values.
- arma::vec& B_dense() { return function.B_dense(); }
+ arma::vec& DenseB() { return function.DenseB(); }
//! Return the function to be optimized.
const LRSDPFunction& Function() const { return function; }
diff --git a/src/mlpack/core/optimizers/lrsdp/lrsdp_function.cpp b/src/mlpack/core/optimizers/lrsdp/lrsdp_function.cpp
index bb4eded..785c27e 100644
--- a/src/mlpack/core/optimizers/lrsdp/lrsdp_function.cpp
+++ b/src/mlpack/core/optimizers/lrsdp/lrsdp_function.cpp
@@ -15,14 +15,14 @@ using namespace std;
LRSDPFunction::LRSDPFunction(const size_t numSparseConstraints,
const size_t numDenseConstraints,
const arma::mat& initialPoint):
- c_sparse(initialPoint.n_rows, initialPoint.n_rows),
- c_dense(initialPoint.n_rows, initialPoint.n_rows, arma::fill::zeros),
+ sparseC(initialPoint.n_rows, initialPoint.n_rows),
+ denseC(initialPoint.n_rows, initialPoint.n_rows, arma::fill::zeros),
hasModifiedSparseObjective(false),
hasModifiedDenseObjective(false),
- a_sparse(numSparseConstraints),
- b_sparse(numSparseConstraints),
- a_dense(numDenseConstraints),
- b_dense(numDenseConstraints),
+ sparseA(numSparseConstraints),
+ sparseB(numSparseConstraints),
+ denseA(numDenseConstraints),
+ denseB(numDenseConstraints),
initialPoint(initialPoint)
{
if (initialPoint.n_rows < initialPoint.n_cols)
@@ -46,9 +46,9 @@ double LRSDPFunction::EvaluateConstraint(const size_t index,
{
const arma::mat rrt = coordinates * trans(coordinates);
if (index < NumSparseConstraints())
- return trace(a_sparse[index] * rrt) - b_sparse[index];
+ return trace(sparseA[index] * rrt) - sparseB[index];
const size_t index1 = index - NumSparseConstraints();
- return trace(a_dense[index1] * rrt) - b_dense[index1];
+ return trace(denseA[index1] * rrt) - denseB[index1];
}
void LRSDPFunction::GradientConstraint(const size_t /* index */,
@@ -67,8 +67,8 @@ std::string LRSDPFunction::ToString() const
convert << " Number of constraints: " << NumConstraints() << std::endl;
convert << " Problem size: n=" << initialPoint.n_rows << ", r="
<< initialPoint.n_cols << std::endl;
- convert << " Sparse Constraint b_i values: " << b_sparse.t();
- convert << " Dense Constraint b_i values: " << b_dense.t();
+ convert << " Sparse Constraint b_i values: " << sparseB.t();
+ convert << " Dense Constraint b_i values: " << denseB.t();
return convert.str();
}
@@ -133,16 +133,16 @@ double AugLagrangianFunction<LRSDPFunction>::Evaluate(
const arma::mat rrt = coordinates * trans(coordinates);
double objective = 0.;
if (function.hasSparseObjective())
- objective += trace(function.C_sparse() * rrt);
+ objective += trace(function.SparseC() * rrt);
if (function.hasDenseObjective())
- objective += trace(function.C_dense() * rrt);
+ objective += trace(function.DenseC() * rrt);
// Now each constraint.
updateObjective(
- objective, rrt, function.A_sparse(), function.B_sparse(),
+ objective, rrt, function.SparseA(), function.SparseB(),
lambda, 0, sigma);
updateObjective(
- objective, rrt, function.A_dense(), function.B_dense(),
+ objective, rrt, function.DenseA(), function.DenseB(),
lambda, function.NumSparseConstraints(), sigma);
return objective;
@@ -163,15 +163,15 @@ void AugLagrangianFunction<LRSDPFunction>::Gradient(
arma::mat s(function.n(), function.n(), arma::fill::zeros);
if (function.hasSparseObjective())
- s += function.C_sparse();
+ s += function.SparseC();
if (function.hasDenseObjective())
- s += function.C_dense();
+ s += function.DenseC();
updateGradient(
- s, rrt, function.A_sparse(), function.B_sparse(),
+ s, rrt, function.SparseA(), function.SparseB(),
lambda, 0, sigma);
updateGradient(
- s, rrt, function.A_dense(), function.B_dense(),
+ s, rrt, function.DenseA(), function.DenseB(),
lambda, function.NumSparseConstraints(), sigma);
gradient = 2 * s * coordinates;
diff --git a/src/mlpack/core/optimizers/lrsdp/lrsdp_function.hpp b/src/mlpack/core/optimizers/lrsdp/lrsdp_function.hpp
index 66a004c..7eeaf14 100644
--- a/src/mlpack/core/optimizers/lrsdp/lrsdp_function.hpp
+++ b/src/mlpack/core/optimizers/lrsdp/lrsdp_function.hpp
@@ -57,10 +57,10 @@ class LRSDPFunction
arma::mat& gradient) const;
//! Get the number of sparse constraints in the LRSDP.
- size_t NumSparseConstraints() const { return b_sparse.n_elem; }
+ size_t NumSparseConstraints() const { return sparseB.n_elem; }
//! Get the number of dense constraints in the LRSDP.
- size_t NumDenseConstraints() const { return b_dense.n_elem; }
+ size_t NumDenseConstraints() const { return denseB.n_elem; }
//! Get the total number of constraints in the LRSDP.
size_t NumConstraints() const {
@@ -72,49 +72,49 @@ class LRSDPFunction
size_t n() const { return initialPoint.n_rows; }
- //! Return the sparse objective function matrix (C_sparse).
- const arma::sp_mat& C_sparse() const { return c_sparse; }
+ //! Return the sparse objective function matrix (sparseC).
+ const arma::sp_mat& SparseC() const { return sparseC; }
- //! Modify the sparse objective function matrix (C_sparse).
- arma::sp_mat& C_sparse() {
+ //! Modify the sparse objective function matrix (sparseC).
+ arma::sp_mat& SparseC() {
hasModifiedSparseObjective = true;
- return c_sparse;
+ return sparseC;
}
- //! Return the dense objective function matrix (C_dense).
- const arma::mat& C_dense() const { return c_dense; }
+ //! Return the dense objective function matrix (denseC).
+ const arma::mat& DenseC() const { return denseC; }
- //! Modify the dense objective function matrix (C_dense).
- arma::mat& C_dense() {
+ //! Modify the dense objective function matrix (denseC).
+ arma::mat& DenseC() {
hasModifiedDenseObjective = true;
- return c_dense;
+ return denseC;
}
//! Return the vector of sparse A matrices (which correspond to the sparse
// constraints).
- const std::vector<arma::sp_mat>& A_sparse() const { return a_sparse; }
+ const std::vector<arma::sp_mat>& SparseA() const { return sparseA; }
//! Modify the veector of sparse A matrices (which correspond to the sparse
// constraints).
- std::vector<arma::sp_mat>& A_sparse() { return a_sparse; }
+ std::vector<arma::sp_mat>& SparseA() { return sparseA; }
//! Return the vector of dense A matrices (which correspond to the dense
// constraints).
- const std::vector<arma::mat>& A_dense() const { return a_dense; }
+ const std::vector<arma::mat>& DenseA() const { return denseA; }
//! Modify the veector of dense A matrices (which correspond to the dense
// constraints).
- std::vector<arma::mat>& A_dense() { return a_dense; }
+ std::vector<arma::mat>& DenseA() { return denseA; }
//! Return the vector of sparse B values.
- const arma::vec& B_sparse() const { return b_sparse; }
+ const arma::vec& SparseB() const { return sparseB; }
//! Modify the vector of sparse B values.
- arma::vec& B_sparse() { return b_sparse; }
+ arma::vec& SparseB() { return sparseB; }
//! Return the vector of dense B values.
- const arma::vec& B_dense() const { return b_dense; }
+ const arma::vec& DenseB() const { return denseB; }
//! Modify the vector of dense B values.
- arma::vec& B_dense() { return b_dense; }
+ arma::vec& DenseB() { return denseB; }
bool hasSparseObjective() const { return hasModifiedSparseObjective; }
@@ -125,26 +125,26 @@ class LRSDPFunction
private:
//! Sparse objective function matrix c.
- arma::sp_mat c_sparse;
+ arma::sp_mat sparseC;
//! Dense objective function matrix c.
- arma::mat c_dense;
+ arma::mat denseC;
- //! If false, c_sparse is zero
+ //! If false, sparseC is zero
bool hasModifiedSparseObjective;
- //! If false, c_dense is zero
+ //! If false, denseC is zero
bool hasModifiedDenseObjective;
//! A_i for each sparse constraint.
- std::vector<arma::sp_mat> a_sparse;
+ std::vector<arma::sp_mat> sparseA;
//! b_i for each sparse constraint.
- arma::vec b_sparse;
+ arma::vec sparseB;
//! A_i for each dense constraint.
- std::vector<arma::mat> a_dense;
+ std::vector<arma::mat> denseA;
//! b_i for each dense constraint.
- arma::vec b_dense;
+ arma::vec denseB;
//! Initial point.
arma::mat initialPoint;
diff --git a/src/mlpack/tests/lrsdp_test.cpp b/src/mlpack/tests/lrsdp_test.cpp
index 00ba285..4eb4f75 100644
--- a/src/mlpack/tests/lrsdp_test.cpp
+++ b/src/mlpack/tests/lrsdp_test.cpp
@@ -58,22 +58,22 @@ void setupLovaszTheta(const arma::mat& edges,
const size_t vertices = max(max(edges)) + 1;
// C = -(e e^T) = -ones().
- lovasz.C_dense().ones(vertices, vertices);
- lovasz.C_dense() *= -1;
+ lovasz.DenseC().ones(vertices, vertices);
+ lovasz.DenseC() *= -1;
// b_0 = 1; else = 0.
- lovasz.B_sparse().zeros(edges.n_cols);
- lovasz.B_sparse()[0] = 1;
+ lovasz.SparseB().zeros(edges.n_cols);
+ lovasz.SparseB()[0] = 1;
// A_0 = I_n.
- lovasz.A_sparse()[0].eye(vertices, vertices);
+ lovasz.SparseA()[0].eye(vertices, vertices);
// A_ij only has ones at (i, j) and (j, i) and 0 elsewhere.
for (size_t i = 0; i < edges.n_cols; ++i)
{
- lovasz.A_sparse()[i + 1].zeros(vertices, vertices);
- lovasz.A_sparse()[i + 1](edges(0, i), edges(1, i)) = 1.;
- lovasz.A_sparse()[i + 1](edges(1, i), edges(0, i)) = 1.;
+ lovasz.SparseA()[i + 1].zeros(vertices, vertices);
+ lovasz.SparseA()[i + 1](edges(0, i), edges(1, i)) = 1.;
+ lovasz.SparseA()[i + 1](edges(1, i), edges(0, i)) = 1.;
}
// Set the Lagrange multipliers right.
More information about the mlpack-svn
mailing list