示例#1
0
void FidoInterface::gridSearchOptimize() {
  if (VERB > 1) {
    std::cerr << "Running super grid search..." << std::endl;
  }
  
  double alpha_step = 0.05;
  double beta_step = 0.05;
  double gamma_step = 0.05;
  
  double beta_init = 0.00001;
  double alpha_init = 0.001;
  double gamma_init = 0.1;
  
  double gamma_limit = 0.5;
  double beta_limit = 0.05;
  double alpha_limit = 0.5;
  
  if (alpha_ != -1) alpha_init = alpha_limit = alpha_;
  if ( beta_ != -1) beta_init = beta_limit = beta_;
  if (gamma_ != -1) gamma_init = gamma_limit = gamma_;
  
  std::vector<double> gamma_search, beta_search, alpha_search;
  
  //NOTE very annoying the residue error of the floats that get acummulated in every iteration
  for (int i = 0; gamma_init + gamma_step*i <= gamma_limit; ++i) { 
    gamma_search.push_back(gamma_init + gamma_step*i);
  }
  
  double lbi = log10(beta_init);
  for (int i = 0; lbi + i*beta_step <= Round(log10(beta_limit),2); ++i) {
    double j = lbi + i*beta_step;
    double original = pow(10,j);
    double beta_local = original - beta_init;
    if (beta_local > 0.0) beta_local = original;
    beta_search.push_back(beta_local);
  }
  
  double lai = log10(alpha_init);
  for (int i = 0; lai + i*alpha_step <= Round(log10(alpha_limit),2); ++i) {
    double k = lai + i*alpha_step;
    alpha_search.push_back(pow(10,k));
  }
  
  gridSearch(alpha_search, beta_search, gamma_search);
}
示例#2
0
int main(){
  dic = inputDictionary();
  int testCase, i, j, k, l, m, n, o, p;
  char key;

  scanf("%d\n", &testCase);
  for(i=0; i<testCase; i++){
    scanf("%d %d\n", &row, &column);
    char line[column];
    grid = malloc(sizeof(char*)*row);
    for(j=0; j<row; j++){
      grid[j] = malloc(sizeof(char)*column);
    }

    for(k=0; k<row; k++){
      scanf("%s", line);
      for(l=0; l<column; l++){
        grid[k][l]= line[l];
      }

    }
    printf("Words Found Gird #%d:\n", i+1);
    gridSearch();
}
  //After everything is done free the memory

  for(i=0; i<row; i++){ //free dic
    free(grid[i]);
  }
  free(grid);

  for(i=0; i<num; i++){ //free dic
    free(dic[i]);
  }
  free(dic);
return 0;
}
示例#3
0
void FidoInterface::gridSearch() {
  std::vector<double> gamma_search, beta_search, alpha_search;
  
  switch(gridSearchDepth_) {
    case 0:    
      gamma_search.push_back(0.5);
      
      beta_search.push_back(0.001);
      
      alpha_search.push_back(0.008);
      alpha_search.push_back(0.032);
      alpha_search.push_back(0.128);
      break;
    
    case 1:
      gamma_search.push_back(0.1);
      gamma_search.push_back(0.5);
      gamma_search.push_back(0.9);
      
      beta_search.push_back(0.001);
      for (double k = 0.002; k <= 0.4; k*=4) {
       alpha_search.push_back(k);
      }
      break;
      
    case 2:
      gamma_search.push_back(0.1);
      gamma_search.push_back(0.3);
      gamma_search.push_back(0.5);
      gamma_search.push_back(0.7);
      gamma_search.push_back(0.9);
      
      beta_search.push_back(0.001);
      for (double k = 0.001; k <= 0.4; k*=2) {
       alpha_search.push_back(k);
      }
      break;
    case 3:
      for (double k = 0.01; k <= 0.76; k+=0.05) {
       alpha_search.push_back(k);
      }
      beta_search.push_back(0.001);
      for (double k = 0.05; k <= 0.95; k+=0.05) {
       gamma_search.push_back(k);
      }
      break;
    case 4: // grid search from FIDO paper
      for (double k = 0.01; k <= 0.76; k+=0.05) {
       alpha_search.push_back(k);
      }
      for (double k = 0.0; k <= 0.80; k+=0.05) {
       beta_search.push_back(k);
      }
      for (double k = 0.1; k <= 0.9; k+=0.1) {
       gamma_search.push_back(k);
      }
      break;
    default:
      gamma_search.push_back(0.5);
      
      beta_search.push_back(0.001);
      
      alpha_search.push_back(0.008);
      alpha_search.push_back(0.032);
      alpha_search.push_back(0.128);
      break;
  }

  if (alpha_ != -1) alpha_search.push_back(alpha_);
  if ( beta_ != -1) beta_search.push_back(beta_);
  if (gamma_ != -1) gamma_search.push_back(gamma_);
  
  gridSearch(alpha_search, beta_search, gamma_search);
}
示例#4
0
void FidoInterface::computeProbabilities(const std::string& fname) {
  ifstream fin;
  if (fname.size() > 0) {
    fin.open(fname.c_str());
    proteinGraph_->read(fin);
  } else {
    proteinGraph_->read(peptideScores_);
  }
  
  if (trivialGrouping_) updateTargetDecoySizes();
  
  time_t startTime;
  clock_t startClock;
  time(&startTime);
  startClock = clock();
  
  if (mayufdr) {
    computeFDR();
  }
  
  if (doGridSearch_) {
    if (VERB > 1) {
      std::cerr << "The parameters for the model will be estimated by grid search.\n" << std::endl;
    }
    
    if (kOptimizeParams)
      gridSearchOptimize(); 
    else
      gridSearch();
    
    time_t procStart;
    clock_t procStartClock = clock();
    time(&procStart);
    double diff = difftime(procStart, startTime);
    if (VERB > 1) cerr << "Estimating the parameters took : "
      << ((double)(procStartClock - startClock)) / (double)CLOCKS_PER_SEC
      << " cpu seconds or " << diff << " seconds wall time" << endl;
  }

  if (VERB > 1) {
    cerr << "The following parameters have been chosen:\n";
    std::cerr.precision(10);
    cerr << "alpha = " << alpha_ << endl;
    cerr << "beta  = " << beta_ << endl;
    cerr << "gamma = " << gamma_ << endl;
    std::cerr.unsetf(std::ios::floatfield);
    cerr << "\nProtein level probabilities will now be estimated\n";
  }


  if (gridSearchThreshold_ > 0.0 && doGridSearch_) {
    //NOTE reset the tree after grid searching
    proteinGraph_->setProteinThreshold(proteinThreshold_);
    proteinGraph_->setPsmThreshold(kPsmThreshold);
    proteinGraph_->setPeptideThreshold(kPeptideThreshold);
    proteinGraph_->setNoClustering(noClustering_);
    proteinGraph_->setNoPartitioning(noPartitioning_);
    proteinGraph_->setNoPruning(noPruning_);
    proteinGraph_->setTrivialGrouping(trivialGrouping_);
    proteinGraph_->setMultipleLabeledPeptides(kAddPeptideDecoyLabel);
    
    if (fname.size() > 0) {
      proteinGraph_->read(fin);
    } else {
      proteinGraph_->read(peptideScores_);
    }
    if (trivialGrouping_) updateTargetDecoySizes();
  }
  
  proteinGraph_->setAlphaBetaGamma(alpha_, beta_, gamma_);
  proteinGraph_->getProteinProbs();
  pepProteinMap_.clear();
  proteinGraph_->getProteinProbsPercolator(pepProteinMap_);
}
示例#5
0
//NOTE almost entirely duplicated of computeProbabilities, it could be refactored
void FidoInterface::computeProbabilitiesFromFile(ifstream &fin)
{
  
  proteinGraph->read(fin);
  
  time_t startTime;
  clock_t startClock;
  time(&startTime);
  startClock = clock();
  
  if(mayufdr)
  {
    computeFDR();
  }
  
  if(dogridSearch) 
  {
    if(VERB > 1) 
    {
      std::cerr << "The parameters for the model will be estimated by grid search.\n" << std::endl;
    }
    
    if(optimize)
      gridSearchOptimize(); 
    else
      gridSearch();
    
    time_t procStart;
    clock_t procStartClock = clock();
    time(&procStart);
    double diff = difftime(procStart, startTime);
    if (VERB > 1) cerr << "Estimating the parameters took : "
      << ((double)(procStartClock - startClock)) / (double)CLOCKS_PER_SEC
      << " cpu seconds or " << diff << " seconds wall time" << endl;
  }

  if(VERB > 1) 
  {
      cerr << "The following parameters have been chosen:\n";
      std::cerr.precision(10);
      cerr << "gamma = " << gamma << endl;
      cerr << "alpha = " << alpha << endl;
      cerr << "beta  = " << beta << endl;
      std::cerr.unsetf(std::ios::floatfield);
      cerr << "\nProtein level probabilities will now be estimated";
  }


  if(dogridSearch && reduceTree)
  {
    //NOTE lets create the tree again with all the members
    double local_protein_threshold = proteinThreshold;
    if(truncate) local_protein_threshold = 0.0;
    proteinGraph->setProteinThreshold(local_protein_threshold);
    proteinGraph->setPsmThreshold(psmThreshold);
    proteinGraph->setPeptideThreshold(peptideThreshold);
    proteinGraph->setGroupProteins(nogroupProteins);
    proteinGraph->setSeparateProteins(noseparate);
    proteinGraph->setPruneProteins(noprune);
    proteinGraph->setMultipleLabeledPeptides(allow_multiple_labeled_peptides);
    proteinGraph->read(fin);
  }
  
  proteinGraph->setAlphaBetaGamma(alpha,beta,gamma);
  proteinGraph->getProteinProbs();
  pepProteins.clear();
  proteinGraph->getProteinProbsPercolator(pepProteins);
}