Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add linear time mmd api example draft
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
doc/cookbook/source/examples/statistical_testing/linear_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 @@ | ||
=============== | ||
Linear Time MMD | ||
=============== | ||
|
||
The unbiased statistic is given by | ||
|
||
.. math:: | ||
\frac{2}{n}\sum_{i=1}^n k(x_{2i},x_{2i}) + k(x_{2i+1}, x_{2i+1}) - 2k(x_{2i},x_{2i+1}). | ||
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:: linear_time_mmd.sg:create_features | ||
|
||
We create an instance of :sgclass:`CLinearTimeMMD`, passing it data and the kernel to use, a :sgclass:`CGaussianKernel` here. | ||
|
||
.. sgexample:: linear_time_mmd.sg:create_instance | ||
|
||
Computing the statistic is done as | ||
|
||
.. sgexample:: linear_time_mmd.sg:estimate_mmd | ||
|
||
We can perform the hypothesis test as | ||
|
||
.. sgexample:: linear_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![create_features] | ||
GaussianBlobsDataGenerator features_p() | ||
GaussianBlobsDataGenerator features_q() | ||
#![create_features] | ||
|
||
#![create_instance] | ||
LinearTimeMMD 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] |