Skip to content

Commit

Permalink
change API in histogram intersection kernel
Browse files Browse the repository at this point in the history
it can now be more conveniently inited with

HistogramIntersectionKernel(f1,f2, beta, cachesz)
  • Loading branch information
Soeren Sonnenburg committed Sep 27, 2011
1 parent 42b836a commit 4889edc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/shogun/kernel/HistogramIntersectionKernel.cpp
Expand Up @@ -17,20 +17,21 @@
using namespace shogun;

CHistogramIntersectionKernel::CHistogramIntersectionKernel()
: CDotKernel(0), beta(1.0)
: CDotKernel(0), m_beta(1.0)
{
register_params();
}

CHistogramIntersectionKernel::CHistogramIntersectionKernel(int32_t size)
: CDotKernel(size), beta(1.0)
: CDotKernel(size), m_beta(1.0)
{
register_params();
}

CHistogramIntersectionKernel::CHistogramIntersectionKernel(
CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r, int32_t size)
: CDotKernel(size), beta(1.0)
CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r,
float64_t beta, int32_t size)
: CDotKernel(size), m_beta(1.0)
{
init(l,r);
register_params();
Expand Down Expand Up @@ -62,7 +63,7 @@ float64_t CHistogramIntersectionKernel::compute(int32_t idx_a, int32_t idx_b)
float64_t result=0;

// checking if beta is default or not
if (beta == 1.0)
if (m_beta == 1.0)
{
// compute standard histogram intersection kernel
for (int32_t i=0; i<alen; i++)
Expand All @@ -72,7 +73,7 @@ float64_t CHistogramIntersectionKernel::compute(int32_t idx_a, int32_t idx_b)
{
//compute generalized histogram intersection kernel
for (int32_t i=0; i<alen; i++)
result += CMath::min(CMath::pow(avec[i],beta), CMath::pow(bvec[i],beta));
result += CMath::min(CMath::pow(avec[i],m_beta), CMath::pow(bvec[i],m_beta));
}
((CSimpleFeatures<float64_t>*) lhs)->free_feature_vector(avec, idx_a, afree);
((CSimpleFeatures<float64_t>*) rhs)->free_feature_vector(bvec, idx_b, bfree);
Expand All @@ -82,5 +83,5 @@ float64_t CHistogramIntersectionKernel::compute(int32_t idx_a, int32_t idx_b)

void CHistogramIntersectionKernel::register_params()
{
m_parameters->add(&beta, "beta", "the beta parameter of the kernel");
m_parameters->add(&m_beta, "beta", "the beta parameter of the kernel");
}
10 changes: 6 additions & 4 deletions src/shogun/kernel/HistogramIntersectionKernel.h
Expand Up @@ -44,10 +44,12 @@ class CHistogramIntersectionKernel: public CDotKernel
*
* @param l features of left-hand side
* @param r features of right-hand side
* @param beta kernel parameter
* @param size cache size
*/
CHistogramIntersectionKernel(
CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r, int32_t size);
CSimpleFeatures<float64_t>* l, CSimpleFeatures<float64_t>* r,
float64_t beta=1.0, int32_t size=10);

virtual ~CHistogramIntersectionKernel();

Expand Down Expand Up @@ -77,17 +79,17 @@ class CHistogramIntersectionKernel: public CDotKernel
/** getter for beta parameter
* @return beta value
*/
inline float64_t get_beta() { return this->beta; }
inline float64_t get_beta() { return m_beta; }

/** setter for beta parameter
* @param value beta value
*/
inline void set_beta(float64_t value) { this->beta = value; }
inline void set_beta(float64_t beta) { m_beta = beta; }

protected:

/// beta parameter
float64_t beta;
float64_t m_beta;

/** compute kernel function for features a and b
* idx_{a,b} denote the index of the feature vectors
Expand Down

0 comments on commit 4889edc

Please sign in to comment.