[mlpack-svn] r11669 - mlpack/trunk/src/mlpack/methods/mvu
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Feb 29 17:48:41 EST 2012
Author: rcurtin
Date: 2012-02-29 17:48:40 -0500 (Wed, 29 Feb 2012)
New Revision: 11669
Modified:
mlpack/trunk/src/mlpack/methods/mvu/CMakeLists.txt
mlpack/trunk/src/mlpack/methods/mvu/mvu.cpp
mlpack/trunk/src/mlpack/methods/mvu/mvu.hpp
Log:
Some changes to mvu. Not 100% sure if it works yet.
Modified: mlpack/trunk/src/mlpack/methods/mvu/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/methods/mvu/CMakeLists.txt 2012-02-29 22:41:10 UTC (rev 11668)
+++ mlpack/trunk/src/mlpack/methods/mvu/CMakeLists.txt 2012-02-29 22:48:40 UTC (rev 11669)
@@ -5,8 +5,6 @@
set(SOURCES
mvu.hpp
mvu.cpp
- mvu_objective_function.hpp
- mvu_objective_function.cpp
)
# Add directory name to sources.
Modified: mlpack/trunk/src/mlpack/methods/mvu/mvu.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/mvu/mvu.cpp 2012-02-29 22:41:10 UTC (rev 11668)
+++ mlpack/trunk/src/mlpack/methods/mvu/mvu.cpp 2012-02-29 22:48:40 UTC (rev 11669)
@@ -5,11 +5,12 @@
* Implementation of the MVU class and its auxiliary objective function class.
*/
#include "mvu.hpp"
-#include "mvu_objective_function.hpp"
//#include <mlpack/core/optimizers/aug_lagrangian/aug_lagrangian.hpp>
#include <mlpack/core/optimizers/lrsdp/lrsdp.hpp>
+#include <mlpack/methods/neighbor_search/neighbor_search.hpp>
+
using namespace mlpack;
using namespace mlpack::mvu;
using namespace mlpack::optimization;
@@ -23,16 +24,80 @@
const size_t numNeighbors,
arma::mat& outputData)
{
- // Set up LRSDP that we will solve.
-// LRSDP mvuSolver;
+ // First we have to choose the output point. We'll take a linear projection
+ // of the data for now (this is probably not a good final solution).
+ outputData = trans(data.rows(0, newDim));
+ // The number of constraints is the number of nearest neighbors plus one.
+ LRSDP mvuSolver(numNeighbors * data.n_cols + 1, outputData);
- MVUObjectiveFunction obj(data, newDim, numNeighbors);
+ // Set up the objective. Because we are maximizing the trace of (R R^T),
+ // we'll instead state it as min(-I_n * (R R^T)), meaning C() is -I_n.
+ mvuSolver.C().eye(newDim, newDim);
+ mvuSolver.C() *= -1;
- // Set up Augmented Lagrangian method.
- // Memory choice is arbitrary; this needs to be configurable.
-//AugLagrangian<MVUObjectiveFunction> aug(obj, 20);
+ // Now set up each of the constraints.
+ // The first constraint is trace(ones * R * R^T) = 0.
+ mvuSolver.B()[0] = 0;
+ mvuSolver.A()[0].ones(newDim, newDim);
-// outputData = obj.GetInitialPoint();
-// aug.Optimize(outputData, 0);
+ // All of our other constraints will be sparse except the first. So set that
+ // vector of modes accordingly.
+ mvuSolver.AModes().ones();
+ mvuSolver.AModes()[0] = 0;
+
+ // Now all of the other constraints. We first have to run AllkNN to get the
+ // list of nearest neighbors.
+ arma::Mat<size_t> neighbors;
+ arma::mat distances;
+
+ AllkNN allknn(data);
+ allknn.Search(numNeighbors, neighbors, distances);
+
+ // Add each of the other constraints. They are sparse constraints:
+ // Tr(A_ij K) = d_ij;
+ // A_ij = zeros except for 1 at (i, i), (j, j); -1 at (i, j), (j, i).
+ for (size_t i = 0; i < neighbors.n_cols; ++i)
+ {
+ for (size_t j = 0; j < numNeighbors; ++j)
+ {
+ // This is the index of the constraint.
+ const size_t index = (i * numNeighbors) + j + 1;
+
+ arma::mat& aRef = mvuSolver.A()[index];
+
+ aRef.set_size(2, 4);
+
+ // A_ij(i, i) = 1.
+ aRef(0, 0) = i;
+ aRef(1, 0) = i;
+ aRef(2, 0) = 1;
+
+ // A_ij(i, j) = -1.
+ aRef(0, 1) = i;
+ aRef(1, 1) = neighbors(j, i);
+ aRef(2, 1) = -1;
+
+ // A_ij(j, i) = -1.
+ aRef(0, 2) = neighbors(j, i);
+ aRef(1, 2) = i;
+ aRef(2, 2) = -1;
+
+ // A_ij(j, j) = 1.
+ aRef(0, 3) = neighbors(j, i);
+ aRef(1, 3) = neighbors(j, i);
+ aRef(2, 3) = 1;
+
+ // The constraint b_ij is the distance between these two points.
+ mvuSolver.B()[index] = distances(j, i);
+ }
+ }
+
+ // Now on with the solving.
+ double objective = mvuSolver.Optimize(outputData);
+
+ Log::Info << "Final objective is " << objective << "." << std::endl;
+
+ // Revert to original data format.
+ outputData = trans(outputData);
}
Modified: mlpack/trunk/src/mlpack/methods/mvu/mvu.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/mvu/mvu.hpp 2012-02-29 22:41:10 UTC (rev 11668)
+++ mlpack/trunk/src/mlpack/methods/mvu/mvu.hpp 2012-02-29 22:48:40 UTC (rev 11669)
@@ -8,7 +8,7 @@
* Augmented Lagrangian optimizer (which in turn uses the L-BFGS optimizer).
*/
#ifndef __MLPACK_METHODS_MVU_MVU_HPP
-#define __MLPACK_METHODS_VU_MVU_HPP
+#define __MLPACK_METHODS_MVU_MVU_HPP
#include <mlpack/core.hpp>
More information about the mlpack-svn
mailing list