コード例 #1
0
ファイル: kmeans.c プロジェクト: RoboEvangelist/cluster
static void GenerateSolution(TRAININGSET *pTS, CODEBOOK *pCBnew, 
			     PARTITIONING *pPnew, CODEBOOK *pCBinit, 
			     PARTITIONING *pPinit, llong *distance, 
			     llong *distanceInit, int InitMethod, int initial) 
{
  int i;
  
  if (initial)
  {
    CopyCodebook(pCBinit, pCBnew);
    CopyPartitioning(pPinit, pPnew);
    for (i = 0; i < BookSize(pTS); i++)
    {
      distance[i] = distanceInit[i];      
    }
  }
  else
  {
    if (InitMethod == 0) 
      SelectRandomRepresentatives(pTS, pCBnew);
    else if (InitMethod == 1)
      SelectRandomWeightedRepresentatives(pTS, pCBnew);
    else 
      SelectRandomRepresentativesbyMarko(pTS, pCBnew);

    GenerateOptimalPartitioningGeneral(pTS, pCBnew, pPnew, MSE);    
    CalculateDistances(pTS, pCBnew, pPnew, distance);
  }
}  /* GenerateSolution() */
コード例 #2
0
// -------------------------------------------------------------------------
int HypothesisEvaluator::calculateCrudeLikelihood(vector<string> &hypotheses, int start_flow,
    float & refLikelihood, float & minDelta, float & minDistToRead, float & distDelta) {

  vector<float> deltaHypotheses;
  vector<float> distHypotheses;
  int retValue = CalculateDistances(hypotheses, start_flow, 0,0,0, deltaHypotheses, distHypotheses);

  if (retValue == -1)
    return -1;

  float totalDelta = CrudeSumOfSquares(deltaHypotheses, minDelta, minDistToRead,  this->DEBUG);

  if (deltaHypotheses[1]-minDelta < 0)
    refLikelihood = 0;
  else
    refLikelihood = deltaHypotheses[1]-minDelta;

  if (deltaHypotheses[0]-minDelta < 0)
    distDelta = 0;
  else
    distDelta = deltaHypotheses[0]-minDelta;

  if (totalDelta < 0)
    return -1;

  return 0;
}
コード例 #3
0
ファイル: kmeans.c プロジェクト: RoboEvangelist/cluster
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() */
コード例 #4
0
int HypothesisEvaluator::calculateHPLikelihood(const string& read_sequence, const int startFlow, int refHpLen, int flowPosition, float & new_metric, bool strand) {

  new_metric = 0;
  vector<string> Hypotheses;
  if (!strand) {
    char * seqRev = new char[read_sequence.length()+1];
    reverseComplement(read_sequence, seqRev);
    Hypotheses.push_back(string((const char*) seqRev));
  } else
    Hypotheses.push_back(read_sequence);

  vector<float> DistanceObserved(1);
  vector<float> DistanceHypotheses(0);
  int return_val;

  return_val = CalculateDistances(Hypotheses, startFlow, refHpLen, flowPosition, 0,
                                  DistanceObserved, DistanceHypotheses);
  if (return_val == -1)
    return return_val;

  new_metric = DistanceObserved[0];
  return 0;
}