|
@@ -1,4 +1,4 @@
|
|
|
-/**
|
|
|
+/**
|
|
|
* @file GMHIKernel.cpp
|
|
|
* @brief Fast multiplication with histogram intersection kernel matrices (Implementation)
|
|
|
* @author Erik Rodner, Alexander Freytag
|
|
@@ -39,8 +39,8 @@ void GMHIKernel::multiply (NICE::Vector & y, const NICE::Vector & x) const
|
|
|
double *T;
|
|
|
if (useOldPreparation)
|
|
|
{
|
|
|
- NICE::VVector A;
|
|
|
- NICE::VVector B;
|
|
|
+ NICE::VVector A;
|
|
|
+ NICE::VVector B;
|
|
|
// prepare to calculate sum_i x_i K(x,x_i)
|
|
|
fmk->hik_prepare_alpha_multiplications(x, A, B);
|
|
|
T = fmk->hik_prepare_alpha_multiplications_fast(A, B, *q, pf);
|
|
@@ -49,16 +49,16 @@ void GMHIKernel::multiply (NICE::Vector & y, const NICE::Vector & x) const
|
|
|
{
|
|
|
T = fmk->hikPrepareLookupTable(x, *q, pf );
|
|
|
}
|
|
|
- fmk->hik_kernel_multiply_fast ( T, *q, x, y );
|
|
|
+ fmk->hik_kernel_multiply_fast ( T, *q, x, y );
|
|
|
delete [] T;
|
|
|
}
|
|
|
else //no quantization
|
|
|
{
|
|
|
- NICE::VVector A;
|
|
|
- NICE::VVector B;
|
|
|
+ NICE::VVector A;
|
|
|
+ NICE::VVector B;
|
|
|
// prepare to calculate sum_i x_i K(x,x_i)
|
|
|
fmk->hik_prepare_alpha_multiplications(x, A, B);
|
|
|
-
|
|
|
+
|
|
|
if (verbose)
|
|
|
{
|
|
|
int sizeOfDouble (sizeof(double));
|
|
@@ -74,7 +74,7 @@ void GMHIKernel::multiply (NICE::Vector & y, const NICE::Vector & x) const
|
|
|
}
|
|
|
sizeOfA*=sizeOfDouble;
|
|
|
sizeOfB*=sizeOfDouble;
|
|
|
-
|
|
|
+
|
|
|
std::cerr << "multiplySparse: sizeof(A) + sizeof(B): " << sizeOfA + sizeOfB << std::endl;
|
|
|
}
|
|
|
// y = K * x
|
|
@@ -84,6 +84,24 @@ void GMHIKernel::multiply (NICE::Vector & y, const NICE::Vector & x) const
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/** multiply with a vector: A_subset * x = y */
|
|
|
+void GMHIKernel::multiply (const PartialGenericMatrix::SetType & rowSet, const PartialGenericMatrix::SetType & columnSet, NICE::Vector & y, const NICE::Vector & x) const
|
|
|
+{
|
|
|
+ if (q != NULL) {
|
|
|
+ fthrow(NICE::Exception, "not implemented with quantization")
|
|
|
+ } else {
|
|
|
+ NICE::VVector A;
|
|
|
+ NICE::VVector B;
|
|
|
+ // prepare to calculate sum_i x_i K(x,x_i)
|
|
|
+ fmk->hik_prepare_alpha_multiplications_subset(x, A, B, columnSet);
|
|
|
+
|
|
|
+ // y = K * x
|
|
|
+ //we only need x as input argument to add x*noise to beta
|
|
|
+ //all necessary information for the "real" multiplication is already stored in y
|
|
|
+ fmk->hik_kernel_multiply_subset(A, B, x, rowSet, columnSet, y);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/** get the number of rows in A */
|
|
|
uint GMHIKernel::rows () const
|
|
|
{
|
|
@@ -109,7 +127,7 @@ void GMHIKernel::setUseOldPreparation( const bool & _useOldPreparation)
|
|
|
useOldPreparation = _useOldPreparation;
|
|
|
}
|
|
|
|
|
|
-uint GMHIKernel::getNumParameters() const
|
|
|
+uint GMHIKernel::getNumParameters() const
|
|
|
{
|
|
|
if ( pf == NULL )
|
|
|
return 0;
|
|
@@ -133,7 +151,7 @@ void GMHIKernel::setParameters(const Vector & parameters)
|
|
|
fthrow(Exception, "Unable to set parameters of a non-parameterized GMHIKernel object");
|
|
|
|
|
|
pf->parameters() = parameters;
|
|
|
-
|
|
|
+
|
|
|
fmk->applyFunctionToFeatureMatrix( pf );
|
|
|
|
|
|
// only for debugging with small matrices: fmk->featureMatrix().print();
|
|
@@ -146,6 +164,13 @@ void GMHIKernel::getDiagonalElements ( Vector & diagonalElements ) const
|
|
|
diagonalElements += fmk->getNoise();
|
|
|
}
|
|
|
|
|
|
+double GMHIKernel::getDiagonalElement ( uint i ) const
|
|
|
+{
|
|
|
+ Vector diagonalElements;
|
|
|
+ getDiagonalElements(diagonalElements);
|
|
|
+ return diagonalElements[i];
|
|
|
+}
|
|
|
+
|
|
|
void GMHIKernel::getFirstDiagonalElement ( double & diagonalElement ) const
|
|
|
{
|
|
|
Vector diagonalElements;
|
|
@@ -154,12 +179,12 @@ void GMHIKernel::getFirstDiagonalElement ( double & diagonalElement ) const
|
|
|
// add sigma^2 I
|
|
|
diagonalElement += fmk->getNoise();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
bool GMHIKernel::outOfBounds(const Vector & parameters) const
|
|
|
{
|
|
|
if ( pf == NULL && parameters.size() > 0 )
|
|
|
fthrow(Exception, "Unable to check the bounds of a parameter without any parameterization");
|
|
|
-
|
|
|
+
|
|
|
Vector uB = pf->getParameterUpperBounds();
|
|
|
Vector lB = pf->getParameterLowerBounds();
|
|
|
if ( uB.size() != parameters.size() || lB.size() != parameters.size() )
|
|
@@ -203,8 +228,8 @@ void GMHIKernel::setApproximationScheme(const int & _approxScheme)
|
|
|
// interface specific methods for incremental extensions
|
|
|
///////////////////// INTERFACE ONLINE LEARNABLE /////////////////////
|
|
|
|
|
|
-void GMHIKernel::addExample( const NICE::SparseVector * example,
|
|
|
- const double & label,
|
|
|
+void GMHIKernel::addExample( const NICE::SparseVector * example,
|
|
|
+ const double & label,
|
|
|
const bool & performOptimizationAfterIncrement
|
|
|
)
|
|
|
{
|