void KPCA::compPrimalEnd () { if (featureCount != dim) retinThrowException("Wrong number of features"); for (size_t i=0;i<featureDim;i++) primalMean[i] /= dim; for (size_t j=0;j<eigenCount;j++) primalValues[j] = (float)(eigens[firstEigen+j].getValue() / dim); }
void SparseVlatCluster::setEigenDecomposition(const float* eigenVectors , const float* eigenValues, size_t vectorsDim, size_t vectorsSize){ if (vectorsDim != vectorsSize) retinThrowException("Not square matrix"); if (vectorsDim != getTensorDim(1)) retinThrowException2("Invalid dim %d != %d", vectorsDim, getTensorDim(1)); U.resize(vectorsDim*vectorsDim); L.resize(vectorsDim); memcpy(&U[0], eigenVectors, vectorsDim*vectorsDim * sizeof(float)); memcpy(&L[0], eigenValues, vectorsDim * sizeof(float)); }
void KPCA::compPrimalBegin(size_t featureDim_,size_t firstEigen_,size_t eigenCount_) { featureCount = 0; featureDim = featureDim_; firstEigen = firstEigen_; eigenCount = eigenCount_; if (firstEigen+eigenCount > eigens.size()) retinThrowException("Invalid eigen dims"); primalFeature.resize(featureDim); primalMean.resize(featureDim); primalValues.resize(eigenCount); primalVectors.resize(featureDim*eigenCount); }
FeatureRef StandardPcaVlatBuilder::getVlat(string & format){ FeatureRef vlat; size_t dim = getDim(format); vlat = boost::make_shared<Feature>(dim); float * data = vlat->data(); for(size_t i = 0 ; i < clusters.size(); i++){ FeatureRef subVlat = clusters[i]->getData(format); memcpy(data, subVlat->data(), subVlat->dim()*sizeof(float)); data += subVlat->dim(); if((size_t)(data - vlat->data()) > dim) retinThrowException("StandardPcaVlatCluster::getVlat => data - vlat->data() > dim"); } return vlat; }
void StandardPcaVlatCluster::add(const float * f, size_t dim){ if(dim != dimPrim) retinThrowException("StandardPcaVlatCluster::add => dim != dimPrim"); counter++; for(size_t i = 0 ; i<dimPrim ; i++) { (*featc)(i,0) = f[i] - (*meanPrim)(i); } for (size_t k = 0; k < dimPrim; k++) { (featDual->data())[k] = vector_ps_double(featc->data(), proj->data()+k*dimPrim, dimPrim); } if(whitening) vector_mul_double(featDual->data(), invsqrtvar->data(), dimPrim); if(degre == 1) vector_add_double(vlat->data(), featDual->data(), dimDual); else matrix_Cpaat_double(vlat->data(), featDual->data(), dimDual); }