/** 
* @file KernelHIK.cpp
* @brief Interface for the (parameterized) histogram intersection kernel (HIK)
* @author Paul Bodesheim
* @date 02/07/2013

*/

#include <iostream>

#include <math.h>
#include "KernelHIK.h"

using namespace OBJREC;

using namespace std;
using namespace NICE;



KernelHIK::KernelHIK( double _alpha, double _beta )
{
    alpha = _alpha;
    beta = _beta;
}

KernelHIK::KernelHIK ( const KernelHIK & src )
{
	alpha = src.alpha;
	beta = src.beta;
}

KernelHIK::~KernelHIK()
{
}

KernelHIK *KernelHIK::clone(void) const
{
	return new KernelHIK ( *this );
}

	
double KernelHIK::K (const NICE::Vector & x, const NICE::Vector & y) const
{
	if ( x.size() != y.size() ) {
		cerr << "KernelHIK: dimensions: " << x.size() << " vs " << y.size() << endl;
		fthrow(Exception, "Vector dimensions do not match!");
	}

	double sim = 0.0;
	for ( size_t i = 0 ; i < x.size() ; i++ )
	{
                double d = alpha*pow(min(x[i], y[i]), beta);
		sim += d;
	}
        return sim;
}

void KernelHIK::updateKernelData ( KernelData *kernelData ) const
{
        NICE::Matrix & kernelMatrix = kernelData->getKernelMatrix();
        fthrow(Exception, "Not yet implemented!");

}

void KernelHIK::getKernelJacobi ( size_t parameter, const NICE::Vector & parameters, const KernelData *kernelData, NICE::Matrix & jacobiMatrix ) const
{
	fthrow(Exception, "Not yet implemented!");
}

void KernelHIK::setParameters( const NICE::Vector & newParameters ) 
{
	alpha = newParameters[0];
        beta = newParameters[1];
}

void KernelHIK::getParameters( NICE::Vector & newParameters ) const
{
	newParameters.resize(2);
	newParameters[0] = alpha;
        newParameters[1] = beta;
}
