Created
March 23, 2017 06:17
-
-
Save MikeLing/5c19e062e7a689c010f0427d4c329ec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <shogun/labels/BinaryLabels.h> | |
#include <shogun/features/DenseFeatures.h> | |
#include <shogun/features/DataGenerator.h> | |
using namespace shogun; | |
class DataGenerator: public ::testing::Environment | |
{ | |
protected: | |
virtual ~DataGenerator() {} | |
virtual void SetUp() | |
{ | |
CMath::init_random(5); | |
SGMatrix<float64_t> data = CDataGenerator::generate_gaussians(100, 2, 2); | |
CDenseFeatures<float64_t> features(data); | |
SGVector<index_t> train_idx(100), test_idx(100); | |
SGVector<float64_t> labels(100); | |
for (index_t i = 0, j = 0; i < data.num_cols; ++i) | |
{ | |
if (i % 2 == 0) | |
train_idx[j] = i; | |
else | |
test_idx[j++] = i; | |
labels[i/2] = (i < data.num_cols/2) ? 1.0 : -1.0; | |
} | |
features_train = (CDenseFeatures<float64_t>*)features.copy_subset(train_idx); | |
features_test = (CDenseFeatures<float64_t>*)features.copy_subset(test_idx); | |
CBinaryLabels temp_labels = CBinaryLabels(labels); | |
labels_train = (CBinaryLabels*)temp_labels.clone(); | |
labels_test = (CBinaryLabels*)temp_labels.clone(); | |
} | |
virtual void TearDown() | |
{ | |
SG_UNREF(features_train); | |
SG_UNREF(features_test); | |
SG_UNREF(labels_train); | |
SG_UNREF(labels_test); | |
} | |
// data for training | |
CDenseFeatures<float64_t>* features_train; | |
// data for testing | |
CDenseFeatures<float64_t>* features_test; | |
// traning label | |
CBinaryLabels* labels_train; | |
// testing label | |
CBinaryLabels* labels_test; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment