42 using namespace internal;
46 : n_x(nx), n_y(ny), stype(type), terms()
48 SG_SDEBUG(
"number of samples are %d and %d!\n", n_x, n_y);
55 if (i<n_x && j<n_x && i<=j)
57 SG_SDEBUG(
"Adding Kernel(%d,%d)=%f to term_0!\n", i, j, val);
62 else if (i>=n_x && j>=n_x && i<=j)
64 SG_SDEBUG(
"Adding Kernel(%d,%d)=%f to term_1!\n", i, j, val);
69 else if (i>=n_x && j<n_x)
71 SG_SDEBUG(
"Adding Kernel(%d,%d)=%f to term_2!\n", i, j, val);
82 std::iota(permuted_inds.vector, permuted_inds.vector+permuted_inds.vlen, 0);
84 for (
int i=0; i<permuted_inds.vlen; ++i)
85 inverted_permuted_inds[permuted_inds[i]]=i;
87 std::fill(&terms.term[0], &terms.term[2]+1, 0);
88 std::fill(&terms.diag[0], &terms.diag[2]+1, 0);
90 for (
auto j=0; j<n_x+n_y; ++j)
92 for (
auto i=0; i<n_x+n_y; ++i)
93 add_term(km(i, j), inverted_permuted_inds[i], inverted_permuted_inds[j]);
96 terms.term[0]=2*(terms.term[0]-terms.diag[0]);
97 terms.term[1]=2*(terms.term[1]-terms.diag[1]);
98 SG_SDEBUG(
"term_0 sum (without diagonal) = %f!\n", terms.term[0]);
99 SG_SDEBUG(
"term_1 sum (without diagonal) = %f!\n", terms.term[1]);
102 terms.term[0]/=n_x*(n_x-1);
103 terms.term[1]/=n_y*(n_y-1);
107 terms.term[0]+=terms.diag[0];
108 terms.term[1]+=terms.diag[1];
109 SG_SDEBUG(
"term_0 sum (with diagonal) = %f!\n", terms.term[0]);
110 SG_SDEBUG(
"term_1 sum (with diagonal) = %f!\n", terms.term[1]);
111 terms.term[0]/=n_x*n_x;
112 terms.term[1]/=n_y*n_y;
114 SG_SDEBUG(
"term_0 (normalized) = %f!\n", terms.term[0]);
115 SG_SDEBUG(
"term_1 (normalized) = %f!\n", terms.term[1]);
117 SG_SDEBUG(
"term_2 sum (with diagonal) = %f!\n", terms.term[2]);
120 terms.term[2]-=terms.diag[2];
121 SG_SDEBUG(
"term_2 sum (without diagonal) = %f!\n", terms.term[2]);
122 terms.term[2]/=n_x*(n_x-1);
125 terms.term[2]/=n_x*n_y;
126 SG_SDEBUG(
"term_2 (normalized) = %f!\n", terms.term[2]);
129 return terms.term[0]+terms.term[1]-2*terms.term[2];
static void permute(SGVector< T > v, CRandom *rand=NULL)
all of classes and functions are contained in the shogun namespace