From fddba649b1df67f661d659ffb6754ac8f103f62a Mon Sep 17 00:00:00 2001 From: Manish Date: Thu, 28 Jun 2018 15:45:40 +0530 Subject: [PATCH] removed extra L-BFGS related parameters --- src/mlpack/methods/lmnn/lmnn_main.cpp | 33 +------- src/mlpack/tests/lmnn_test.cpp | 3 +- src/mlpack/tests/main_tests/lmnn_test.cpp | 92 ----------------------- 3 files changed, 6 insertions(+), 122 deletions(-) diff --git a/src/mlpack/methods/lmnn/lmnn_main.cpp b/src/mlpack/methods/lmnn/lmnn_main.cpp index 84579b1aca..1c4f9b23b1 100644 --- a/src/mlpack/methods/lmnn/lmnn_main.cpp +++ b/src/mlpack/methods/lmnn/lmnn_main.cpp @@ -94,12 +94,9 @@ PROGRAM_INFO("Large Margin Nearest Neighbors (LMNN)", "The L-BFGS optimizer, specified by the value 'lbfgs' for the parameter " + PRINT_PARAM_STRING("optimizer") + ", uses a back-tracking line search " "algorithm to minimize a function. The following parameters are used by " - "L-BFGS: " + PRINT_PARAM_STRING("num_basis") + " (specifies the number" - " of memory points used by L-BFGS), " + - PRINT_PARAM_STRING("max_iterations") + ", " + - PRINT_PARAM_STRING("armijo_constant") + ", " + - PRINT_PARAM_STRING("wolfe") + ", " + PRINT_PARAM_STRING("tolerance") + - " (the optimization is terminated when the gradient norm is below this " + "L-BFGS: " + PRINT_PARAM_STRING("max_iterations") + ", " + + PRINT_PARAM_STRING("tolerance") + + "(the optimization is terminated when the gradient norm is below this " "value). For more details on the L-BFGS optimizer, consult either the " "mlpack L-BFGS documentation (in lbfgs.hpp) or the vast set of published " "literature on L-BFGS. In addition, a normalized starting point can be " @@ -135,7 +132,7 @@ PARAM_STRING_IN("optimizer", "Optimizer to use; 'amsgrad', 'bbsgd', 'sgd', or " "'lbfgs'.", "O", "amsgrad"); PARAM_DOUBLE_IN("regularization", "Regularization for LMNN objective function ", "r", 0.5); -PARAM_INT_IN("rank", "Rank of distance matrix to be optimized. ", "K", 0); +PARAM_INT_IN("rank", "Rank of distance matrix to be optimized. ", "A", 0); PARAM_FLAG("normalize", "Use a normalized starting point for optimization. It" "is useful for when points are far apart, or when SGD is returning NaN.", "N"); @@ -150,10 +147,6 @@ PARAM_DOUBLE_IN("step_size", "Step size for AMSGrad, BB_SGD and SGD (alpha).", PARAM_FLAG("linear_scan", "Don't shuffle the order in which data points are " "visited for SGD or mini-batch SGD.", "L"); PARAM_INT_IN("batch_size", "Batch size for mini-batch SGD.", "b", 50); -PARAM_INT_IN("num_basis", "Number of memory points to be stored for L-BFGS.", - "B", 5); -PARAM_DOUBLE_IN("armijo_constant", "Armijo constant for L-BFGS.", "A", 1e-4); -PARAM_DOUBLE_IN("wolfe", "Wolfe condition parameter for L-BFGS.", "w", 0.9); PARAM_INT_IN("range", "Number of iterations after which impostors needs to be " "recalculated", "R", 1); PARAM_INT_IN("seed", "Random seed. If 0, 'std::time(NULL)' is used.", "s", 0); @@ -224,26 +217,14 @@ static void mlpackMain() // Warn on unused parameters. if (optimizerType == "amsgrad") { - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("armijo_constant", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("wolfe", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); ReportIgnoredParam("max_iterations", "L-BFGS optimizer is not being used"); } else if (optimizerType == "bbsgd") { - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("armijo_constant", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("wolfe", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); ReportIgnoredParam("max_iterations", "L-BFGS optimizer is not being used"); } else if (optimizerType == "sgd") { - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("armijo_constant", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("wolfe", "L-BFGS optimizer is not being used"); - ReportIgnoredParam("num_basis", "L-BFGS optimizer is not being used"); ReportIgnoredParam("max_iterations", "L-BFGS optimizer is not being used"); } else if (optimizerType == "lbfgs") @@ -283,9 +264,6 @@ static void mlpackMain() const bool normalize = CLI::HasParam("normalize"); const bool printAccuracy = CLI::HasParam("print_accuracy"); const bool shuffle = !CLI::HasParam("linear_scan"); - const int numBasis = CLI::GetParam("num_basis"); - const double armijoConstant = CLI::GetParam("armijo_constant"); - const double wolfe = CLI::GetParam("wolfe"); const size_t batchSize = (size_t) CLI::GetParam("batch_size"); const size_t range = (size_t) CLI::GetParam("range"); const size_t rank = (size_t) CLI::GetParam("rank"); @@ -388,10 +366,7 @@ static void mlpackMain() LMNN, L_BFGS> lmnn(data, labels, k); lmnn.Regularization() = regularization; lmnn.Range() = range; - lmnn.Optimizer().NumBasis() = numBasis; lmnn.Optimizer().MaxIterations() = maxIterations; - lmnn.Optimizer().ArmijoConstant() = armijoConstant; - lmnn.Optimizer().Wolfe() = wolfe; lmnn.Optimizer().MinGradientNorm() = tolerance; lmnn.LearnDistance(distance); diff --git a/src/mlpack/tests/lmnn_test.cpp b/src/mlpack/tests/lmnn_test.cpp index 969bd457a8..5c744d3925 100644 --- a/src/mlpack/tests/lmnn_test.cpp +++ b/src/mlpack/tests/lmnn_test.cpp @@ -1,5 +1,6 @@ /** * @file lmnn_test.cpp + * @author Marcus Edel * @author Ryan Curtin * @author Manish Kumar * @@ -490,7 +491,7 @@ BOOST_AUTO_TEST_CASE(LMNNLowRankAccuracyTest) // BOOST_REQUIRE_CLOSE(Accuracy1, Accuracy2, 2.0); } -// Comprehensive gradient tests by Ryan Curtin. +// Comprehensive gradient tests by Marcus Edel & Ryan Curtin. // Simple numerical gradient checker. template diff --git a/src/mlpack/tests/main_tests/lmnn_test.cpp b/src/mlpack/tests/main_tests/lmnn_test.cpp index eb22cd95c9..b76fb7d5b3 100644 --- a/src/mlpack/tests/main_tests/lmnn_test.cpp +++ b/src/mlpack/tests/main_tests/lmnn_test.cpp @@ -608,98 +608,6 @@ BOOST_AUTO_TEST_CASE(LMNNDiffRangeTest) transformedData), 0); } -/** - * Ensure that different value of wolfe results in a - * different output matrix. - */ -BOOST_AUTO_TEST_CASE(LMNNDiffWolfeTest) -{ - arma::mat inputData; - if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Cannot load iris.csv!"); - - arma::Row labels; - if (!data::Load("iris_labels.txt", labels)) - BOOST_FAIL("Cannot load iris_labels.txt!"); - - // Set parameters. - SetInputParam("input", inputData); - SetInputParam("labels", labels); - SetInputParam("optimizer", std::string("lbfgs")); - SetInputParam("k", 5); - SetInputParam("wolfe", 0.1); - - mlpackMain(); - - arma::mat output = CLI::GetParam("output"); - arma::mat transformedData = CLI::GetParam("transformed_data"); - - // Reset settings. - CLI::ClearSettings(); - CLI::RestoreSettings(testName); - - // Set different parameters. - SetInputParam("input", std::move(inputData)); - SetInputParam("labels", std::move(labels)); - SetInputParam("optimizer", std::string("lbfgs")); - SetInputParam("k", 5); - SetInputParam("wolfe", 1.0); - - mlpackMain(); - - // Check that the output matrices are different. - BOOST_REQUIRE_GT( - arma::accu(CLI::GetParam("output") != output), 0); - BOOST_REQUIRE_GT(arma::accu(CLI::GetParam("transformed_data") != - transformedData), 0); -} - -/** - * Ensure that different value of NumBasis results in a - * different output matrix. - */ -BOOST_AUTO_TEST_CASE(LMNNDiffNumBasisTest) -{ - arma::mat inputData; - if (!data::Load("iris.csv", inputData)) - BOOST_FAIL("Cannot load iris.csv!"); - - arma::Row labels; - if (!data::Load("iris_labels.txt", labels)) - BOOST_FAIL("Cannot load iris_labels.txt!"); - - // Set parameters and use a larger num_basis. - SetInputParam("input", inputData); - SetInputParam("labels", labels); - SetInputParam("optimizer", std::string("lbfgs")); - SetInputParam("k", 5); - SetInputParam("num_basis", (int) 100); - - mlpackMain(); - - arma::mat output = CLI::GetParam("output"); - arma::mat transformedData = CLI::GetParam("transformed_data"); - - // Reset Settings. - CLI::ClearSettings(); - CLI::RestoreSettings(testName); - - // Set parameters with a smaller num_basis. - SetInputParam("input", std::move(inputData)); - SetInputParam("labels", labels); - SetInputParam("optimizer", std::string("lbfgs")); - SetInputParam("k", 5); - SetInputParam("num_basis", (int) 1); - - mlpackMain(); - - // Check that the output matrices are different. - BOOST_REQUIRE_GT( - arma::accu(CLI::GetParam("output") != output), 0); - BOOST_REQUIRE_GT(arma::accu(CLI::GetParam("transformed_data") != - transformedData), 0); -} - /** * Ensure that using a different value of max_iteration * results in a different output matrix.