Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an initial cookbook page for quadratic time mmd
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
doc/cookbook/source/examples/statistical_testing/quadratic_time_mmd.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
================== | ||
Quadratic Time MMD | ||
================== | ||
|
||
The unbiased statistic is given by | ||
|
||
.. math:: | ||
\frac{1}{n(n-1)}\sum_{i=1}^n\sum_{j=1}^n k(x_i,x_i) + k(x_j, x_j) - 2k(x_i,x_j). | ||
See :cite:`gretton2012kernel` for a detailed introduction. | ||
|
||
------- | ||
Example | ||
------- | ||
|
||
Imagine we have samples from :math:`p` and :math:`p`. We create CDenseFeatures (here 64 bit floats aka RealFeatures)as | ||
|
||
.. sgexample:: quadratic_time_mmd.sg:create_features | ||
|
||
We create an instance of :sgclass:`CQuadraticTimeMMD`, passing it data and the kernel to use, a :sgclass:`CGaussianKernel` here. | ||
|
||
.. sgexample:: quadratic_time_mmd.sg:create_instance | ||
|
||
Computing the statistic is done as | ||
|
||
.. sgexample:: quadratic_time_mmd.sg:estimate_mmd | ||
|
||
We can perform the hypothesis test as | ||
|
||
.. sgexample:: quadratic_time_mmd.sg:perform_test | ||
|
||
---------- | ||
References | ||
---------- | ||
.. bibliography:: ../../references.bib | ||
:filter: docname in docnames |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 11 additions & 2 deletions
13
examples/meta/src/statistical_testing/quadratic_time_mmd.sg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
CSVFile f_features_p("../../data/two_sample_test_gaussian.dat") | ||
CSVFile f_features_q("../../data/two_sample_test_laplace.dat") | ||
|
||
#![create_features] | ||
RealFeatures features_p(f_features_p) | ||
RealFeatures features_q(f_features_q) | ||
#![create_features] | ||
|
||
GaussianKernel kernel() | ||
|
||
#![create_instance] | ||
QuadraticTimeMMD mmd() | ||
GaussianKernel kernel() | ||
mmd.set_kernel(kernel) | ||
mmd.set_p(features_p) | ||
mmd.set_q(features_q) | ||
#![create_instance] | ||
|
||
#![estimate_mmd] | ||
Real statistic = mmd.compute_statistic() | ||
#![estimate_mmd] | ||
|
||
#![perform_test] | ||
Real alpha = 0.05 | ||
Real threshold = mmd.compute_threshold(alpha) | ||
Real p_value = mmd.compute_p_value(alpha) | ||
Real h0_rejected = mmd.perform_test(alpha) | ||
#![perform_test] | ||
|