src/mlpack/tests/main_tests/adaboost_test.cpp
BOOST_AUTO_TEST_CASE(AdaBoostDiffItrTest)
{
  arma::mat trainData;
  if (!data::Load("vc2.csv", trainData))
    BOOST_FAIL("Unable to load train dataset vc2.csv!");

  arma::Row<size_t> labels;
  if (!data::Load("vc2_labels.txt", labels))
    BOOST_FAIL("Unable to load label dataset vc2_labels.txt!");

  arma::mat testData;
  if (!data::Load("vc2_test.csv", testData))
    BOOST_FAIL("Unable to load test dataset vc2.csv!");

  arma::Row<size_t> testLabels;
  if (!data::Load("vc2_test_labels.txt", testLabels))
    BOOST_FAIL("Unable to load labels for vc2__test_labels.txt");

  // Iterations = 1
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 1);

  mlpackMain();

  // Calculate accuracy.
  arma::Row<size_t> output;
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);

  size_t correct = arma::accu(output == testLabels);
  double accuracy1 = (double(correct) / double(testLabels.n_elem) * 100);

  bindings::tests::CleanMemory();

  // Iterations = 10
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 10);

  mlpackMain();

  // Calculate accuracy.
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);

  correct = arma::accu(output == testLabels);
  double accuracy10 = (double(correct) / double(testLabels.n_elem) * 100);

  bindings::tests::CleanMemory();

  // Iterations = 100
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 100);

  mlpackMain();

  // Calculate accuracy.
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);

  correct = arma::accu(output == testLabels);
  double accuracy100 = (double(correct) / double(testLabels.n_elem) * 100);

  BOOST_REQUIRE_LE(accuracy1, accuracy10);
  BOOST_REQUIRE_LE(accuracy10, accuracy100);
}
/**
 * Accuracy increases as Number of Iterations increases.
 * (Or converges and remains same)
 */
Accuracy increases as Number of Iterations increases.
(Or converges and remains same)
Accuracy increases as Number of Iterations increases . ( Or converges and remains same )
BOOST_AUTO_TEST_CASE(AdaBoostDiffItrTest)
{
  arma::mat trainData;
  if (!data::Load("vc2.csv", trainData))
    BOOST_FAIL("Unable to load train dataset vc2.csv!");
  arma::Row<size_t> labels;
  if (!data::Load("vc2_labels.txt", labels))
    BOOST_FAIL("Unable to load label dataset vc2_labels.txt!");
  arma::mat testData;
  if (!data::Load("vc2_test.csv", testData))
    BOOST_FAIL("Unable to load test dataset vc2.csv!");
  arma::Row<size_t> testLabels;
  if (!data::Load("vc2_test_labels.txt", testLabels))
    BOOST_FAIL("Unable to load labels for vc2__test_labels.txt");
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 1);
  mlpackMain();
  arma::Row<size_t> output;
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);
  size_t correct = arma::accu(output == testLabels);
  double accuracy1 = (double(correct) / double(testLabels.n_elem) * 100);
  bindings::tests::CleanMemory();
  0
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 10);
  mlpackMain();
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);
  correct = arma::accu(output == testLabels);
  double accuracy10 = (double(correct) / double(testLabels.n_elem) * 100);
  bindings::tests::CleanMemory();
  00
  SetInputParam("training", trainData);
  SetInputParam("labels", labels);
  SetInputParam("weak_learner", std::string("perceptron"));
  SetInputParam("iterations", (int) 100);
  mlpackMain();
  CLI::GetParam<AdaBoostModel*>("output_model")->Classify(testData,
       output);
  correct = arma::accu(output == testLabels);
  double accuracy100 = (double(correct) / double(testLabels.n_elem) * 100);
  BOOST_REQUIRE_LE(accuracy1, accuracy10);
  BOOST_REQUIRE_LE(accuracy10, accuracy100);
}
BOOST_AUTO_TEST_CASE ( AdaBoostDiffItrTest ) { arma :: mat trainData ; if ( ! data :: Load ( " " , trainData ) ) BOOST_FAIL ( " " ) ; arma :: Row < size_t > labels ; if ( ! data :: Load ( " " , labels ) ) BOOST_FAIL ( " " ) ; arma :: mat testData ; if ( ! data :: Load ( " " , testData ) ) BOOST_FAIL ( " " ) ; arma :: Row < size_t > testLabels ; if ( ! data :: Load ( " " , testLabels ) ) BOOST_FAIL ( " " ) ; SetInputParam ( " " , trainData ) ; SetInputParam ( " " , labels ) ; SetInputParam ( " " , std :: string ( " " ) ) ; SetInputParam ( " " , ( int ) 1 ) ; mlpackMain ( ) ; arma :: Row < size_t > output ; CLI :: GetParam < AdaBoostModel * > ( " " ) -> Classify ( testData , output ) ; size_t correct = arma :: accu ( output == testLabels ) ; double accuracy1 = ( double ( correct ) / double ( testLabels . n_elem ) * 100 ) ; bindings :: tests :: CleanMemory ( ) ; SetInputParam ( " " , trainData ) ; SetInputParam ( " " , labels ) ; SetInputParam ( " " , std :: string ( " " ) ) ; SetInputParam ( " " , ( int ) 10 ) ; mlpackMain ( ) ; CLI :: GetParam < AdaBoostModel * > ( " " ) -> Classify ( testData , output ) ; correct = arma :: accu ( output == testLabels ) ; double accuracy10 = ( double ( correct ) / double ( testLabels . n_elem ) * 100 ) ; bindings :: tests :: CleanMemory ( ) ; SetInputParam ( " " , trainData ) ; SetInputParam ( " " , labels ) ; SetInputParam ( " " , std :: string ( " " ) ) ; SetInputParam ( " " , ( int ) 100 ) ; mlpackMain ( ) ; CLI :: GetParam < AdaBoostModel * > ( " " ) -> Classify ( testData , output ) ; correct = arma :: accu ( output == testLabels ) ; double accuracy100 = ( double ( correct ) / double ( testLabels . n_elem ) * 100 ) ; BOOST_REQUIRE_LE ( accuracy1 , accuracy10 ) ; BOOST_REQUIRE_LE ( accuracy10 , accuracy100 ) ; }
Accuracy increases as Number of Iterations increases.
Accuracy increases as Number of Iterations increases .
// Iterations = 1 // Calculate accuracy. // Iterations = 10 // Calculate accuracy. // Iterations = 100 // Calculate accuracy.