Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add unittest for SVM Light #3711

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions tests/unit/classifier/svm/SVMLight_unittest.cc
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2016, Shogun-Toolbox e.V. <shogun-team@shogun-toolbox.org>
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Authors: 2016 MikeLing, Viktor Gal, Sergey Lisitsyn, Heiko Strathmann
*/

#include <gtest/gtest.h>
#include <shogun/classifier/svm/SVMLight.h>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license missing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

#include <shogun/evaluation/ContingencyTableEvaluation.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/kernel/GaussianKernel.h>

#include "environments/LinearTestEnvironment.h"

using namespace shogun;
#ifdef USE_SVMLIGHT
TEST(SVMLight, train)
{
auto C = 1.0;
auto epsilon = 0.001;
std::shared_ptr<GaussianCheckerboard> mockData =
LinearTestEnvironment::instance().getBinaryLabelData();

CDenseFeatures<float64_t>* train_feats = mockData->get_features_train();
CDenseFeatures<float64_t>* test_feats = mockData->get_features_test();

CBinaryLabels* ground_truth = (CBinaryLabels*)mockData->get_labels_train();

CGaussianKernel* gauss_kernel =
new CGaussianKernel(train_feats, train_feats, 15);
CSVMLight* svml = new CSVMLight(C, gauss_kernel, ground_truth);

svml->set_epsilon(epsilon);
svml->train();

CLabels* pred = svml->apply(test_feats);

CAccuracyMeasure evaluate = CAccuracyMeasure();
evaluate.evaluate(pred, mockData->get_labels_test());
EXPECT_GT(evaluate.get_accuracy(), 0.99);

SG_UNREF(svml);
SG_UNREF(pred);
}
#endif // USE_SVMLIGHT
2 changes: 1 addition & 1 deletion tests/unit/classifier/svm/SVMOcas_unittest.cc
Expand Up @@ -20,7 +20,7 @@ TEST(SVMOcasTest,train)
CDenseFeatures<float64_t>* train_feats = mockData->get_features_train();
CDenseFeatures<float64_t>* test_feats = mockData->get_features_test();

CBinaryLabels* ground_truth = (CBinaryLabels*)mockData->get_labels_test();
CBinaryLabels* ground_truth = (CBinaryLabels*)mockData->get_labels_train();

CSVMOcas* ocas = new CSVMOcas(1.0, train_feats, ground_truth);
ocas->parallel->set_num_threads(1);
Expand Down