index_max() and fix to test

This commit is contained in:
Ayush
2019-04-07 22:05:07 -04:00
committed by Ryan Curtin
parent b98027ff4a
commit 2e32b5c298
2 changed files with 18 additions and 6 deletions
@@ -95,6 +95,18 @@ const
{
Classify(data, scores);
#if ARMA_VERSION_MAJOR > 7 || ARMA_VERSION_MAJOR == 7 \
&& ARMA_VERSION_MINOR >= 300
// Prepare necessary data
labels.zeros(data.n_cols);
labels = arma::conv_to<arma::Row<size_t>>::from(
arma::index_max(scores));
#else
// Once the minimum version is Armadillo is increased, remove this part.
// Prepare necessary data
labels.zeros(data.n_cols);
double maxScore = 0;
@@ -116,6 +128,7 @@ const
// Set maximum probability to zero for next input.
maxScore = 0;
}
#endif
}
template <typename MatType>
+5 -6
View File
@@ -573,9 +573,8 @@ BOOST_AUTO_TEST_CASE(LinearSVMFitIntercept)
const double delta = 1.0;
// Generate a two-Gaussian dataset,
// which can't be separated without adding the intercept term.
GaussianDistribution g1(arma::vec("1.0 1.0 1.0"), arma::eye<arma::mat>(3, 3));
GaussianDistribution g2(arma::vec("9.0 9.0 9.0"), arma::eye<arma::mat>(3, 3));
GaussianDistribution g1(arma::vec("1.0 9.0 1.0"), arma::eye<arma::mat>(3, 3));
GaussianDistribution g2(arma::vec("4.0 3.0 4.0"), arma::eye<arma::mat>(3, 3));
arma::mat data(inputSize, points);
arma::Row<size_t> labels(points);
@@ -710,7 +709,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMPSGDSimpleTest)
// Compare training accuracy to 1.
const double acc = lsvm.ComputeAccuracy(dataset, labels);
BOOST_REQUIRE_CLOSE(acc, 1.0, 0.5);
BOOST_REQUIRE_CLOSE(acc, 1.0, 1.0);
}
/**
@@ -756,7 +755,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses)
// Compare training accuracy to 1.
const double acc = lsvm.ComputeAccuracy(data, labels);
BOOST_REQUIRE_CLOSE(acc, 1.0, 0.5);
BOOST_REQUIRE_CLOSE(acc, 1.0, 1.0);
// Create test dataset.
for (size_t i = 0; i < points / 2; i++)
@@ -772,7 +771,7 @@ BOOST_AUTO_TEST_CASE(LinearSVMParallelSGDTwoClasses)
// Compare test accuracy to 1.
const double testAcc = lsvm.ComputeAccuracy(data, labels);
BOOST_REQUIRE_CLOSE(testAcc, 1.0, 0.6);
BOOST_REQUIRE_CLOSE(testAcc, 1.0, 1.0);
}
#endif