|
@@ -250,14 +250,14 @@ void FastMinKernel::hik_prepare_alpha_multiplications(const NICE::Vector & _alph
|
|
|
|
|
|
double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVector & _A,
|
|
|
const NICE::VVector & _B,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf
|
|
|
) const
|
|
|
{
|
|
|
//NOTE keep in mind: for doing this, we already have precomputed A and B using hik_prepare_alpha_multiplications!
|
|
|
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
double *prototypes = new double [ hmax ];
|
|
@@ -265,9 +265,9 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
if ( _pf != NULL ) {
|
|
|
// FIXME: the transformed prototypes could change from dimension to another dimension
|
|
|
// We skip this flexibility ...but it should be changed in the future
|
|
|
- prototypes[i] = _pf->f ( 1, _q.getPrototype(i) );
|
|
|
+ prototypes[i] = _pf->f ( 1, _q->getPrototype(i) );
|
|
|
} else {
|
|
|
- prototypes[i] = _q.getPrototype(i);
|
|
|
+ prototypes[i] = _q->getPrototype(i);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -294,7 +294,7 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
uint index = 0;
|
|
|
// we use the quantization of the original features! the transformed feature were
|
|
|
// already used to calculate A and B, this of course assumes monotonic functions!!!
|
|
|
- uint qBin = _q.quantize ( i->first );
|
|
|
+ uint qBin = _q->quantize ( i->first, dim );
|
|
|
|
|
|
// the next loop is linear in max(hmax, n)
|
|
|
// REMARK: this could be changed to hmax*log(n), when
|
|
@@ -319,7 +319,7 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
i++;
|
|
|
|
|
|
if ( i->first != iPredecessor->first )
|
|
|
- qBin = _q.quantize ( i->first );
|
|
|
+ qBin = _q->quantize ( i->first, dim );
|
|
|
}
|
|
|
// compute current element in the lookup table and keep in mind that
|
|
|
// index is the next element and not the previous one
|
|
@@ -344,12 +344,12 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
}
|
|
|
|
|
|
double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf
|
|
|
) const
|
|
|
{
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
double *prototypes = new double [ hmax ];
|
|
@@ -357,9 +357,9 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
if ( _pf != NULL ) {
|
|
|
// FIXME: the transformed prototypes could change from dimension to another dimension
|
|
|
// We skip this flexibility ...but it should be changed in the future
|
|
|
- prototypes[i] = _pf->f ( 1, _q.getPrototype(i) );
|
|
|
+ prototypes[i] = _pf->f ( 1, _q->getPrototype(i) );
|
|
|
} else {
|
|
|
- prototypes[i] = _q.getPrototype(i);
|
|
|
+ prototypes[i] = _q->getPrototype(i);
|
|
|
}
|
|
|
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
@@ -391,7 +391,7 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
uint index = 0;
|
|
|
|
|
|
// we use the quantization of the original features! Nevetheless, the resulting lookupTable is computed using the transformed ones
|
|
|
- uint qBin = _q.quantize ( i->first );
|
|
|
+ uint qBin = _q->quantize ( i->first, dim );
|
|
|
|
|
|
double alpha_sum(0.0);
|
|
|
double alpha_times_x_sum(0.0);
|
|
@@ -423,7 +423,7 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
i++;
|
|
|
|
|
|
if ( i->first != iPredecessor->first )
|
|
|
- qBin = _q.quantize ( i->first );
|
|
|
+ qBin = _q->quantize ( i->first, dim );
|
|
|
}
|
|
|
// compute current element in the lookup table and keep in mind that
|
|
|
// index is the next element and not the previous one
|
|
@@ -454,7 +454,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
const double & _alphaNew,
|
|
|
const double & _alphaOld,
|
|
|
const uint & _idx,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf
|
|
|
) const
|
|
|
{
|
|
@@ -466,7 +466,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
}
|
|
|
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
double *prototypes = new double [ hmax ];
|
|
@@ -474,9 +474,9 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
if ( _pf != NULL ) {
|
|
|
// FIXME: the transformed prototypes could change from dimension to another dimension
|
|
|
// We skip this flexibility ...but it should be changed in the future
|
|
|
- prototypes[i] = _pf->f ( 1, _q.getPrototype(i) );
|
|
|
+ prototypes[i] = _pf->f ( 1, _q->getPrototype(i) );
|
|
|
} else {
|
|
|
- prototypes[i] = _q.getPrototype(i);
|
|
|
+ prototypes[i] = _q->getPrototype(i);
|
|
|
}
|
|
|
|
|
|
double diffOfAlpha(_alphaNew - _alphaOld);
|
|
@@ -494,7 +494,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
for (uint j = 0; j < hmax; j++)
|
|
|
{
|
|
|
double fval;
|
|
|
- uint q_bin = _q.quantize(x_i);
|
|
|
+ uint q_bin = _q->quantize( x_i, dim );
|
|
|
|
|
|
if ( q_bin > j )
|
|
|
fval = prototypes[j];
|
|
@@ -575,7 +575,7 @@ void FastMinKernel::hik_kernel_multiply(const NICE::VVector & _A,
|
|
|
}
|
|
|
|
|
|
void FastMinKernel::hik_kernel_multiply_fast(const double *_Tlookup,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const NICE::Vector & _alpha,
|
|
|
NICE::Vector & _beta) const
|
|
|
{
|
|
@@ -593,8 +593,8 @@ void FastMinKernel::hik_kernel_multiply_fast(const double *_Tlookup,
|
|
|
{
|
|
|
const SortedVectorSparse<double>::dataelement & de = i->second;
|
|
|
uint feat = de.first;
|
|
|
- uint qBin = _q.quantize(i->first);
|
|
|
- _beta[feat] += _Tlookup[dim*_q.size() + qBin];
|
|
|
+ uint qBin = _q->quantize( i->first, dim );
|
|
|
+ _beta[feat] += _Tlookup[dim*_q->size() + qBin];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -752,7 +752,7 @@ void FastMinKernel::hik_kernel_sum(const NICE::VVector & _A,
|
|
|
}
|
|
|
|
|
|
void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const NICE::Vector & _xstar,
|
|
|
double & _beta
|
|
|
) const
|
|
@@ -768,14 +768,14 @@ void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
|
|
|
for ( uint dim = 0; dim < this->ui_d; dim++)
|
|
|
{
|
|
|
double v = _xstar[dim];
|
|
|
- uint qBin = _q.quantize(v);
|
|
|
+ uint qBin = _q->quantize( v, dim );
|
|
|
|
|
|
- _beta += _Tlookup[dim*_q.size() + qBin];
|
|
|
+ _beta += _Tlookup[dim*_q->size() + qBin];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const NICE::SparseVector & _xstar,
|
|
|
double & _beta
|
|
|
) const
|
|
@@ -789,15 +789,15 @@ void FastMinKernel::hik_kernel_sum_fast(const double *_Tlookup,
|
|
|
{
|
|
|
uint dim = i->first;
|
|
|
double v = i->second;
|
|
|
- uint qBin = _q.quantize(v);
|
|
|
+ uint qBin = _q->quantize( v, dim );
|
|
|
|
|
|
- _beta += _Tlookup[dim*_q.size() + qBin];
|
|
|
+ _beta += _Tlookup[dim*_q->size() + qBin];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
|
NICE::Vector & _alpha,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf,
|
|
|
const bool & _useRandomSubsets,
|
|
|
uint _maxIterations,
|
|
@@ -811,7 +811,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
|
bool verboseMinimal ( false );
|
|
|
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
NICE::Vector diagonalElements(_y.size(),0.0);
|
|
|
this->X_sorted.hikDiagonalElements(diagonalElements);
|
|
@@ -877,7 +877,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
|
for (uint j = 0; j < this->ui_d; j++)
|
|
|
{
|
|
|
x_i = this->X_sorted(j,perm[i]);
|
|
|
- pseudoResidual(perm[i]) += Tlookup[j*hmax + _q.quantize(x_i)];
|
|
|
+ pseudoResidual(perm[i]) += Tlookup[j*hmax + _q->quantize( x_i, j )];
|
|
|
}
|
|
|
|
|
|
//NOTE: this threshhold could also be a parameter of the function call
|
|
@@ -928,7 +928,7 @@ double *FastMinKernel::solveLin(const NICE::Vector & _y,
|
|
|
for (uint j = 0; j < this->ui_d; j++)
|
|
|
{
|
|
|
x_i = this->X_sorted(j,i);
|
|
|
- pseudoResidual(i) += Tlookup[j*hmax + _q.quantize(x_i)];
|
|
|
+ pseudoResidual(i) += Tlookup[j*hmax + _q->quantize( x_i, j )];
|
|
|
}
|
|
|
|
|
|
//NOTE: this threshhold could also be a parameter of the function call
|
|
@@ -1132,13 +1132,13 @@ void FastMinKernel::hikPrepareKVNApproximation(NICE::VVector & _A) const
|
|
|
}
|
|
|
|
|
|
double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf ) const
|
|
|
{
|
|
|
//NOTE keep in mind: for doing this, we already have precomputed A using hikPrepareSquaredKernelVector!
|
|
|
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
double *prototypes = new double [ hmax ];
|
|
@@ -1146,9 +1146,9 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
if ( _pf != NULL ) {
|
|
|
// FIXME: the transformed prototypes could change from dimension to another dimension
|
|
|
// We skip this flexibility ...but it should be changed in the future
|
|
|
- prototypes[i] = _pf->f ( 1, _q.getPrototype(i) );
|
|
|
+ prototypes[i] = _pf->f ( 1, _q->getPrototype(i) );
|
|
|
} else {
|
|
|
- prototypes[i] = _q.getPrototype(i);
|
|
|
+ prototypes[i] = _q->getPrototype(i);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -1172,7 +1172,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
uint index = 0;
|
|
|
// we use the quantization of the original features! the transformed feature were
|
|
|
// already used to calculate A and B, this of course assumes monotonic functions!!!
|
|
|
- uint qBin = _q.quantize ( i->first );
|
|
|
+ uint qBin = _q->quantize ( i->first, dim );
|
|
|
|
|
|
// the next loop is linear in max(hmax, n)
|
|
|
// REMARK: this could be changed to hmax*log(n), when
|
|
@@ -1198,7 +1198,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
i++;
|
|
|
|
|
|
if ( i->first != iPredecessor->first )
|
|
|
- qBin = _q.quantize ( i->first );
|
|
|
+ qBin = _q->quantize ( i->first, dim );
|
|
|
}
|
|
|
// compute current element in the lookup table and keep in mind that
|
|
|
// index is the next element and not the previous one
|
|
@@ -1224,12 +1224,12 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
return Tlookup;
|
|
|
}
|
|
|
|
|
|
-double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantization & _q,
|
|
|
+double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantization * _q,
|
|
|
const ParameterizedFunction *_pf
|
|
|
) const
|
|
|
{
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q.size();
|
|
|
+ uint hmax = _q->size();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
double *prototypes = new double [ hmax ];
|
|
@@ -1237,9 +1237,9 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
|
|
|
if ( _pf != NULL ) {
|
|
|
// FIXME: the transformed prototypes could change from dimension to another dimension
|
|
|
// We skip this flexibility ...but it should be changed in the future
|
|
|
- prototypes[i] = _pf->f ( 1, _q.getPrototype(i) );
|
|
|
+ prototypes[i] = _pf->f ( 1, _q->getPrototype(i) );
|
|
|
} else {
|
|
|
- prototypes[i] = _q.getPrototype(i);
|
|
|
+ prototypes[i] = _q->getPrototype(i);
|
|
|
}
|
|
|
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
@@ -1262,7 +1262,7 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
|
|
|
uint index = 0;
|
|
|
|
|
|
// we use the quantization of the original features! Nevetheless, the resulting lookupTable is computed using the transformed ones
|
|
|
- uint qBin = _q.quantize ( i->first );
|
|
|
+ uint qBin = _q->quantize ( i->first, dim );
|
|
|
|
|
|
double sum(0.0);
|
|
|
|
|
@@ -1287,7 +1287,7 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
|
|
|
i++;
|
|
|
|
|
|
if ( i->first != iPredecessor->first )
|
|
|
- qBin = _q.quantize ( i->first );
|
|
|
+ qBin = _q->quantize ( i->first, dim );
|
|
|
}
|
|
|
// compute current element in the lookup table and keep in mind that
|
|
|
// index is the next element and not the previous one
|
|
@@ -1374,7 +1374,7 @@ void FastMinKernel::hikComputeKVNApproximation(const NICE::VVector & _A,
|
|
|
}
|
|
|
|
|
|
void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const NICE::SparseVector & _xstar,
|
|
|
double & _norm
|
|
|
) const
|
|
@@ -1387,9 +1387,9 @@ void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
|
|
|
double v = i->second;
|
|
|
// we do not need a parameterized function here, since the quantizer works on the original feature values.
|
|
|
// nonetheless, the lookup table was created using the parameterized function
|
|
|
- uint qBin = _q.quantize(v);
|
|
|
+ uint qBin = _q->quantize( v, dim );
|
|
|
|
|
|
- _norm += _Tlookup[dim*_q.size() + qBin];
|
|
|
+ _norm += _Tlookup[dim*_q->size() + qBin];
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1517,7 +1517,7 @@ void FastMinKernel::hikComputeKVNApproximation(const NICE::VVector & _A,
|
|
|
}
|
|
|
|
|
|
void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
|
|
|
- const Quantization & _q,
|
|
|
+ const Quantization * _q,
|
|
|
const NICE::Vector & _xstar,
|
|
|
double & _norm
|
|
|
) const
|
|
@@ -1525,14 +1525,14 @@ void FastMinKernel::hikComputeKVNApproximationFast(const double *_Tlookup,
|
|
|
_norm = 0.0;
|
|
|
// runtime is O(d) if the quantizer is O(1)
|
|
|
uint dim ( 0 );
|
|
|
- for (Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++ )
|
|
|
+ for ( NICE::Vector::const_iterator i = _xstar.begin(); i != _xstar.end(); i++, dim++ )
|
|
|
{
|
|
|
double v = *i;
|
|
|
// we do not need a parameterized function here, since the quantizer works on the original feature values.
|
|
|
// nonetheless, the lookup table was created using the parameterized function
|
|
|
- uint qBin = _q.quantize(v);
|
|
|
+ uint qBin = _q->quantize( v, dim );
|
|
|
|
|
|
- _norm += _Tlookup[dim*_q.size() + qBin];
|
|
|
+ _norm += _Tlookup[dim*_q->size() + qBin];
|
|
|
}
|
|
|
}
|
|
|
|