Skip to content

Instantly share code, notes, and snippets.

@lambday
Created April 16, 2018 21:22
Show Gist options
  • Save lambday/983830beb0afeb38b9447fd91a143e67 to your computer and use it in GitHub Desktop.
Save lambday/983830beb0afeb38b9447fd91a143e67 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <shogun/base/init.h>
#include <shogun/lib/config.h>
#include <shogun/lib/SGMatrix.h>
#include <shogun/base/some.h>
#include <shogun/io/streaming/StreamingFileFromDenseFeatures.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/streaming/generators/MeanShiftDataGenerator.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/statistical_testing/QuadraticTimeMMD.h>
#include <shogun/statistical_testing/LinearTimeMMD.h>
#include <shogun/io/CSVFile.h>
#include <shogun/io/SGIO.h>
#include <algorithm>
using namespace shogun;
using namespace std;
float64_t test1()
{
auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
auto f_features_q = some<CCSVFile>("../../data/toy/two_sample_test_laplace.dat");
auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
auto features_q = some<CDenseFeatures<float64_t>>(f_features_q);
auto mmd = some<CLinearTimeMMD>(features_p, features_q);
mmd->set_num_samples_p(250);
mmd->set_num_samples_q(250);
mmd->set_num_blocks_per_burst(1000);
mmd->set_kernel(some<CGaussianKernel>(128, 8));
mmd->set_statistic_type(ST_UNBIASED_FULL);
double statistic = mmd->compute_statistic();
return statistic;
}
float64_t test2()
{
auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
auto f_features_q = some<CCSVFile>("../../data/toy/two_sample_test_laplace.dat");
auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
auto features_q = some<CDenseFeatures<float64_t>>(f_features_q);
auto streaming_features_p = some<CStreamingDenseFeatures<float64_t>>(features_p);
auto streaming_features_q = some<CStreamingDenseFeatures<float64_t>>(features_q);
auto mmd = some<CLinearTimeMMD>(streaming_features_p, streaming_features_q);
mmd->set_num_samples_p(250);
mmd->set_num_samples_q(250);
mmd->set_num_blocks_per_burst(1000);
mmd->set_kernel(some<CGaussianKernel>(128, 8));
mmd->set_statistic_type(ST_UNBIASED_FULL);
double statistic = mmd->compute_statistic();
return statistic;
}
void test3()
{
auto f_features_p = some<CCSVFile>("../../data/toy/two_sample_test_gaussian.dat");
auto features_p = some<CDenseFeatures<float64_t>>(f_features_p);
auto streaming_features_p = some<CStreamingDenseFeatures<float64_t>>(features_p);
auto to_stream = 4;
streaming_features_p->start_parser();
auto streamed_p = streaming_features_p->get_streamed_features(to_stream);
cout << streamed_p->get_num_vectors() << endl;
streaming_features_p->end_parser();
}
int main(int argc, char** argv)
{
init_shogun_with_defaults();
// get_global_io()->set_loglevel(MSG_DEBUG);
get_global_io()->set_location_info(MSG_FUNCTION);
cout << test1() << endl;
cout << test2() << endl;
test3();
exit_shogun();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment