Skip to content

Commit

Permalink
added test for hsic_gamma
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 7, 2012
1 parent 7051cc8 commit 377658c
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions examples/undocumented/libshogun/statistics_hsic.cpp
Expand Up @@ -31,35 +31,46 @@ void create_mean_data(SGMatrix<float64_t> target, float64_t difference)
}
}

/** tests the hsic statistic for a single fixed data case and ensures
* equality with matlab implementation */
void test_hsic_fixed()
void create_fixed_data_kernel(CFeatures*& features_p,
CFeatures*& features_q, CKernel*& kernel_p, CKernel*& kernel_q)
{
index_t m=2;
index_t d=3;
float64_t sigma_x=2;
float64_t sq_sigma_x_twice=sigma_x*sigma_x*2;
float64_t sigma_y=3;
float64_t sq_sigma_y_twice=sigma_y*sigma_y*2;

SGMatrix<float64_t> p(d,2*m);
for (index_t i=0; i<2*d*m; ++i)
p.matrix[i]=i;

// p.display_matrix("p");
p.display_matrix("p");

SGMatrix<float64_t> q(d,2*m);
for (index_t i=0; i<2*d*m; ++i)
q.matrix[i]=i+10;

// q.display_matrix("q");
q.display_matrix("q");

CDenseFeatures<float64_t>* features_p=new CDenseFeatures<float64_t>(p);
CDenseFeatures<float64_t>* features_q=new CDenseFeatures<float64_t>(q);
features_p=new CDenseFeatures<float64_t>(p);
features_q=new CDenseFeatures<float64_t>(q);

float64_t sigma_x=2;
float64_t sigma_y=3;
float64_t sq_sigma_x_twice=sigma_x*sigma_x*2;
float64_t sq_sigma_y_twice=sigma_y*sigma_y*2;

/* shoguns kernel width is different */
CGaussianKernel* kernel_p=new CGaussianKernel(10, sq_sigma_x_twice);
CGaussianKernel* kernel_q=new CGaussianKernel(10, sq_sigma_y_twice);
kernel_p=new CGaussianKernel(10, sq_sigma_x_twice);
kernel_q=new CGaussianKernel(10, sq_sigma_y_twice);
}

/** tests the hsic statistic for a single fixed data case and ensures
* equality with matlab implementation */
void test_hsic_fixed()
{
CFeatures* features_p=NULL;
CFeatures* features_q=NULL;
CKernel* kernel_p=NULL;
CKernel* kernel_q=NULL;
create_fixed_data_kernel(features_p, features_q, kernel_p, kernel_q);

CHSIC* hsic=new CHSIC(kernel_p, kernel_q, features_p, features_q);

Expand All @@ -71,15 +82,34 @@ void test_hsic_fixed()
SG_UNREF(hsic);
}

void test_hsic_gamma()
{
CFeatures* features_p=NULL;
CFeatures* features_q=NULL;
CKernel* kernel_p=NULL;
CKernel* kernel_q=NULL;
create_fixed_data_kernel(features_p, features_q, kernel_p, kernel_q);

CHSIC* hsic=new CHSIC(kernel_p, kernel_q, features_p, features_q);
hsic->set_null_approximation_method(HSIC_GAMMA);

hsic->compute_p_value(1);

SG_UNREF(hsic);
}

int main(int argc, char** argv)
{
init_shogun_with_defaults();

// sg_io->set_loglevel(MSG_DEBUG);

/* all tests have been "speed up" by reducing the number of runs/samples.
* If you have any doubts in the results, set all num_runs to original
* numbers and activate asserts. If they fail, something is wrong.
*/
test_hsic_fixed();
test_hsic_gamma();

exit_shogun();
return 0;
Expand Down

0 comments on commit 377658c

Please sign in to comment.