コード例 #1
0
ファイル: poly_test.c プロジェクト: FDUJiChao/wdan-ics
int main(int argc, char *argv[])
{
  int i;
  double cpe = cstandard[0].cref;
  double cfix = cstandard[1].cref;
  if (argc > 1 && !strcmp(argv[1], "-v"))
      verbose = 1;
  if (argc > 1) {
    test_degree = atoi(argv[1]);
    if (test_degree < 1) {
      fprintf(stderr, "Must specify maximum degree > 1\n");
      exit(1);
    }
    if (test_degree > MAXDEGREE) {
      fprintf(stderr, "Must specify maximum degree <= %d\n", MAXDEGREE);
      exit(1);
    }
  }
  init();
  for (i = 0; peval_fun_tab[i].f != NULL; i++) {
    run_poly(peval_fun_tab[i].f, peval_fun_tab[i].descr, &cpe, &cfix);
    if (i == 0)
      printf("  Best CPE score = %.0f\n",
	     compute_score(cpe, cstandard[0].cref, cstandard[0].cbest));
    if (i == 1)
      printf("  Best C(10) score = %.0f\n",
	     compute_score(cfix, cstandard[1].cref, cstandard[1].cbest));
  }
  return 0;
}
コード例 #2
0
ファイル: main.cpp プロジェクト: pdib/octo-wallhack
int justify_text(const int & page_size,
                 const std::vector<std::string> & words,
                 std::vector<int> & solution,
                 std::vector<int> & dyn_table,
                 int index) {
    if (words.size() == 0) return 0;
    if (dyn_table[index] > 0) return dyn_table[index];
    int line_size = -1;
    int score = -1;
    int i = 1;
    for (i = 1; i < words.size(); i++) {
        line_size += words[i-1].length() + 1;
        if (line_size > page_size) break;
        int new_score = compute_score(line_size, page_size)
            + justify_text(page_size,
                           std::vector<std::string>(begin(words) + i,
                                                    end(words)),
                           solution,
                           dyn_table,
                           index + i);
        if (score < 0 || score > new_score) score = new_score;
    }
    dyn_table[index] = score;
    solution[index] = index + i - 1;
    return score;
}
コード例 #3
0
ファイル: filein.c プロジェクト: jfujihub/league
void set_away_team(TEAM *team, char **token)
{
	strcpy(team->name, token[AWAY_TEAM_COL]);
	team->gfo = atoi(token[AWAY_GOAL_COL]);
	team->gag = atoi(token[HOME_GOAL_COL]);
	compute_score(team);
}
コード例 #4
0
ファイル: compute_score.c プロジェクト: slyj91/CS1010
int main()
{
	char word[MAX]={'\0'};
	printf("Word please:");
	scanf("%s", word);
	
	printf("%d\n", compute_score(word));

	return 0;
}
コード例 #5
0
ファイル: mapsmerger.cpp プロジェクト: blsailer/bearingslam
// finds the transformation matrix with the highest score, stores it in "best_transformation", and returns the index of the first vector of the couple chosen in the first map (the point around which the rotation is performed)
unsigned int find_best_transformation(std::vector<Eigen::Vector3d> * map1,
		std::vector<Eigen::Vector3d> * map2,
		Eigen::Matrix3d * best_transformation, double distance_threshold) {
	// variables for storing the best results
	unsigned int best_points[4]; //	<i1, i2, j1, j2>
	unsigned int most_friends = 0;

	unsigned int evaluated_models = 0;

	// i1 and i2 are indices for map1.
	// j1 and j2 are indices for map2
	for (unsigned int i1 = 0; i1 < map1->size() - 1; i1++) {
		for (unsigned int i2 = i1 + 1; i2 < map1->size(); i2++) {
			// for every couple of points in the first map

			for (unsigned int j1 = 0; j1 < map2->size() - 1; j1++) {
				for (unsigned int j2 = 0; j2 < map2->size(); j2++) {
					// for every couple of points in the second map
					if (j2 == j1)
						continue; // must be a couple!

					Eigen::Matrix3d transf = computeTransformation((*map1)[i1],
							(*map1)[i2], (*map2)[j1], (*map2)[j2]);

					// do checks on the scale
					if(!approveModel(&transf)){
						continue;
					}

					// apply the scale factor
					transf(0,0) = transf(0,0) / transf(2,2);
					transf(0,1) = transf(0,1) / transf(2,2);
					transf(1,0) = transf(1,0) / transf(2,2);
					transf(1,1) = transf(1,1) / transf(2,2);
					transf(2,2) = 1;

					unsigned int friends = compute_score(map1, map2, transf,
							(*map1)[i1], distance_threshold);
					evaluated_models++;

					if (friends > most_friends) {
						most_friends = friends;
						best_points[0] = i1;
						best_points[1] = i2;
						best_points[2] = j1;
						best_points[3] = j2;
						*best_transformation = transf;
					}
				}
			}
		}
	}
	std::cout << "evaluated models: " << evaluated_models << "\n";
	return best_points[0];
}
コード例 #6
0
WeightedFitParameters WeightedProfileFitter::search_fit_parameters(
                           ProfilesTemp& partial_profiles,
                           float min_c1, float max_c1,
                           float min_c2, float max_c2,
                           float old_chi, std::vector<double>& weights) const {
  int c1_cells = 10;
  int c2_cells = 10;
  if(old_chi < (std::numeric_limits<float>::max()-1)) { // second iteration
    c1_cells = 5;
    c2_cells = 5;
  }

  float delta_c1 = (max_c1-min_c1)/c1_cells;
  float delta_c2 = (max_c2-min_c2)/c2_cells;

  bool last_c1 = false;
  bool last_c2 = false;
  if(delta_c1 < 0.0001) { c1_cells=1; delta_c1 = max_c1-min_c1; last_c1=true; }
  if(delta_c2 < 0.001) { c2_cells=1; delta_c2 = max_c2-min_c2; last_c2=true; }
  float best_c1(1.0), best_c2(0.0), best_chi(old_chi);
  bool best_set = false;

  // c1 iteration
  float c1(min_c1);
  for(int i=0; i<=c1_cells; i++, c1+= delta_c1) {
    // c2 iteration
    float c2 = min_c2;
    for(int j=0; j<=c2_cells; j++, c2+= delta_c2) {
      // sum up the profiles for c1/c2 combo
      for(unsigned int k=0; k<partial_profiles.size(); k++)
        partial_profiles[k]->sum_partial_profiles(c1, c2);
      std::vector<double> curr_weights;
      float curr_chi = compute_score(partial_profiles, curr_weights);
      if(!best_set || curr_chi < best_chi) {
        best_set = true;
        best_chi = curr_chi;
        best_c1 = c1;
        best_c2 = c2;
        weights = curr_weights;
      }
    }
  }

  if(std::fabs(best_chi-old_chi) > 0.005 &&
     (!(last_c1 && last_c2))) { //refine more
    min_c1 = std::max(best_c1-delta_c1, min_c1);
    max_c1 = std::min(best_c1+delta_c1, max_c1);
    min_c2 = std::max(best_c2-delta_c2, min_c2);
    max_c2 = std::min(best_c2+delta_c2, max_c2);
    return search_fit_parameters(partial_profiles,
                                 min_c1, max_c1, min_c2, max_c2,
                                 best_chi, weights);
  }
  return WeightedFitParameters(best_chi, best_c1, best_c2, (Floats)weights);
}
コード例 #7
0
ファイル: go_benchmark.c プロジェクト: 5tivi/julia
static void
benchmark(int num_games_per_point)
{
  int i, j;
  unsigned int random_seed = 1U;
  board_size = 9;
  komi = 0.5;

  init_brown(random_seed);

  for (i = 0; i < board_size; i++) {
    for (j = 0; j < board_size; j++) {
      int white_wins = 0;
      int black_wins = 0;
      int k;
      for (k = 0; k < num_games_per_point; k++) {
	int passes = 0;
	int num_moves = 1;
	int color = WHITE;
        clear_board();
	play_move(i, j, BLACK);
        while (passes < 3 && num_moves < 600) {
	  int m, n;
          generate_move(&m, &n, color);
          play_move(m, n, color);
          if (pass_move(m, n)) {
            passes++;
          }
          else {
            passes = 0;
          }
          num_moves++;
          color = OTHER_COLOR(color);
        }
	if (passes == 3) {
	  if (compute_score() > 0) {
	    white_wins++;
	  }
	  else {
	    black_wins++;
	  }
	}
      }
      /*
      printf("%d %d %f\n", i, j,
	     (float) black_wins / (float) (black_wins + white_wins));
      */
    }
  }
}
コード例 #8
0
Float evaluate_sequences(vector<vector<int> > &goldS,
			 vector<vector<int> > &predicted,
			 vector<string> &LIS ,
			 int num_labels,
			 int verbose,
			 ofstream &out){
  int numtag,numctag,numbtag;
  numtag=numctag=numbtag=0;
  int num_class =  ( num_labels / 2 ) + 1;
  vector<int> ccount(num_class,0),pcount(num_class,0),ncorrect(num_class,0),
	      nleft(num_class,0),nright(num_class,0),
	      nbcorrect(num_class,0),nbleft(num_class,0),nbright(num_class,0);
  int match,bmatch;
  match=bmatch=0;
  int num_seq = goldS.size();

  for (int i = 0; i < num_seq ; ++i){
  // For each sequence
       unsigned int N = goldS[i].size();
       if ( N != predicted[i].size() ) {
	  cerr << "Unmatching length of labels for sentence" << i << "\n";
          abort();
       }
       for ( unsigned int n = 0 ; n < N ; ++n, ++numtag )   {
          int clabel = goldS[i][n];
          int cclass = class_type( clabel );
          int cbraket = braket_type( n, goldS[i] );
          if ( cbraket == SBrac || cbraket == BBrac ) {
		ccount[cclass]++;
          }

	  int plabel = predicted[i][n];
          int pclass = class_type( plabel );
          int pbraket = braket_type( n, predicted[i] );
          if ( pbraket == SBrac || pbraket == BBrac ) {
		pcount[pclass]++;
          }

          if ( cbraket == pbraket ) numbtag++;
          if ( clabel == plabel && cbraket == pbraket ) numctag++;
          if ( pbraket == SBrac  &&  cbraket == SBrac ) {
                 nbcorrect[pclass]++; nbleft[pclass]++; nbright[pclass]++;
		 if( pclass == cclass ) { 
		     ncorrect[pclass]++; nleft[pclass]++; nright[pclass]++; 
		 }
	  }
	  else if ( pbraket == SBrac  &&  cbraket == EBrac ) { 
		 nbright[pclass]++;
		 if( pclass == cclass ) { nright[pclass]++; }
	  }
	  else if ( pbraket == SBrac  &&  cbraket == BBrac ) { 
		 nbleft[pclass]++;
		 if( pclass == cclass ) { nleft[pclass]++; }
	  }
	  else if ( pbraket == BBrac  &&  cbraket == SBrac ) { 
		 nbleft[pclass]++;
		 if( pclass == cclass ) { nleft[pclass]++; }
	  }
	  else if ( pbraket == BBrac  &&  cbraket == BBrac ) { 
		 nbleft[pclass]++;   bmatch=1;
		 if( pclass == cclass ) { nleft[pclass]++; match=1;}
	  }
/*
          if ( pbraket != cbraket ) bmatch = 0;
	  if (!(clabel == plabel && cbraket == pbraket ) ) match = 0;
	  if ( pbraket == none || cbraket == none )  match=bmatch=0;
*/
          if ( pbraket != cbraket || pbraket == none )  bmatch = 0;
          if ( cclass != pclass || !bmatch )            match = 0;

	  if ( pbraket == EBrac && cbraket == SBrac )  {
		 nbright[pclass]++;
		 if( pclass == cclass ) { nright[pclass]++; }
      	  }
          if ( pbraket == EBrac && cbraket == EBrac ) {
		if( bmatch )  nbcorrect[pclass]++;
		nbright[pclass]++;
		if( pclass == cclass ) {
		     if ( match && ncorrect[pclass] <= pcount[pclass]) 
			 ncorrect[pclass]++;
		     nright[pclass]++;	
		}
	  }
       }
  }


  Float score;
  int numans = getsum( pcount );
  int numref = getsum( ccount );
  if (verbose) {
    out << "\n[Tagging Performance]\n";
    out << "# of tags: " << numtag << ",\t correct tags: " << numctag
	<< ",\t correct IOBs: " << numbtag << "\n";
    out << "precision with class info: " << (float)numctag/numtag;
    out << ",\t w/o class info: " <<  (float)numbtag/numtag << "\n";
    out << "\n[Object Identification Performance]\n";
    out << "# of OBJECTs: " << numref << "\t ANSWERs: " << numans << ".\n";
    out << "\n# (recall / precision / f-score) of ...\n";
  }
  if ( !numref ) cerr << "\n\nNo names in reference!\n";
  if ( !numans ) cerr << "\n\nNo names in answers!\n";

  Float ret_val = compute_score( getsum(ncorrect), numans, numref , 
				 "FULLY CORRECT answer", verbose, out);
/* There is a bug on the right
  score = compute_score( getsum(nleft), numans, numref , 
			 "correct LEFT boundary", verbose, out );
  score = compute_score( getsum(nright), numans, numref , 
			 "correct RIGHT boundary", verbose, out );
 
*/
  if (num_class > 2 && verbose )
  for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) {
    string cl_str = LIS[reverse_class_type(cl)];
    out << "\n[" << cl << "/" << string(cl_str,2,int(cl_str.size()-2)) << "\tIdentification Performance]\n";
    out << "# of OBJECTs: " << ccount[cl] << ",\t ANSWERs: " << pcount[cl];
    out << "\n# (recall / precision / f-score) of ...\n";
    score = compute_score( ncorrect[cl], pcount[cl], ccount[cl] , 
			   "FULLY CORRECT answer", verbose, out );
/*
    score = compute_score( nleft[cl], pcount[cl], ccount[cl] , 
			   "correct LEFT boundary", verbose, out );
    score = compute_score( nright[cl], pcount[cl], ccount[cl] , 
			   "correct RIGHT boundary", verbose, out );
*/


  }
  else if ( !verbose ) 
      for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) {
           score = compute_score( ncorrect[cl], pcount[cl], ccount[cl] , 
			          "FULLY CORRECT answer", verbose, out );
	   cerr << "Cl:" << cl << " " << score << " ";
      }
                                                                                

  //assert(ret_val<=1.0);
  if (ret_val>1.0) ret_val=1.0;
  return ret_val;
}
コード例 #9
0
Float evaluate_sequences(vector<vector<int> > &goldS,vector<vector<int> > &predicted,vector<string> &LIS ,int num_labels,vector<verbose_res> &VR){
  int numtag,numctag,numbtag;
  numtag=numctag=numbtag=0;
  int num_class =  ( num_labels / 2 ) + 1;
  vector<int> ccount(num_class,0),pcount(num_class,0),ncorrect(num_class,0),
    nleft(num_class,0),nright(num_class,0),
    nbcorrect(num_class,0),nbleft(num_class,0),nbright(num_class,0);
  int match,bmatch;
  match=bmatch=0;
  int num_seq = goldS.size();

  for (int i = 0; i < num_seq ; ++i){                                 // For each sequence
    unsigned int N = goldS[i].size();
    if ( N != predicted[i].size() ) {
      cerr << "Unmatching length of labels for sentence" << i << "\n"; abort();
    }
    for ( unsigned int n = 0 ; n < N ; ++n, ++numtag )   {
      int clabel = goldS[i][n];
      int cclass = class_type( clabel );
      int cbraket = braket_type( n, goldS[i] );
      if ( cbraket == SBrac || cbraket == BBrac ) {
	ccount[cclass]++;
      }

      int plabel = predicted[i][n];
      int pclass = class_type( plabel );
      int pbraket = braket_type( n, predicted[i] );
      if ( pbraket == SBrac || pbraket == BBrac ) {
	pcount[pclass]++;
      }
      
      if ( cbraket == pbraket ) numbtag++;
      if ( clabel == plabel && cbraket == pbraket ) numctag++;
      if ( pbraket == SBrac  &&  cbraket == SBrac ) {
	nbcorrect[pclass]++; nbleft[pclass]++; nbright[pclass]++;
	if( pclass == cclass ) { 
	  ncorrect[pclass]++; nleft[pclass]++; nright[pclass]++; 
	}
      }
      else if ( pbraket == SBrac  &&  cbraket == EBrac ) { 
	nbright[pclass]++;
	if( pclass == cclass ) { nright[pclass]++; }
      }
      else if ( pbraket == SBrac  &&  cbraket == BBrac ) { 
	nbleft[pclass]++;
	if( pclass == cclass ) { nleft[pclass]++; }
      }
      else if ( pbraket == BBrac  &&  cbraket == SBrac ) { 
	nbleft[pclass]++;
	if( pclass == cclass ) { nleft[pclass]++; }
      }
      else if ( pbraket == BBrac  &&  cbraket == BBrac ) { 
	nbleft[pclass]++;   bmatch=1;
	if( pclass == cclass ) { nleft[pclass]++; match=1;}
      }
      if ( pbraket != cbraket || pbraket == none )  bmatch = 0;
      if ( cclass != pclass || !bmatch )            match = 0;
      
      if ( pbraket == EBrac && cbraket == SBrac )  {
	nbright[pclass]++;
	if( pclass == cclass ) { nright[pclass]++; }
      }
      if ( pbraket == EBrac && cbraket == EBrac ) {
	if( bmatch )  nbcorrect[pclass]++;
	nbright[pclass]++;
	if( pclass == cclass ) {
	  if ( match && ncorrect[pclass] <= pcount[pclass]) 
	    ncorrect[pclass]++;
	  nright[pclass]++;	
	}
      }
    }
  }

  Float score;
  int numans = getsum(pcount), numref = getsum(ccount);
  verbose_res vr("ALL",int(numref),int(numans));
  if ( !numref ) cerr << "\n\nNo names in reference!\n";
  if ( !numans ) cerr << "\n\nNo names in answers!\n";
  Float ret_val = compute_score(getsum(ncorrect),numans,numref,"FULLY CORRECT answer",vr);
  VR.push_back(vr);

  if (num_class > 2)
    for( unsigned int cl = 1 ; cl < pcount.size() ; ++cl ) {
      string cl_str = LIS[reverse_class_type(cl)];
      verbose_res vr_cl(string(cl_str,2,int(cl_str.size()-2)),ccount[cl],pcount[cl]);
      score = compute_score(ncorrect[cl],pcount[cl],ccount[cl],"FULLY CORRECT answer",vr_cl);
      VR.push_back(vr_cl);
    }
  if (ret_val>1.0) ret_val=1.0;
  return ret_val;
}
コード例 #10
0
 int operator()(lua_State* L) const
 {
     return compute_score(L, Signature(), Policies());
 }
