Beispiel #1
0
void FidoInterface::gridSearch(std::vector<double>& alpha_search, 
    std::vector<double>& beta_search, 
    std::vector<double>& gamma_search) {
  double gamma_best = -1.0, alpha_best = -1.0, beta_best = -1.0;
  double best_objective = -100000000;
  double current_objective;
  
  for (unsigned int i = 0; i < gamma_search.size(); i++) {
    double gamma_local = gamma_search[i];
    for (unsigned int j = 0; j < alpha_search.size(); j++) {
      double alpha_local = alpha_search[j];
      for (unsigned int k = 0; k < beta_search.size(); k++) {
        double beta_local = beta_search[k];
        
        current_objective = calcObjective(alpha_local, beta_local, gamma_local);
        if (current_objective > best_objective) {
          best_objective = current_objective;
          gamma_best = gamma_local;
          alpha_best = alpha_local;
          beta_best = beta_local;
        }
      }
    }
  }
  alpha_ = alpha_best;
  beta_ = beta_best;
  gamma_ = gamma_best;
}
void dtw_model::validate(Corpus& corpus) {
  static const size_t MINIATURE_SIZE = 10000;
  static vector<tsample> samples = corpus.getSamples(MINIATURE_SIZE);
  static double objective = 0;
  static bool aboutToStop = false;
  static const double SOFT_THRESHOLD = 2e-6 * _learning_rate;
  static const double HARD_THRESHOLD = SOFT_THRESHOLD * 0.1;
  static size_t MIN_ITERATION = 128;
  static size_t itr = 0;

  double obj = calcObjective(samples);
  double diff = obj - objective;
  double improveRate = abs(diff / objective);

  printf("objective = %.7f \t prev-objective = %.7f \n", obj, objective);
  printf("improvement rate on dev-set of size %lu = %.6e ", samples.size(), improveRate);
  printf(", still "GREEN"%.0f"COLOREND" times of threshold \n", improveRate / SOFT_THRESHOLD);

  if (itr > MIN_ITERATION) {
    if (improveRate != improveRate)
      exit(-1);
    
    if (improveRate < HARD_THRESHOLD) {
      printf("\nObjective function on dev-set is no longer decreasing...\n");
      printf("Training process "GREEN"DONE"COLOREND"\n");
      // doPause();
      exit(0);
    }
    else if (aboutToStop || improveRate < SOFT_THRESHOLD) {
      aboutToStop = true;
      _learning_rate /= 2;
    }
  }

  objective = obj;
  ++itr;
}