Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <shogun/statistics/KernelTwoSampleTestStatistic.h>
00011 #include <shogun/features/Features.h>
00012 #include <shogun/kernel/Kernel.h>
00013 #include <shogun/kernel/CustomKernel.h>
00014
00015 using namespace shogun;
00016
00017 CKernelTwoSampleTestStatistic::CKernelTwoSampleTestStatistic() :
00018 CTwoDistributionsTestStatistic()
00019 {
00020 init();
00021 }
00022
00023 CKernelTwoSampleTestStatistic::CKernelTwoSampleTestStatistic(CKernel* kernel,
00024 CFeatures* p_and_q, index_t q_start) :
00025 CTwoDistributionsTestStatistic(p_and_q, q_start)
00026 {
00027 init();
00028
00029 m_kernel=kernel;
00030 SG_REF(kernel);
00031 }
00032
00033 CKernelTwoSampleTestStatistic::CKernelTwoSampleTestStatistic(CKernel* kernel,
00034 CFeatures* p, CFeatures* q) : CTwoDistributionsTestStatistic(p, q)
00035 {
00036 init();
00037
00038 m_kernel=kernel;
00039 SG_REF(kernel);
00040
00041
00042 m_kernel->init(m_p_and_q, m_p_and_q);
00043 }
00044
00045 CKernelTwoSampleTestStatistic::~CKernelTwoSampleTestStatistic()
00046 {
00047 SG_UNREF(m_kernel);
00048 }
00049
00050 void CKernelTwoSampleTestStatistic::init()
00051 {
00052 SG_ADD((CSGObject**)&m_kernel, "kernel", "Kernel for two sample test",
00053 MS_AVAILABLE);
00054 m_kernel=NULL;
00055 }
00056
00057 SGVector<float64_t> CKernelTwoSampleTestStatistic::bootstrap_null()
00058 {
00059
00060 SGVector<float64_t> results;
00061
00062
00063
00064
00065 if (m_kernel->get_kernel_type()==K_CUSTOM)
00066 {
00067
00068 results=SGVector<float64_t>(m_bootstrap_iterations);
00069
00070
00071 SGVector<index_t> ind_permutation(m_p_and_q->get_num_vectors());
00072 ind_permutation.range_fill();
00073
00074
00075
00076 CCustomKernel* custom_kernel=(CCustomKernel*)m_kernel;
00077
00078 for (index_t i=0; i<m_bootstrap_iterations; ++i)
00079 {
00080
00081
00082
00083
00084 SGVector<int32_t>::permute_vector(ind_permutation);
00085
00086 custom_kernel->add_row_subset(ind_permutation);
00087 custom_kernel->add_col_subset(ind_permutation);
00088
00089
00090 results[i]=compute_statistic();
00091
00092
00093 custom_kernel->remove_row_subset();
00094 custom_kernel->remove_col_subset();
00095 }
00096 }
00097 else
00098 {
00099
00100 results=CTwoDistributionsTestStatistic::bootstrap_null();
00101 }
00102
00103 return results;
00104 }