Skip to content

Instantly share code, notes, and snippets.

@lambday
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambday/9371699 to your computer and use it in GitHub Desktop.
Save lambday/9371699 to your computer and use it in GitHub Desktop.
CBTestMMD : public CQuadratricTimeMMD
{
// methods
float64_t compute_statistic()
float64_t sample_null()
// data members
CStreamingFeatures m_streaming_p;
CStreamingFeatures m_streaming_q;
index_t blocksize;
}
//h(x,x',y,y')=k(x,x')+k(y,y')-k(x,y')-k(x',y)
// if there are multiple kernels, do this for every kernel and return a SGVector of statistics instead
(test_statistic, variance) CBtestMMD::compute_statistic_and_variance()
{
m = total number of samples
m2 = floor(m/blocksize)
SGVector<float64_t> statistic(m2)
for (i=0 to m2) // here m should be same for both
{
current_size = blocksize or rest of the samples, whichever is smaller
// get next blocksize number of features from streaming features p and q
p = m_streaming_p.get_streamed_features(current_size)
q = m_streaming_q.get_streamed_features(current_size)
// temporarily initialize its base class's appended feature object
m_p_and_q = p and q merged
// temporarily replace base class number of element to be used in QuadraticTimeMMD::compute_unbiased_statistic()
m_m = current_size
// handle permutation here
if (m_simulate_h0) // same as LinearTimeMMD
permute_and_shuffle(m_p_and_q) // add subset
// compute statistic
statistic[i]=QuadraticTimeMMD::compute_unbiased_statistic()
if (m_simulate_h0)
undo_permutation(m_p_and_q) // remove subset
// although no need to remove subsets, we can just unref m_p_and_q here
}
test_statistic=mean(statistic)
variance = (1 / m2) * cov(statistic)
return test_statistic, variance // to be used to fit normal cdf
}
// compute_p_value and compute_threshold would be exactly similar to LinearTimeMMD - may be make these friends??
compute_p_value()
{
if MMD1_GAUSSAIN:
compute the variance and fit normal cdf // same as LinearTimeMMD
else
call KernelTwoSampleTest::compute_p_value()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment