int parameter_server(int argc, char *argv[]) { std::vector<std::vector<double> > training; // TODO: can be optimized, we can count the number of feats and allocate accordingly std::vector<std::vector<double> > validation; // TODO: can be optimized, we can count the number of feats and allocate accordingly std::unordered_set<double> label_set; std::unordered_map<double, std::vector<double> > model; char *training_file = argv[1]; assert(strlen(argv[2]) == 1); char delimiter = argv[2][0]; // read training data std::cout << "Reading training data ... "; read_training_data(training_file, delimiter, training, validation, label_set); std::cout << "[Done]" << std::endl; int data_passes = std::stoi(std::string(argv[6]));; size_t batch_size = training.size(); if (argc == 8) batch_size = std::stoul(std::string(argv[7])); std::cout << std::endl << "***Info***" << std::endl << "Training Data File: " << training_file << std::endl << "Learning Rate: " << learning_rate << std::endl << "Regularization Parameter: " << reg_param << std::endl << "Data Passes: " << data_passes << std::endl << "Batch Size: " << batch_size << std::endl << "Num Labels: " << label_set.size() << std::endl << "Training Set Size: " << training.size() << std::endl << "Validation Set Size: " << validation.size() << std::endl << "**********" << std::endl; // logistic regression logistic_regression(training, label_set, model, learning_rate, reg_param, batch_size, data_passes); // print the f-score(s) const std::unordered_map<double, double> fsc = fscore(validation, label_set, model); std::cout << std::endl << std::endl; std::cout << "F-Score(s):" << std::endl; std::cout << "Label\tScore" << std::endl; for (std::unordered_map<double, double>::const_iterator it = fsc.begin(); it != fsc.end(); ++it) { std::cout << it->first << "\t" << it->second << std::endl; } return 0; }
void ConfusionMatrix::print_summary() { // overall counts and summary cout.precision(4); cout << "== Summary ==" << endl; cout << setw(23) <<"Correctly classified:" << setw(12) << right << correct << setw(10) << right << accuracy() * 100 << "%" << endl; cout << setw(23) << "Incorrectly classified:" << setw(12) << right << incorrect << setw(10) << right << error() * 100 << "%" << endl; cout << setw(23) << "Total classifications:" << setw(12) << right << correct + incorrect << endl << endl; // determine the width of the left (category name) column int max_name_length = 0; for(int category = 1; category <= data_set->categories_size(); category++) if(data_set->category_feature()->names[category].length() > max_name_length) max_name_length = data_set->category_feature()->names[category].length(); if(average_row_name.length() > max_name_length) max_name_length = average_row_name.length(); max_name_length += 1; // detailed category information cout << "== Category Performance ==" << endl; cout << setw(max_name_length) << ""; cout << setw(9) << right << "True +"; cout << setw(9) << right << "False +"; cout << setw(9) << right << "True -"; cout << setw(9) << right << "False -"; cout << setw(9) << right << "Precis."; cout << setw(9) << right << "Recall"; cout << setw(9) << right << "F-score" << endl; for(int category = 1; category <= data_set->categories_size(); category++) { cout << setw(max_name_length) << data_set->category_feature()->names[category]; cout << setw(9) << tp(category); cout << setw(9) << fp(category); cout << setw(9) << tn(category); cout << setw(9) << fn(category); cout << setw(8) << precision(category) * 100 << "%"; cout << setw(8) << recall(category) * 100 << "%"; cout << setw(8) << fscore(category) * 100 << "%" << endl; } cout << setw(max_name_length) << average_row_name; cout << setw(9) << avg_tp(); cout << setw(9) << avg_fp(); cout << setw(9) << avg_tn(); cout << setw(9) << avg_fn(); cout << setw(8) << avg_precision() * 100 << "%"; cout << setw(8) << avg_recall() * 100 << "%"; cout << setw(8) << avg_fscore() * 100 << "%" << endl; }
inline void load_scores(unsigned &contest_handicap) { // replay_file int index = replay_file.find_last_of("."); std::string score_file = replay_file.substr(0, index) + ".txt"; if (verbose) { std::cout << "# replay file: " << replay_file << "\n"; std::cout << "# score file: " << score_file << "\n"; } std::ifstream fscore(score_file.c_str()); double tmp; fscore >> tmp; official_index = (fixed)tmp; load_score_file(fscore, official_score_classic); load_score_file(fscore, official_score_sprint); load_score_file(fscore, official_score_fai); load_score_file(fscore, official_score_plus); fscore.close(); contest_handicap = (unsigned)official_index; if (contest_handicap==0) { // in case file load failed contest_handicap = 100; } }
void deplacements(char terrain[20][38], coordonees *PacMan, coordonees *fantomeA, coordonees *fantomeB, coordonees *fantomeC, coordonees *fantomeD) { char entree, pointA = ' ', pointB = ' ', pointC = ' ', pointD = ' '; int directionA = 0, directionB = 0, directionC = 0, directionD = 0; int score=0, bonus = 0, frame = 0; int c; int vies; for(vies = 3 ; vies > 0 ; vies--) { //Le PacMan se déplace à l'aide des touches z,q,s et d. Le jeu peut être quitté avec Esc affichage(terrain, score, bonus, frame, vies); entree = getch(); //Cette commande permet au jeu de ne pas démarer tout de suite, mais d'attendre que le joueur soit pret do { /*On récupère les entrées au clavier grace à la fonction GetKeyState qui est dans windows.h Les tests empèchent le joueur de diriger PacMan vers un mur (cela ralentirai le jeu)*/ if(GetKeyState(0x5A) < 0 && (terrain[PacMan->i - 1][PacMan->j] == ' ' || terrain[PacMan->i - 1][PacMan->j] == '.' || terrain[PacMan->i - 1][PacMan->j] == 'M')) { entree = 'z'; } if(GetKeyState(0x51) < 0 && (terrain[PacMan->i][PacMan->j - 1] == ' ' || terrain[PacMan->i][PacMan->j - 1] == '.' || terrain[PacMan->i][PacMan->j - 1] == 'M')) { entree = 'q'; } if(GetKeyState(0x53) < 0 && (terrain[PacMan->i + 1][PacMan->j] == ' ' || terrain[PacMan->i + 1][PacMan->j] == '.' || terrain[PacMan->i + 1][PacMan->j] == 'M')) { entree = 's'; } if(GetKeyState(0x44) < 0 && (terrain[PacMan->i][PacMan->j + 1] == ' ' || terrain[PacMan->i][PacMan->j + 1] == '.' || terrain[PacMan->i][PacMan->j + 1] == 'M')) { entree = 'd'; } if(GetKeyState(VK_ESCAPE) < 0) { entree = 'Q'; } //En fonction de la touche appuiée on déplace le PacMan switch(entree) { case 's': if(terrain[PacMan->i + 1][PacMan->j] == '.') //Si PacMan se dirige vers un point on supprime le point et on incrémente le score { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i + 1; terrain[PacMan->i][PacMan->j] = 'C'; score = score + 1; } else if(terrain[PacMan->i + 1][PacMan->j] == ' ') //Si il n'y a rien on déplace juste PacMan { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i + 1; terrain[PacMan->i][PacMan->j] = 'C'; } else if(terrain[PacMan->i + 1][PacMan->j] == 'M' && !bonus) //Si c'est un fantôme et que le bonus n'est pas activé c'est perdu { entree = 'Q'; } else if(terrain[PacMan->i + 1][PacMan->j] == 'M' && bonus) //Si c'est un fantôme et que le bonus est activé, PacMan mange le fantôme et gagne 10 points { terrain[PacMan->i][PacMan->j] = ' '; //La réaparition de PacMan est gérée plus loin car il y a plusieurs fantômes et qu'il faut les gérer au cas par cas PacMan->i = PacMan->i + 1; score += 10; } else if(terrain[PacMan->i + 1][PacMan->j] == point) //Si la case est un bonus on active le bonus { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i + 1; terrain[PacMan->i][PacMan->j] = 'C'; bonus = 1; } break; case 'q': if(terrain[PacMan->i][PacMan->j - 1]=='.') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j - 1; terrain[PacMan->i][PacMan->j] = 'C'; score = score + 1; } else if(terrain[PacMan->i][PacMan->j - 1]==' ') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j - 1; terrain[PacMan->i][PacMan->j] = 'C'; } else if(terrain[PacMan->i][PacMan->j - 1]=='M' && !bonus) { entree = 'Q'; } else if(terrain[PacMan->i][PacMan->j - 1]=='M' && bonus) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j - 1; score += 10; } else if(terrain[PacMan->i][PacMan->j - 1]==point) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j - 1; terrain[PacMan->i][PacMan->j] = 'C'; bonus = 1; } break; case 'z': if(terrain[PacMan->i - 1][PacMan->j] == '.') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i - 1; terrain[PacMan->i][PacMan->j] = 'C'; score = score + 1; } else if(terrain[PacMan->i - 1][PacMan->j] == ' ') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i - 1; terrain[PacMan->i][PacMan->j] = 'C'; } else if(terrain[PacMan->i - 1][PacMan->j] == 'M' && !bonus) { entree = 'Q'; } else if(terrain[PacMan->i - 1][PacMan->j] == 'M' && bonus) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i - 1; score += 10; } else if(terrain[PacMan->i - 1][PacMan->j] == point) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->i = PacMan->i - 1; terrain[PacMan->i][PacMan->j] = 'C'; bonus = 1; } break; case 'd': if(terrain[PacMan->i][PacMan->j + 1]=='.') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j + 1; terrain[PacMan->i][PacMan->j] = 'C'; score = score + 1; } else if(terrain[PacMan->i][PacMan->j + 1]==' ') { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j + 1; terrain[PacMan->i][PacMan->j] = 'C'; } else if(terrain[PacMan->i][PacMan->j + 1]=='M' && !bonus) { entree = 'Q'; } else if(terrain[PacMan->i][PacMan->j + 1]=='M' && bonus) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j + 1; score += 10; } else if(terrain[PacMan->i][PacMan->j + 1]==point) { terrain[PacMan->i][PacMan->j] = ' '; PacMan->j = PacMan->j + 1; terrain[PacMan->i][PacMan->j] = 'C'; bonus = 1; } break; } /*On gère les fantômes au cas par cas, il n'y a pas de condition bonus car le seul moyen pour que les coordonées de PacMan soient identiques à celle d'un fantôme est que le bonus soit activé*/ if(PacMan->i == fantomeA->i && PacMan->j == fantomeA->j) { terrain[fantomeA->i][fantomeA->j] = 'C'; fantomeA->i = 13; fantomeA->j = 15; pointA = ' '; terrain[fantomeA->i][fantomeA->j] = 'M'; } else if(PacMan->i == fantomeB->i && PacMan->j == fantomeB->j) { terrain[fantomeB->i][fantomeB->j] = 'C'; fantomeB->i = 13; fantomeB->j = 17; pointB = ' '; terrain[fantomeB->i][fantomeB->j] = 'M'; } else if(PacMan->i == fantomeC->i && PacMan->j == fantomeC->j) { terrain[fantomeC->i][fantomeC->j] = 'C'; fantomeC->i = 13; fantomeC->j = 19; pointC = ' '; terrain[fantomeC->i][fantomeC->j] = 'M'; } else if(PacMan->i == fantomeD->i && PacMan->j == fantomeD->j) { terrain[fantomeD->i][fantomeD->j] = 'C'; fantomeD->i = 13; fantomeD->j = 21; pointD = ' '; terrain[fantomeD->i][fantomeD->j] = 'M'; } //Deplacement des fantomes directionA = ia(*PacMan, *fantomeA, terrain, directionA); directionB = ia(*PacMan, *fantomeB, terrain, directionB); directionC = ia(*PacMan, *fantomeC, terrain, directionC); directionD = ia(*PacMan, *fantomeD, terrain, directionD); pointA = deplacementFantome(directionA, fantomeA, pointA, terrain, &entree, bonus); pointB = deplacementFantome(directionB, fantomeB, pointB, terrain, &entree, bonus); pointC = deplacementFantome(directionC, fantomeC, pointC, terrain, &entree, bonus); pointD = deplacementFantome(directionD, fantomeD, pointD, terrain, &entree, bonus); //On affiche la nouvelle frame ainsi générée affichage(terrain, score, bonus, frame, vies); //compteur de frame if(bonus) { frame++; } //On réinitialise le bonus après 50 frames if(frame>50) { bonus=0; frame=0; } }while(entree != 'Q'); if(vies-1>0) { system("CLS"); do { textcolor(12); printf("\n\n\n OUILLE !\n\n\n\n"); textcolor(15); printf("Tu as perdu une vie, pour continuer appuye sur la touche espace"); if(vies>1) { printf("\nIl te reste %d vies", vies-1); } else { printf("\nIl te reste %d vie", vies-1); } c = getch(); system("CLS"); }while (c != ' '); //On valide par espace terrain[PacMan->i][PacMan->j] = ' '; terrain[1][1] = 'C'; PacMan->i = 1; PacMan->j = 1; } } //On vide le buffer clavier car la fonction GetKeyState garde toutes les entrées en mémoire et les ressorts au getch suivant system("CLS"); do { textcolor(12); printf("\n\n\n GAME OVER\n\n\n\n"); textcolor(15); printf("Pour sauvegarder et afficher votre score appuyer sur la touche espace"); c = getch(); system("CLS"); } while (c != ' '); //On valide par espace fscore(score); }