Skip to content

Commit

Permalink
Add an initial cookbook page for quadratic time mmd
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 4, 2016
1 parent a00d19c commit 919a51e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
@@ -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
9 changes: 9 additions & 0 deletions doc/cookbook/source/index.rst
Expand Up @@ -32,6 +32,15 @@ Regression

examples/regression/**

Statistical Testing
-------------------

.. toctree::
:maxdepth: 1
:glob:

examples/statistical_testing/**

Kernels
-------

Expand Down
13 changes: 13 additions & 0 deletions doc/cookbook/source/references.bib
Expand Up @@ -16,13 +16,26 @@ @article{fan2008liblinear
journal={The Journal of Machine Learning Research},
volume={9},
pages={1871--1874},
<<<<<<< bcd4d7fdaeb804f05bc0d0f0c1f66ae81e7e2ba3
year={2008}
}
@book{Rasmussen2005GPM,
author = {Rasmussen, C. E. and Williams, C. K. I.},
title = {Gaussian Processes for Machine Learning (Adaptive Computation and Machine Learning)},
year = {2005},
publisher = {The MIT Press}
=======
year={2008},

@article{gretton2012kernel,
title={A kernel two-sample test},
author={Gretton, A. and Borgwardt, K.M. and Rasch, M.J. and Sch{\"o}lkopf, B. and Smola, A.},
journal={The Journal of Machine Learning Research},
volume={13},
number={1},
pages={723--773},
year={2012},
>>>>>>> Add an initial cookbook page for quadratic time mmd
}
@article{ueda2000smem,
title={SMEM Algorithm for Mixture Models},
Expand Down
13 changes: 11 additions & 2 deletions examples/meta/src/statistical_testing/quadratic_time_mmd.sg
@@ -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]

0 comments on commit 919a51e

Please sign in to comment.