/* VQ.cpp Written by: Michael Götting (2007) University of Bielefeld AG Neuroinformatik mgoettin@techfak.uni-bielefeld.de */ #include "VQ.h" #include "Mathematics.h" #include "StackTimer.h" using namespace std; using namespace icl; namespace icl { // {{{ Constructor/ Destructor template class U> VQ::VQ(ImgBase *poSrc, bool deepCopyData) { FUNCTION_LOG(""); m_poData = new U(poSrc, deepCopyData); m_vecRefDataPtr = m_poData->getDataPtr(); m_uiVQDim = m_poData->getDim(); m_uiSrcDim = poSrc->getDim(); m_bClusterIsInitialized = false; m_uiMaxTrainSteps=3000; } template class U> VQ::~VQ() { FUNCTION_LOG(""); } // }}} // {{{ cluster functions template class U> void VQ::createCluster(unsigned int uiCenter) { FUNCTION_LOG(""); // store variables m_uiCenter = uiCenter; // allocate memory for cluster m_vecCluster.resize(m_uiCenter); for (unsigned int i=0;i class U> void VQ::resizeCluster(unsigned int uiCenter) { FUNCTION_LOG(""); m_vecCluster.clear(); createCluster(uiCenter); } template class U> void VQ::clearCluster() { FUNCTION_LOG(""); for (unsigned int i=0;i class U> void VQ::initClusterFromSrc(vqinitmode eMode, unsigned int uiStart) { BENCHMARK_THIS_FUNCTION FUNCTION_LOG(""); unsigned int uiRndPos; switch(eMode) { case initRnd: for (unsigned int i=0;i(m_vecCluster[i],255.0); } break; case initRndFromData: for(unsigned int i=0;i class U> void VQ::vq(unsigned int uiDataIdx) { BENCHMARK_THIS_FUNCTION; FUNCTION_LOG(""); // check pre start options ICLASSERT(m_bClusterIsInitialized); // variable initilization unsigned int uiMinDistIdx; // The min distance codeword to the source data float fErrBuf=0; // The minimal distance // calc the euklidian distance to each codeword uiMinDistIdx = nn(uiDataIdx, fErrBuf); // update the codebook for (unsigned int i=0;i class U> void VQ::lbg() { // {{{ open BENCHMARK_THIS_FUNCTION; FUNCTION_LOG(""); // check pre start options ICLASSERT(m_bClusterIsInitialized); // variable initilization unsigned int uiMinDistIdx; // The min distance codeword float fErrBuf=0; vector vecClustCnt(m_uiCenter); // cluster size counters vector > vecAccu(m_uiCenter); // data accumulators for (unsigned int i=0;i::max(); // calc the euklidian distance to each codeword LOOP_LOG("Center -> Distance"); for (unsigned int i=0;i "< class U> void VQ::printCluster() { BENCHMARK_THIS_FUNCTION; FUNCTION_LOG(""); // calc center with minimal distance printf("Cluster data\n"); printf("------------\n"); for (unsigned int i=0;i; template class VQ; template class VQ; }