Skip to content

Commit

Permalink
fixes, gamma test should work now
Browse files Browse the repository at this point in the history
  • Loading branch information
karlnapf committed Jul 8, 2012
1 parent e1db78e commit 3e19962
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/shogun/statistics/HSIC.cpp
Expand Up @@ -69,7 +69,8 @@ float64_t CHSIC::compute_statistic()
result+=K(j, i)*L(i, j);
}

result/=m*m;
/* return m times statistic */
result/=m;

return result;
}
Expand Down Expand Up @@ -107,23 +108,13 @@ float64_t CHSIC::compute_p_value_gamma(float64_t statistic)

index_t m=m_p->get_num_vectors();

/* NOTE: the gamma distribution is fitted to m*HSIC_b. Therefore, the
* parameter statistic value is multiplied by m before anything is done.
* This assumes that the feature data size is NOT changed after statistics
* call */
statistic*=m;
SG_WARNING("check this! Gamma test uses different statistic!\n");

/* 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_q->get_kernel_matrix();

K.display_matrix("K");
L.display_matrix("L");

/* compute sum and trace of uncentered kernel matrices, needed later */
float64_t trace_K=0;
float64_t trace_L=0;
Expand All @@ -146,9 +137,6 @@ float64_t CHSIC::compute_p_value_gamma(float64_t statistic)
K.center();
L.center();

K.display_matrix("K_centered");
L.display_matrix("L_centered");

/* compute the trace of MATLAB: (1/6 * Kc.*Lc).^2 Ü */
float64_t trace=0;
for (index_t i=0; i<m; ++i)
Expand All @@ -174,7 +162,7 @@ float64_t CHSIC::compute_p_value_gamma(float64_t statistic)

/* finally, compute variance of hsic under H0
* MATLAB: varHSIC = 72*(m-4)*(m-5)/m/(m-1)/(m-2)/(m-3) * varHSIC */
var_hsic=72.0*(m-4)*(m-5)/m/(m-1)/(m-2)/(m-2)*var_hsic;
var_hsic=72.0*(m-4)*(m-5)/m/(m-1)/(m-2)/(m-3)*var_hsic;
SG_DEBUG("var_hsic: %f\n", var_hsic);

/* compute mean of matrices with diagonal elements zero on the base of sums
Expand All @@ -195,7 +183,7 @@ float64_t CHSIC::compute_p_value_gamma(float64_t statistic)
/* return: cdf('gam',statistic,al,bet) (MATLAB)
* which will get the position in the null distribution */
float64_t result=CStatistics::gamma_cdf(statistic, a, b);
SG_DEBUG("result: %f\n", result);
SG_DEBUG("gamma_cdf(%f, %f, %f): %f\n", statistic, a, b, result);

SG_DEBUG(("leaving %s::compute_p_value_gamma()\n"), get_name());
return result;
Expand Down

0 comments on commit 3e19962

Please sign in to comment.