Skip to content

Commit

Permalink
make use of new data generator
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 22, 2012
1 parent 3d23819 commit 1b70388
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions examples/undocumented/libshogun/statistics_quadratic_time_mmd.cpp
Expand Up @@ -12,25 +12,10 @@
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/mathematics/Statistics.h>
#include <shogun/features/DataGenerator.h>

using namespace shogun;


void create_mean_data(SGMatrix<float64_t> target, float64_t difference)
{
/* create data matrix for P and Q. P is a standard normal, Q is the same but
* has a mean difference in one dimension */
for (index_t i=0; i<target.num_rows; ++i)
{
for (index_t j=0; j<target.num_cols/2; ++j)
target(i,j)=CMath::randn_double();

/* add mean difference in first dimension of second half of data */
for (index_t j=target.num_cols/2; j<target.num_cols; ++j)
target(i,j)=CMath::randn_double() + (i==0 ? difference : 0);
}
}

/** tests the quadratic mmd statistic for a single data case and ensures
* equality with matlab implementation */
void test_quadratic_mmd_fixed()
Expand Down Expand Up @@ -73,8 +58,8 @@ void test_quadratic_mmd_bootstrap()
index_t num_iterations=1000;
num_iterations=10; //speed up

SGMatrix<float64_t> data(dimension, 2*m);
create_mean_data(data, difference);
SGMatrix<float64_t> data=CDataGenerator::generate_mean_data(m, dimension,
difference);
CDenseFeatures<float64_t>* features=new CDenseFeatures<float64_t>(data);

/* shoguns kernel width is different */
Expand Down Expand Up @@ -112,8 +97,8 @@ void test_quadratic_mmd_spectrum()
float64_t difference=0.5;
float64_t sigma=2;

SGMatrix<float64_t> data(dimension, 2*m);
create_mean_data(data, difference);
SGMatrix<float64_t> data=CDataGenerator::generate_mean_data(m, dimension,
difference);

CDenseFeatures<float64_t>* features=new CDenseFeatures<float64_t>(data);

Expand Down Expand Up @@ -185,8 +170,8 @@ void test_quadratic_mmd_random()
num_runs=10; //speed up
SGVector<float64_t> mmds(num_runs);

/* pre-allocate data matrix and features, just change elements later */
SGMatrix<float64_t> data(dimension, 2*m);

CDenseFeatures<float64_t>* features=new CDenseFeatures<float64_t>(data);

/* shoguns kernel width is different */
Expand All @@ -195,7 +180,9 @@ void test_quadratic_mmd_random()
mmd->set_statistic_type(UNBIASED);
for (index_t i=0; i<num_runs; ++i)
{
create_mean_data(data, difference);
/* use pre-allocated space for data generation */
CDataGenerator::generate_mean_data(m, dimension,
difference, data.matrix);
kernel->init(features, features);
mmds[i]=mmd->compute_statistic();
}
Expand Down

0 comments on commit 1b70388

Please sign in to comment.