Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <shogun/labels/BinaryLabels.h>
  2. #include <shogun/features/DenseFeatures.h>
  3. #include <shogun/features/DataGenerator.h>
  4.  
  5. using namespace shogun;
  6.  
  7. class DataGenerator: public ::testing::Environment
  8. {
  9. protected:
  10. virtual ~DataGenerator() {}
  11. virtual void SetUp()
  12. {
  13. CMath::init_random(5);
  14. SGMatrix<float64_t> data = CDataGenerator::generate_gaussians(100, 2, 2);
  15. CDenseFeatures<float64_t> features(data);
  16.  
  17. SGVector<index_t> train_idx(100), test_idx(100);
  18. SGVector<float64_t> labels(100);
  19. for (index_t i = 0, j = 0; i < data.num_cols; ++i)
  20. {
  21. if (i % 2 == 0)
  22. train_idx[j] = i;
  23. else
  24. test_idx[j++] = i;
  25.  
  26. labels[i/2] = (i < data.num_cols/2) ? 1.0 : -1.0;
  27. }
  28.  
  29. features_train = (CDenseFeatures<float64_t>*)features.copy_subset(train_idx);
  30. features_test = (CDenseFeatures<float64_t>*)features.copy_subset(test_idx);
  31.  
  32. CBinaryLabels temp_labels = CBinaryLabels(labels);
  33. labels_train = (CBinaryLabels*)temp_labels.clone();
  34. labels_test = (CBinaryLabels*)temp_labels.clone();
  35. }
  36.  
  37. virtual void TearDown()
  38. {
  39. SG_UNREF(features_train);
  40. SG_UNREF(features_test);
  41. SG_UNREF(labels_train);
  42. SG_UNREF(labels_test);
  43. }
  44.  
  45. // data for training
  46. CDenseFeatures<float64_t>* features_train;
  47.  
  48. // data for testing
  49. CDenseFeatures<float64_t>* features_test;
  50.  
  51. // traning label
  52. CBinaryLabels* labels_train;
  53.  
  54. // testing label
  55. CBinaryLabels* labels_test;
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement