forked from shogun-toolbox/shogun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVMOcas_unittest.cc
43 lines (32 loc) · 1.2 KB
/
SVMOcas_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <shogun/classifier/svm/SVMOcas.h>
#include <shogun/evaluation/ContingencyTableEvaluation.h>
#include <shogun/features/DataGenerator.h>
#include <shogun/features/DenseFeatures.h>
#include <gtest/gtest.h>
#include "environments/LinearTestEnvironment.h"
using namespace shogun;
#ifdef USE_GPL_SHOGUN
#ifdef HAVE_LAPACK
TEST(SVMOcasTest,train)
{
CMath::init_random(5);
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();
CSVMOcas* ocas = new CSVMOcas(1.0, train_feats, ground_truth);
ocas->parallel->set_num_threads(1);
ocas->set_epsilon(1e-5);
ocas->train();
float64_t objective = ocas->compute_primal_objective();
EXPECT_NEAR(objective, 0.024344632618686062, 1e-2);
CLabels* pred = ocas->apply(test_feats);
CAccuracyMeasure evaluate = CAccuracyMeasure();
evaluate.evaluate(pred, ground_truth);
EXPECT_GT(evaluate.get_accuracy(), 0.99);
SG_UNREF(ocas);
SG_UNREF(pred);
}
#endif // HAVE_LAPACK
#endif //USE_GPL_SHOGUN