Skip to content

Commit

Permalink
removed MultiKernelMMD class, put in ComputeMMD class itself
Browse files Browse the repository at this point in the history
  • Loading branch information
lambday committed Jul 13, 2016
1 parent fe8ee29 commit 6816e7e
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 103 deletions.
Expand Up @@ -37,7 +37,7 @@
#include <shogun/statistical_testing/MultiKernelQuadraticTimeMMD.h>
#include <shogun/statistical_testing/internals/FeaturesUtil.h>
#include <shogun/statistical_testing/internals/KernelManager.h>
#include <shogun/statistical_testing/internals/mmd/MultiKernelMMD.h>
#include <shogun/statistical_testing/internals/mmd/ComputeMMD.h>
#include <shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.h>

using namespace shogun;
Expand All @@ -54,6 +54,7 @@ struct CMultiKernelQuadraticTimeMMD::Self
unique_ptr<CCustomDistance> m_pairwise_distance;
EDistanceType m_dtype;
KernelManager m_kernel_mgr;
ComputeMMD compute_mmd;
};

CMultiKernelQuadraticTimeMMD::Self::Self(CQuadraticTimeMMD *owner) : m_owner(owner),
Expand Down Expand Up @@ -158,8 +159,10 @@ SGVector<float64_t> CMultiKernelQuadraticTimeMMD::statistic(const KernelManager&
kernel_mgr.set_precomputed_distance(self->m_pairwise_distance.get());
SG_UNREF(distance);

MultiKernelMMD compute(nx, ny, stype);
SGVector<float64_t> result=compute(kernel_mgr);
self->compute_mmd.m_n_x=nx;
self->compute_mmd.m_n_y=ny;
self->compute_mmd.m_stype=stype;
SGVector<float64_t> result=self->compute_mmd(kernel_mgr);

kernel_mgr.unset_precomputed_distance();

Expand Down
2 changes: 0 additions & 2 deletions src/shogun/statistical_testing/QuadraticTimeMMD.cpp
Expand Up @@ -49,8 +49,6 @@
#include <shogun/statistical_testing/internals/mmd/ComputeMMD.h>
#include <shogun/statistical_testing/internals/mmd/FullDirect.h>
#include <shogun/statistical_testing/internals/mmd/WithinBlockPermutationBatch.h>
#include <shogun/statistical_testing/internals/mmd/MultiKernelMMD.h>
#include <shogun/statistical_testing/internals/mmd/MultiKernelPermutationTest.h>
#include <shogun/statistical_testing/kernelselection/KernelSelectionStrategy.h>

using namespace shogun;
Expand Down
31 changes: 31 additions & 0 deletions src/shogun/statistical_testing/internals/mmd/ComputeMMD.h
Expand Up @@ -32,9 +32,13 @@
#define COMPUTE_MMD_H_

#include <array>
#include <vector>
#include <shogun/io/SGIO.h>
#include <shogun/lib/config.h>
#include <shogun/lib/SGVector.h>
#include <shogun/kernel/Kernel.h>
#include <shogun/statistical_testing/MMD.h>
#include <shogun/statistical_testing/internals/KernelManager.h>
#include <shogun/mathematics/eigen3.h>

namespace shogun
Expand Down Expand Up @@ -89,6 +93,33 @@ struct ComputeMMD
return static_cast<T>(compute(terms));
}

SGVector<float64_t> operator()(const KernelManager& kernel_mgr) const
{
ASSERT(m_n_x>0 && m_n_y>0);
std::vector<terms_t> terms(kernel_mgr.num_kernels());
const index_t size=m_n_x+m_n_y;
for (auto j=0; j<size; ++j)
{
for (auto i=j; i<size; ++i)
{
for (size_t k=0; k<kernel_mgr.num_kernels(); ++k)
{
auto kernel=kernel_mgr.kernel_at(k)->kernel(i, j);
add_term(terms[k], kernel, i, j);
}
}
}

SGVector<float64_t> result(kernel_mgr.num_kernels());
for (size_t k=0; k<kernel_mgr.num_kernels(); ++k)
{
result[k]=compute(terms[k]);
SG_SDEBUG("result[%d] = %f!\n", k, result[k]);
}
terms.resize(0);
return result;
}

template <typename T>
inline void add_term(terms_t& terms, T kernel_value, index_t i, index_t j) const
{
Expand Down
94 changes: 0 additions & 94 deletions src/shogun/statistical_testing/internals/mmd/MultiKernelMMD.h

This file was deleted.

Expand Up @@ -41,7 +41,7 @@
#include <shogun/mathematics/eigen3.h>
#include <shogun/statistical_testing/TwoDistributionTest.h>
#include <shogun/statistical_testing/internals/KernelManager.h>
#include <shogun/statistical_testing/internals/mmd/MultiKernelMMD.h>
#include <shogun/statistical_testing/internals/mmd/ComputeMMD.h>
#include <gtest/gtest.h>
#include <gmock/gmock.h>

Expand Down Expand Up @@ -88,7 +88,10 @@ TEST(MultiKernelMMD, biased_full)
auto distance=kernel_mgr.get_distance_instance();
kernel_mgr.set_precomputed_distance(test->compute_joint_distance(distance));

MultiKernelMMD tester(m, n, stype);
ComputeMMD tester;
tester.m_n_x=m;
tester.m_n_y=n;
tester.m_stype=stype;
SGVector<float64_t> values=tester(kernel_mgr);
kernel_mgr.unset_precomputed_distance();

Expand Down Expand Up @@ -150,7 +153,10 @@ TEST(MultiKernelMMD, unbiased_full)
auto distance=kernel_mgr.get_distance_instance();
kernel_mgr.set_precomputed_distance(test->compute_joint_distance(distance));

MultiKernelMMD tester(m, n, stype);
ComputeMMD tester;
tester.m_n_x=m;
tester.m_n_y=n;
tester.m_stype=stype;
SGVector<float64_t> values=tester(kernel_mgr);
kernel_mgr.unset_precomputed_distance();

Expand Down Expand Up @@ -212,7 +218,10 @@ TEST(MultiKernelMMD, unbiased_incomplete)
auto distance=kernel_mgr.get_distance_instance();
kernel_mgr.set_precomputed_distance(test->compute_joint_distance(distance));

MultiKernelMMD tester(m, n, stype);
ComputeMMD tester;
tester.m_n_x=m;
tester.m_n_y=n;
tester.m_stype=stype;
SGVector<float64_t> values=tester(kernel_mgr);
kernel_mgr.unset_precomputed_distance();

Expand Down

0 comments on commit 6816e7e

Please sign in to comment.