示例#1
0
static void InitializeSolutions(TRAININGSET *pTS, CODEBOOK *pCB, 
PARTITIONING *pP, CODEBOOK *pCBnew, PARTITIONING *pPnew, CODEBOOK *pCBinit, 
PARTITIONING *pPinit, llong *distanceInit, int clus, int initial)
{
  CreateNewCodebook(pCBnew, clus, pTS);
  CreateNewPartitioning(pPnew, pTS, clus);
  CreateNewCodebook(pCBinit, clus, pTS);
  CreateNewPartitioning(pPinit, pTS, clus);
  
  if (initial) 
  {  
    if (initial == 1)
    {
      GenerateOptimalPartitioningGeneral(pTS, pCB, pP, MSE);
    } 
    else if (initial == 2)
    {
      GenerateOptimalCodebookGeneral(pTS, pCB, pP, MSE);
    } 
      
    CopyCodebook(pCB, pCBinit);
    CopyPartitioning(pP, pPinit);
    CalculateDistances(pTS, pCBinit, pPinit, distanceInit);
  }
}  /* InitializeSolutions() */
示例#2
0
TSData::TSData(TRAININGSET *ts)
{
    this->dataType = TSFILE;
    CreateNewCodebook(&this->trainingSet, BookSize(ts), ts);
    CopyCodebook(ts, &this->trainingSet);

    m_fileName = "(imported training set)";
    suggestedFilename = "trainingset";
}
示例#3
0
//modify by QP on 2k8-4-7 
//change the function ReadInitialCBorPA( )
//add two parameters int Minclus and Maxclus,delete int clus
//Minclus -- Min number of clusters
//Maxclus -- Max number of clusters
int ReadInitialCBorPA(char *InName, int Minclus, int Maxclus, TRAININGSET *pTS, 
CODEBOOK *pCB, PARTITIONING *pP) 
{
  int useInitial = 0;
  
  if (*InName)  /* we use initial codebook/partitioning */
  {
    switch (DetermineCBFileType(InName)) {
      case TSFILE: case CBFILE:
        ReadCodebook(InName, pCB);
        useInitial = 1;
        //modify by QP on 2k8-4-7 
		//If we use initial ones, we just need to judge the size of codebook/
		//training set is in the range: [Minclus, Maxclus]
		if (BookSize(pCB) < Minclus || BookSize(pCB) > Maxclus )
        {
          ErrorMessage("\nERROR: Number of vectors in initial codebook ");
          ErrorMessage("(%d) <> number of clusters ", BookSize(pCB));
          ErrorMessage("(%d)(%d)!\n\n", Minclus, Maxclus);
          FreeCodebook(pTS);
          FreeCodebook(pCB);
          ExitProcessing(FATAL_ERROR);
        }
        
        CreateNewPartitioning(pP, pTS, BookSize(pCB));
        break;
        
      case PAFILE:
        ReadPartitioning(InName, pP, pTS);
        useInitial = 2;
        
        //modify by QP on 2k8-4-7 
		//judge the size of partitioning is in the range: [Minclus, Maxclus]
        if (PartitionCount(pP)<Minclus || PartitionCount(pP) > Maxclus)
        {
          ErrorMessage("\nERROR: Number of partitions in initial partitioning ");
          ErrorMessage("(%d) <> number of clusters ", PartitionCount(pP));
          ErrorMessage("(%d)(%d)!\n\n", Minclus, Maxclus);
          FreeCodebook(pTS);
          FreePartitioning(pP);
          ExitProcessing(FATAL_ERROR);
        }
        
        CreateNewCodebook(pCB, PartitionCount(pP), pTS);
        break;
        
      case NOTFOUND:
        ErrorMessage("\nERROR: Type of initial codebook/partitioning file "
            "%s is unidentified!\n\n", InName);
        FreeCodebook(pTS);
        ExitProcessing(FATAL_ERROR);
        break;
    }      
  }
  else  /* we don't use initial codebook/partitioning */
  {
 //   CreateNewCodebook(pCB, clus, pTS);
 //   CreateNewPartitioning(pP, pTS, clus);
    useInitial = 0;
  }
  
  return useInitial;
}
示例#4
0
TRAININGSET* TSData::getDataCopy() {
    CODEBOOK* rv = new CODEBOOK;
    CreateNewCodebook(rv, BookSize((&trainingSet)), (&trainingSet));
    CopyCodebook((&trainingSet), rv);
    return rv;
}