|
@@ -142,7 +142,7 @@ void GMHIKernelRaw::initData ( const std::vector< const NICE::SparseVector *> &_
|
|
{
|
|
{
|
|
|
|
|
|
this->q->computeParametersFromData ( this );
|
|
this->q->computeParametersFromData ( this );
|
|
- this->table_T = allocateTableT();
|
|
+ this->table_T = this->allocateTableT();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -162,10 +162,10 @@ double **GMHIKernelRaw::allocateTableAorB() const
|
|
return table;
|
|
return table;
|
|
}
|
|
}
|
|
|
|
|
|
-double **GMHIKernelRaw::allocateTableT() const
|
|
+double *GMHIKernelRaw::allocateTableT() const
|
|
{
|
|
{
|
|
- double **table;
|
|
+ double *table;
|
|
- table = new double *[this->num_dimension * this->q->getNumberOfBins()];
|
|
+ table = new double [this->num_dimension * this->q->getNumberOfBins()];
|
|
return table;
|
|
return table;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -183,16 +183,16 @@ void GMHIKernelRaw::copyTableAorB(double **src, double **dst) const
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void GMHIKernelRaw::copyTableC(double **src, double **dst) const
|
|
+void GMHIKernelRaw::copyTableT(double *_src, double *_dst) const
|
|
{
|
|
{
|
|
- for (uint i = 0; i < this->num_dimension; i++)
|
|
+ double p_src = _src;
|
|
- {
|
|
+ double p_dst = _dst;
|
|
- for (uint j = 0; j < this->q->getNumberOfBins(); j++)
|
|
+ for ( int i = 0; i < this->num_dimension * this->q->getNumberOfBins(); i++ )
|
|
- {
|
|
+ {
|
|
-
|
|
+ *p_dst = *p_src;
|
|
- dst[i][j] = src[i][j];
|
|
+ p_src++;
|
|
- }
|
|
+ p_dst++;
|
|
- }
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
void GMHIKernelRaw::updateTables ( const NICE::Vector _x ) const
|
|
void GMHIKernelRaw::updateTables ( const NICE::Vector _x ) const
|
|
@@ -200,30 +200,24 @@ void GMHIKernelRaw::updateTables ( const NICE::Vector _x ) const
|
|
|
|
|
|
double * prototypes;
|
|
double * prototypes;
|
|
double * p_prototypes;
|
|
double * p_prototypes;
|
|
|
|
+ uint hmax;
|
|
|
|
|
|
|
|
|
|
if ( this->q != NULL)
|
|
if ( this->q != NULL)
|
|
{
|
|
{
|
|
|
|
|
|
- uint hmax = _q->getNumberOfBins();
|
|
+ hmax = this->q->getNumberOfBins();
|
|
|
|
|
|
|
|
|
|
- double * prototypes = new double [ hmax * this->ui_d ];
|
|
+ double * prototypes = new double [ hmax * this->num_dimension ];
|
|
double * p_prototypes = prototypes;
|
|
double * p_prototypes = prototypes;
|
|
|
|
|
|
- for (uint dim = 0; dim < this->ui_d; dim++)
|
|
+ for (uint dim = 0; dim < this->num_dimension; dim++)
|
|
{
|
|
{
|
|
for ( uint i = 0 ; i < hmax ; i++ )
|
|
for ( uint i = 0 ; i < hmax ; i++ )
|
|
{
|
|
{
|
|
- if ( _pf != NULL )
|
|
+ *p_prototypes = this->q->getPrototype( i, dim );
|
|
- {
|
|
+ p_prototypes++;
|
|
- *p_prototypes = _pf->f ( dim, _q->getPrototype( i, dim ) );
|
|
|
|
- } else
|
|
|
|
- {
|
|
|
|
- *p_prototypes = _q->getPrototype( i, dim );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- p_prototypes++;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -234,7 +228,9 @@ void GMHIKernelRaw::updateTables ( const NICE::Vector _x ) const
|
|
double alpha_sum = 0.0;
|
|
double alpha_sum = 0.0;
|
|
double alpha_times_x_sum = 0.0;
|
|
double alpha_times_x_sum = 0.0;
|
|
uint nnz = nnz_per_dimension[dim];
|
|
uint nnz = nnz_per_dimension[dim];
|
|
|
|
+
|
|
|
|
|
|
|
|
+
|
|
|
|
|
|
sparseVectorElement *training_values_in_dim = examples_raw[dim];
|
|
sparseVectorElement *training_values_in_dim = examples_raw[dim];
|
|
for ( uint cntNonzeroFeat = 0; cntNonzeroFeat < nnz; cntNonzeroFeat++, training_values_in_dim++ )
|
|
for ( uint cntNonzeroFeat = 0; cntNonzeroFeat < nnz; cntNonzeroFeat++, training_values_in_dim++ )
|
|
@@ -249,61 +245,82 @@ void GMHIKernelRaw::updateTables ( const NICE::Vector _x ) const
|
|
|
|
|
|
alpha_sum += _x[index];
|
|
alpha_sum += _x[index];
|
|
this->table_B[dim][cntNonzeroFeat] = alpha_sum;
|
|
this->table_B[dim][cntNonzeroFeat] = alpha_sum;
|
|
|
|
+ }
|
|
|
|
|
|
- if ( this->q != NULL)
|
|
+ if ( this->q != NULL)
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ uint idxProto ( 0 );
|
|
|
|
+ double t;
|
|
|
|
+
|
|
|
|
+ uint idxProtoElem;
|
|
|
|
+
|
|
|
|
+ sparseVectorElement * i = examples_raw[dim];
|
|
|
|
+ sparseVectorElement * iPredecessor = examples_raw[dim];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ int indexElem = 0;
|
|
|
|
+
|
|
|
|
+ double elem = i->value;
|
|
|
|
+
|
|
|
|
+ for (uint idxProto = 0; idxProto < hmax; idxProto++)
|
|
{
|
|
{
|
|
-
|
|
+ double fvalProto = prototypes[ dim*hmax + idxProto ];
|
|
-
|
|
+ double t;
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ idxProtoElem = this->q->quantize ( elem, dim );
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ if ( (indexElem == 0) && (idxProto < idxProtoElem) )
|
|
-
|
|
+ {
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ t = fvalProto*( this->table_B[ dim ][ nnz-1 ] );
|
|
-
|
|
+ }
|
|
-
|
|
+ else
|
|
-
|
|
+ {
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ while ( (idxProto >= idxProtoElem) && ( indexElem < ( nnz - 1 ) ) )
|
|
-
|
|
+ {
|
|
-
|
|
+ indexElem++;
|
|
-
|
|
+ iPredecessor = i;
|
|
-
|
|
+ i++;
|
|
-
|
|
+
|
|
-
|
|
+ if ( i->value != iPredecessor->value )
|
|
-
|
|
+ {
|
|
-
|
|
+ idxProtoElem = this->q->quantize ( i->value, dim );
|
|
-
|
|
+ }
|
|
-
|
|
+ }
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ if ( (idxProto >= idxProtoElem) && ( indexElem==( nnz-1 ) ) )
|
|
-
|
|
+ {
|
|
-
|
|
+
|
|
-
|
|
+
|
|
-
|
|
+ t = table_A[ dim ][ indexElem ];
|
|
-
|
|
+ }
|
|
-
|
|
+ else
|
|
-
|
|
+ {
|
|
-
|
|
+
|
|
-
|
|
+ t = table_A[ dim ][ indexElem-1 ] + fvalProto*( table_B[ dim ][ nnz-1 ] - table_B[ dim ][ indexElem-1 ] );
|
|
-
|
|
+ }
|
|
-
|
|
+ }
|
|
-
|
|
+
|
|
-
|
|
+ this->table_T[ dim*hmax + idxProto ] = t;
|
|
-
|
|
+ }
|
|
-
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
+ if ( this->q != NULL)
|
|
|
|
+ {
|
|
|
|
+ delete [] prototypes;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|