Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <shogun/statistics/KernelIndependenceTestStatistic.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 CKernelIndependenceTestStatistic::CKernelIndependenceTestStatistic() :
00018 CTwoDistributionsTestStatistic()
00019 {
00020 init();
00021 }
00022
00023 CKernelIndependenceTestStatistic::CKernelIndependenceTestStatistic(
00024 CKernel* kernel_p, CKernel* kernel_q, CFeatures* p_and_q,
00025 index_t q_start) : CTwoDistributionsTestStatistic(m_p_and_q, q_start)
00026 {
00027 init();
00028
00029 m_kernel_p=kernel_p;
00030 m_kernel_q=kernel_q;
00031 SG_REF(kernel_p);
00032 SG_REF(kernel_q);
00033 }
00034
00035 CKernelIndependenceTestStatistic::CKernelIndependenceTestStatistic(
00036 CKernel* kernel_p, CKernel* kernel_q, CFeatures* p, CFeatures* q) :
00037 CTwoDistributionsTestStatistic(p, q)
00038 {
00039 init();
00040
00041 m_kernel_p=kernel_p;
00042 SG_REF(kernel_p);
00043
00044 m_kernel_q=kernel_q;
00045 SG_REF(kernel_q);
00046 }
00047
00048 CKernelIndependenceTestStatistic::~CKernelIndependenceTestStatistic()
00049 {
00050 SG_UNREF(m_kernel_p);
00051 SG_UNREF(m_kernel_q);
00052 }
00053
00054 void CKernelIndependenceTestStatistic::init()
00055 {
00056 SG_ADD((CSGObject**)&m_kernel_p, "kernel_p", "Kernel for samples from p",
00057 MS_AVAILABLE);
00058 SG_ADD((CSGObject**)&m_kernel_q, "kernel_q", "Kernel for samples from q",
00059 MS_AVAILABLE);
00060 m_kernel_p=NULL;
00061 m_kernel_q=NULL;
00062 }
00063
00064 SGVector<float64_t> CKernelIndependenceTestStatistic::bootstrap_null()
00065 {
00066 SG_DEBUG("entering CKernelIndependenceTestStatistic::bootstrap_null()\n");
00067
00068
00069 SGVector<float64_t> results;
00070
00071
00072
00073
00074 if (m_kernel_p->get_kernel_type()==K_CUSTOM &&
00075 m_kernel_q->get_kernel_type()==K_CUSTOM)
00076 {
00077
00078 results=SGVector<float64_t>(m_bootstrap_iterations);
00079
00080
00081 SGVector<index_t> ind_permutation(m_p_and_q->get_num_vectors());
00082 ind_permutation.range_fill();
00083
00084
00085
00086 CCustomKernel* custom_kernel_p=(CCustomKernel*)m_kernel_p;
00087 CCustomKernel* custom_kernel_q=(CCustomKernel*)m_kernel_q;
00088
00089 for (index_t i=0; i<m_bootstrap_iterations; ++i)
00090 {
00091
00092
00093
00094
00095 SGVector<int32_t>::permute_vector(ind_permutation);
00096
00097 custom_kernel_p->add_row_subset(ind_permutation);
00098 custom_kernel_p->add_col_subset(ind_permutation);
00099 custom_kernel_q->add_row_subset(ind_permutation);
00100 custom_kernel_q->add_col_subset(ind_permutation);
00101
00102
00103 results[i]=compute_statistic();
00104
00105
00106 custom_kernel_p->remove_row_subset();
00107 custom_kernel_p->remove_col_subset();
00108 custom_kernel_q->remove_row_subset();
00109 custom_kernel_q->remove_col_subset();
00110 }
00111 }
00112 else
00113 {
00114
00115 results=CTwoDistributionsTestStatistic::bootstrap_null();
00116 }
00117
00118
00119 SG_DEBUG("leaving CKernelIndependenceTestStatistic::bootstrap_null()\n");
00120 return results;
00121 }
00122