Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add linear time mmd api example draft
  • Loading branch information
karlnapf committed Mar 29, 2016
1 parent 05b6e61 commit fcee3d0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
@@ -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
23 changes: 23 additions & 0 deletions examples/meta/src/statistical_testing/linear_time_mmd.sg
@@ -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]

0 comments on commit fcee3d0

Please sign in to comment.