Skip to content

Commit

Permalink
Merge pull request #621 from karlnapf/master
Browse files Browse the repository at this point in the history
HSIC statistic, fixes and new interfaces
  • Loading branch information
karlnapf committed Jul 4, 2012
2 parents af1733e + 0fc3472 commit caa554c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/interfaces/modular/Statistics.i
Expand Up @@ -13,10 +13,16 @@
%rename(KernelTwoSampleTestStatistic) CKernelTwoSampleTestStatistic;
%rename(LinearTimeMMD) CLinearTimeMMD;
%rename(QuadraticTimeMMD) CQuadraticTimeMMD;
%rename(IndependenceTestStatistic) CIndependenceTestStatistic;
%rename(KernelIndependenceTestStatistic) CKernelIndependenceTestStatistic;
%rename(HSIC) CHSIC;

/* Include Class Headers to make them visible from within the target language */
%include <shogun/statistics/TestStatistic.h>
%include <shogun/statistics/TwoSampleTestStatistic.h>
%include <shogun/statistics/KernelTwoSampleTestStatistic.h>
%include <shogun/statistics/LinearTimeMMD.h>
%include <shogun/statistics/QuadraticTimeMMD.h>
%include <shogun/statistics/IndependenceTestStatistic.h>
%include <shogun/statistics/KernelIndependenceTestStatistic.h>
%include <shogun/statistics/HSIC.h>
3 changes: 3 additions & 0 deletions src/interfaces/modular/Statistics_includes.i
Expand Up @@ -4,5 +4,8 @@
#include <shogun/statistics/KernelTwoSampleTestStatistic.h>
#include <shogun/statistics/LinearTimeMMD.h>
#include <shogun/statistics/QuadraticTimeMMD.h>
#include <shogun/statistics/IndependenceTestStatistic.h>
#include <shogun/statistics/KernelIndependenceTestStatistic.h>
#include <shogun/statistics/HSIC.h>
%}

30 changes: 29 additions & 1 deletion src/shogun/statistics/HSIC.cpp
Expand Up @@ -22,6 +22,12 @@ CHSIC::CHSIC() : CKernelIndependenceTestStatistic()
CHSIC::CHSIC(CKernel* kernel_p, CKernel* kernel_q, CFeatures* p,CFeatures* q) :
CKernelIndependenceTestStatistic(kernel_p, kernel_q, p, q)
{
if (p->get_num_vectors()!=q->get_num_vectors())
{
SG_ERROR("%s: Only features with equal number of vectors "
"are currently possible\n", get_name());
}

init();
}

Expand All @@ -44,7 +50,29 @@ float64_t CHSIC::compute_statistic()
get_name());
}

return 0;
/* compute kernel matrices (these have to be stored unfortunately */
m_kernel_p->init(m_p, m_p);
m_kernel_q->init(m_q, m_q);

SGMatrix<float64_t> K=m_kernel_p->get_kernel_matrix();
SGMatrix<float64_t> L=m_kernel_p->get_kernel_matrix();

/* center matrices (replaces this H matrix from the paper) */
K.center();
L.center();

/* compute MATLAB: sum(sum((H*K)' .* (H*L))), which is biased HSIC */
index_t m=K.num_rows;
float64_t result=0;
for (index_t i=0; i<m; ++i)
{
for (index_t j=0; j<m; ++j)
result+=K(j,i)*L(i,j);
}

result/=m*m;

return result;
}

float64_t CHSIC::compute_p_value(float64_t statistic)
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/statistics/HSIC.h
Expand Up @@ -18,7 +18,7 @@ namespace shogun
/** TODO
*
*/
class CHSIC : CKernelIndependenceTestStatistic
class CHSIC : public CKernelIndependenceTestStatistic
{
public:
/** TODO */
Expand All @@ -35,7 +35,7 @@ class CHSIC : CKernelIndependenceTestStatistic

virtual ~CHSIC();

/** TODO */
/** Computes the biased HSIC TODO */
virtual float64_t compute_statistic();

/** computes a p-value based on current method for approximating the
Expand Down

0 comments on commit caa554c

Please sign in to comment.