|
@@ -257,20 +257,28 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
//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->getNumberOfBins();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
- double *prototypes = new double [ hmax ];
|
|
|
- for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
- 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) );
|
|
|
- } else {
|
|
|
- prototypes[i] = _q->getPrototype(i);
|
|
|
- }
|
|
|
-
|
|
|
+ double * prototypes = new double [ hmax * this->ui_d ];
|
|
|
+ double * p_prototypes = prototypes;
|
|
|
|
|
|
+ for (uint dim = 0; dim < this->ui_d; dim++)
|
|
|
+ {
|
|
|
+ for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
+ {
|
|
|
+ if ( _pf != NULL )
|
|
|
+ {
|
|
|
+ *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ *p_prototypes = _q->getPrototype( i, dim );
|
|
|
+ }
|
|
|
+
|
|
|
+ p_prototypes++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
|
// for fast evaluation
|
|
|
double *Tlookup = new double [ hmax * this->ui_d ];
|
|
@@ -302,7 +310,7 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
|
|
|
for (uint j = 0; j < hmax; j++)
|
|
|
{
|
|
|
- double fval = prototypes[j];
|
|
|
+ double fval = prototypes[ dim*hmax + j ];
|
|
|
double t;
|
|
|
|
|
|
if ( (index == 0) && (j < qBin) ) {
|
|
@@ -339,6 +347,12 @@ double *FastMinKernel::hik_prepare_alpha_multiplications_fast(const NICE::VVecto
|
|
|
}
|
|
|
|
|
|
delete [] prototypes;
|
|
|
+
|
|
|
+ double * Tval = Tlookup;
|
|
|
+ std::cerr << " computed LUT " << std::endl;
|
|
|
+ for ( uint idx = 0 ; idx < hmax * this->ui_d; idx++, Tval++ )
|
|
|
+ std::cerr << " " << *Tval ;
|
|
|
+ std::cerr << std::endl;
|
|
|
|
|
|
return Tlookup;
|
|
|
}
|
|
@@ -349,18 +363,27 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
) const
|
|
|
{
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q->size();
|
|
|
+ uint hmax = _q->getNumberOfBins();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
- double *prototypes = new double [ hmax ];
|
|
|
- for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
- 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) );
|
|
|
- } else {
|
|
|
- prototypes[i] = _q->getPrototype(i);
|
|
|
+ double * prototypes = new double [ hmax * this->ui_d ];
|
|
|
+ double * p_prototypes = prototypes;
|
|
|
+
|
|
|
+ for (uint dim = 0; dim < this->ui_d; dim++)
|
|
|
+ {
|
|
|
+ for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
+ {
|
|
|
+ if ( _pf != NULL )
|
|
|
+ {
|
|
|
+ *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ *p_prototypes = _q->getPrototype( i, dim );
|
|
|
+ }
|
|
|
+
|
|
|
+ p_prototypes++;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
|
// for fast evaluation
|
|
@@ -400,7 +423,7 @@ double *FastMinKernel::hikPrepareLookupTable(const NICE::Vector & _alpha,
|
|
|
|
|
|
for (uint j = 0; j < hmax; j++)
|
|
|
{
|
|
|
- double fval = prototypes[j];
|
|
|
+ double fval = prototypes[ dim*hmax + j ];
|
|
|
double t;
|
|
|
|
|
|
if ( (index == 0) && (j < qBin) ) {
|
|
@@ -466,18 +489,27 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
}
|
|
|
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q->size();
|
|
|
+ uint hmax = _q->getNumberOfBins();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
- double *prototypes = new double [ hmax ];
|
|
|
- for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
- 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) );
|
|
|
- } else {
|
|
|
- prototypes[i] = _q->getPrototype(i);
|
|
|
+ double * prototypes = new double [ hmax * this->ui_d ];
|
|
|
+ double * p_prototypes = prototypes;
|
|
|
+
|
|
|
+ for (uint dim = 0; dim < this->ui_d; dim++)
|
|
|
+ {
|
|
|
+ for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
+ {
|
|
|
+ if ( _pf != NULL )
|
|
|
+ {
|
|
|
+ *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ *p_prototypes = _q->getPrototype( i, dim );
|
|
|
+ }
|
|
|
+
|
|
|
+ p_prototypes++;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
double diffOfAlpha(_alphaNew - _alphaOld);
|
|
|
|
|
@@ -497,7 +529,7 @@ void FastMinKernel::hikUpdateLookupTable(double * _T,
|
|
|
uint q_bin = _q->quantize( x_i, dim );
|
|
|
|
|
|
if ( q_bin > j )
|
|
|
- fval = prototypes[j];
|
|
|
+ fval = prototypes[ dim*hmax + j ];
|
|
|
else
|
|
|
fval = x_i;
|
|
|
|
|
@@ -1138,18 +1170,27 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
//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->getNumberOfBins();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
- double *prototypes = new double [ hmax ];
|
|
|
- for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
- 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) );
|
|
|
- } else {
|
|
|
- prototypes[i] = _q->getPrototype(i);
|
|
|
+ double *prototypes = new double [ hmax * this->ui_d ];
|
|
|
+ double * p_prototypes = prototypes;
|
|
|
+
|
|
|
+ for (uint dim = 0; dim < this->ui_d; dim++)
|
|
|
+ {
|
|
|
+ for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
+ {
|
|
|
+ if ( _pf != NULL )
|
|
|
+ {
|
|
|
+ *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ *p_prototypes = _q->getPrototype( i, dim );
|
|
|
+ }
|
|
|
+
|
|
|
+ p_prototypes++;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
@@ -1181,7 +1222,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
|
|
|
for (uint j = 0; j < hmax; j++)
|
|
|
{
|
|
|
- double fval = prototypes[j];
|
|
|
+ double fval = prototypes[ dim*hmax + j];
|
|
|
double t;
|
|
|
|
|
|
if ( (index == 0) && (j < qBin) ) {
|
|
@@ -1209,9 +1250,7 @@ double * FastMinKernel::hikPrepareKVNApproximationFast(NICE::VVector & _A,
|
|
|
t = _A[dim][index];
|
|
|
} else {
|
|
|
// standard case
|
|
|
- t = _A[dim][index-1] + pow( fval, 2 ) * (this->ui_n-nrZeroIndices-(index) );
|
|
|
-// A[dim][index-1] + fval * (n-nrZeroIndices-(index) );//fval*fval * (n-nrZeroIndices-(index-1) );
|
|
|
-
|
|
|
+ t = _A[dim][index-1] + pow( fval, 2 ) * (this->ui_n-nrZeroIndices-(index) );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1229,18 +1268,27 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
|
|
|
) const
|
|
|
{
|
|
|
// number of quantization bins
|
|
|
- uint hmax = _q->size();
|
|
|
+ uint hmax = _q->getNumberOfBins();
|
|
|
|
|
|
// store (transformed) prototypes
|
|
|
- double *prototypes = new double [ hmax ];
|
|
|
- for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
- 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) );
|
|
|
- } else {
|
|
|
- prototypes[i] = _q->getPrototype(i);
|
|
|
+ double *prototypes = new double [ hmax * this->ui_d ];
|
|
|
+ double * p_prototypes = prototypes;
|
|
|
+
|
|
|
+ for (uint dim = 0; dim < this->ui_d; dim++)
|
|
|
+ {
|
|
|
+ for ( uint i = 0 ; i < hmax ; i++ )
|
|
|
+ {
|
|
|
+ if ( _pf != NULL )
|
|
|
+ {
|
|
|
+ *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ *p_prototypes = _q->getPrototype( i, dim );
|
|
|
+ }
|
|
|
+
|
|
|
+ p_prototypes++;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
// creating the lookup table as pure C, which might be beneficial
|
|
|
// for fast evaluation
|
|
@@ -1268,7 +1316,7 @@ double* FastMinKernel::hikPrepareLookupTableForKVNApproximation(const Quantizati
|
|
|
|
|
|
for (uint j = 0; j < hmax; j++)
|
|
|
{
|
|
|
- double fval = prototypes[j];
|
|
|
+ double fval = prototypes[ dim*hmax + j];
|
|
|
double t;
|
|
|
|
|
|
if ( (index == 0) && (j < qBin) ) {
|