Skip to content

Commit

Permalink
Optimizing the Jensen-Shannon kernel computation
Browse files Browse the repository at this point in the history
Instead of doing two divisions switch to one multiplication
  • Loading branch information
vigsterkr committed Feb 12, 2012
1 parent 4af1dff commit 4d01e40
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/shogun/kernel/JensenShannonKernel.cpp
Expand Up @@ -63,11 +63,11 @@ float64_t CJensenShannonKernel::compute(int32_t idx_a, int32_t idx_b)
float64_t a_i = 0, b_i = 0;
float64_t ab = avec[i]+bvec[i];
if (avec[i] != 0)
a_i = avec[i]/2 * CMath::log2(ab/avec[i]);
a_i = avec[i] * CMath::log2(ab/avec[i]);
if (bvec[i] != 0)
b_i = bvec[i]/2 * CMath::log2(ab/bvec[i]);
b_i = bvec[i] * CMath::log2(ab/bvec[i]);

result += a_i + b_i;
result += 0.5*(a_i + b_i);
}

((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
Expand Down

0 comments on commit 4d01e40

Please sign in to comment.