Guest User

Untitled

a guest
Apr 24th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <shogun/base/init.h>
  3. #include <shogun/lib/config.h>
  4. #include <shogun/lib/SGMatrix.h>
  5. #include <shogun/base/some.h>
  6. #include <shogun/io/streaming/StreamingFileFromDenseFeatures.h>
  7. #include <shogun/features/DenseFeatures.h>
  8. #include <shogun/features/streaming/generators/MeanShiftDataGenerator.h>
  9. #include <shogun/kernel/GaussianKernel.h>
  10. #include <shogun/statistical_testing/QuadraticTimeMMD.h>
  11. #include <shogun/statistical_testing/LinearTimeMMD.h>
  12. #include <shogun/io/CSVFile.h>
  13. #include <shogun/io/SGIO.h>
  14. #include <algorithm>
  15.  
  16. using namespace shogun;
  17. using namespace std;
  18.  
  19. float64_t test1()
  20. {
  21. auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
  22. auto f_features_q = some<CCSVFile>("../../data/toy/two_sample_test_laplace.dat");
  23.  
  24. auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
  25. auto features_q = some<CDenseFeatures<float64_t>>(f_features_q);
  26.  
  27. auto mmd = some<CLinearTimeMMD>(features_p, features_q);
  28. mmd->set_num_samples_p(250);
  29. mmd->set_num_samples_q(250);
  30. mmd->set_num_blocks_per_burst(1000);
  31. mmd->set_kernel(some<CGaussianKernel>(128, 8));
  32. mmd->set_statistic_type(ST_UNBIASED_FULL);
  33. double statistic = mmd->compute_statistic();
  34.  
  35. return statistic;
  36. }
  37.  
  38. float64_t test2()
  39. {
  40. auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
  41. auto f_features_q = some<CCSVFile>("../../data/toy/two_sample_test_laplace.dat");
  42.  
  43. auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
  44. auto features_q = some<CDenseFeatures<float64_t>>(f_features_q);
  45.  
  46. auto streaming_features_p = some<CStreamingDenseFeatures<float64_t>>(features_p);
  47. auto streaming_features_q = some<CStreamingDenseFeatures<float64_t>>(features_q);
  48.  
  49. auto mmd = some<CLinearTimeMMD>(streaming_features_p, streaming_features_q);
  50. mmd->set_num_samples_p(250);
  51. mmd->set_num_samples_q(250);
  52. mmd->set_num_blocks_per_burst(1000);
  53. mmd->set_kernel(some<CGaussianKernel>(128, 8));
  54. mmd->set_statistic_type(ST_UNBIASED_FULL);
  55. double statistic = mmd->compute_statistic();
  56.  
  57. return statistic;
  58. }
  59.  
  60. void test3()
  61. {
  62. auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
  63. auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
  64. auto streaming_features_p = some<CStreamingDenseFeatures<float64_t>>(features_p);
  65.  
  66. auto to_stream = 4;
  67. streaming_features_p->start_parser();
  68.  
  69. auto streamed_p = streaming_features_p->get_streamed_features(to_stream);
  70. cout << streamed_p->get_num_vectors() << endl;
  71.  
  72. streaming_features_p->end_parser();
  73. }
  74.  
  75. int main(int argc, char** argv)
  76. {
  77. init_shogun_with_defaults();
  78. // get_global_io()->set_loglevel(MSG_DEBUG);
  79. get_global_io()->set_location_info(MSG_FUNCTION);
  80. cout << test1() << endl;
  81. cout << test2() << endl;
  82. test3();
  83. exit_shogun();
  84. return 0;
  85. }
Add Comment
Please, Sign In to add comment