コード例 #11
0
/* manip()-27 statements */
void 
manip(char str[],char query[],
	  int count_l,ranker_t ranked_lines[])
{  
	int debug[MAX_QLEN][MAX_QLEN],i=0,j=0,bytes=0;
	double max_count=0.0,score=0.0,count_same=0.0;
	char changed_q[STR_SIZE];
	bytes=strlen(str);
	
	strcpy(changed_q,"");
	compute_changed_query(query,changed_q);
	initialize_debug(debug,changed_q);
	
	for(i=0;str[i]!='\0';i++)
	{
		/* So that no new lines are printed when the line is empty */
		if(i==0&&str[i]!='\0') 
		{
			printf("\n");
		}
		
		printf("%c",str[i]);
		
		for(j=0;query[j]!='\0';j++)
		{
			/* Checking each str and query combination */
			count_same=stage2_score(i,j,str,query); 
			
			/* Highest score for each line determined */
			if(max_count<count_same)
			{
				max_count=count_same;
			}
			
			/* Computing the debugging array for S4 */
			compute_debug(i,j,str,changed_q,debug);
		}		
	}
	
	/* Printing only non-empty lines */
	if(bytes!=0) 
	{
		printf("\nS1: line %5d, bytes =%3d\n",count_l,bytes);
		printf("S2: line %5d, score =%7.3f",count_l,max_count);
		printf("\n");
		
		#if(DEBUG==1) /*Only printing debugger when debug is 1*/
		{
			print_debug(debug,changed_q);
		}
		#endif
		
		/* Computing S4 score */
		score=compute_score(debug,bytes,changed_q);
		printf("S4: line %5d, score =%7.3f\n",count_l,score);
		
		/* Ranking the line and storing it if required */
		rank_lines(ranked_lines,str,score,count_l);
		printf("---");
	}
	return;
}