40 #include <shogun/lib/external/libqp.h>
42 using namespace shogun;
74 SG_DEBUG(
"computing MMD values for current kernel!\n");
97 for (
index_t i=0; i<num_this_run; ++i)
98 current[i]=pp[i]+qq[i]-pq[i]-qp[i];
118 bool multiple_kernels)
129 "multiple kernels specified, but underlying kernel is not of type "
140 if (multiple_kernels)
143 SG_DEBUG(
"computing MMD and variance for %d sub-kernels\n",
156 "statistic vector size (%d) does not match number of kernels (%d)\n",
157 statistic.
vlen, num_kernels);
160 "variance vector size (%d) does not match number of kernels (%d)\n",
161 variance.
vlen, num_kernels);
175 index_t num_examples_processed=0;
176 while (num_examples_processed<m_2)
181 SG_DEBUG(
"processing %d more examples. %d so far processed. Blocksize "
182 "is %d\n", num_this_run, num_examples_processed,
m_blocksize);
191 if (multiple_kernels)
192 SG_DEBUG(
"using multiple kernels\n");
196 for (
index_t i=0; i<num_kernels; ++i)
199 if (multiple_kernels)
209 for (
index_t j=0; j<num_this_run; ++j)
212 delta=current[j]-statistic[i];
213 statistic[i]+=delta/term_counters[i]++;
214 variance[i]+=delta*(current[j]-statistic[i]);
216 SG_DEBUG(
"burst: current=%f, delta=%f, statistic=%f, "
217 "variance=%f, kernel_idx=%d\n", current[j], delta,
218 statistic[i], variance[i], i);
221 if (multiple_kernels)
229 num_examples_processed+=num_this_run;
231 SG_DEBUG(
"Done compouting statistic, processed 2*%d examples.\n",
232 num_examples_processed);
241 for (
index_t i=0; i<num_kernels; ++i)
242 variance[i]=variance[i]/(m_2-1)/m_2;
262 "underlying kernel is not of type K_COMBINED\n");
274 index_t num_kernels=combined->get_num_subkernels();
275 REQUIRE(num_kernels>0,
"At least one kernel is needed\n");
286 "statistic vector size (%d) does not match number of kernels (%d)\n",
287 statistic.
vlen, num_kernels);
290 "Q number of rows does (%d) not match number of kernels (%d)\n",
294 "Q number of columns (%d) does not match number of kernels (%d)\n",
305 for (
index_t k_idx=0; k_idx<combined->get_num_kernels(); k_idx++)
307 CKernel* kernel = combined->get_kernel(k_idx);
319 index_t num_examples_processed=0;
320 while (num_examples_processed<m_4)
325 SG_DEBUG(
"processing %d more examples. %d so far processed. Blocksize "
326 "is %d\n", num_this_run, num_examples_processed,
m_blocksize);
374 for (
index_t i=0; i<num_kernels; ++i)
404 for (
index_t it=0; it<num_this_run; ++it)
407 term=(h_i_a[it]-h_i_b[it])*(h_j_a[it]-h_j_b[it]);
412 Q(i, j)+=(term-Q(i, j))/term_counters_Q(i, j)++;
425 for (
index_t it=0; it<num_this_run; ++it)
429 statistic[i]=statistic[i]+
430 (h_i_a[it]-statistic[i])/term_counters_statistic[i]++;
433 statistic[i]=statistic[i]+
434 (h_i_b[it]-statistic[i])/(term_counters_statistic[i]++);
446 num_examples_processed+=num_this_run;
453 SG_DEBUG(
"Done compouting statistic, processed 4*%d examples.\n",
454 num_examples_processed);