void adaboost(struct list_haar *larray, int nbex, int T) { //printf("******lancement d'adaboost****\n\n"); float alpha = 1; long Et = 0; float *w = malloc(nbex * sizeof(float)); *w = (1/(float)nbex); int i, j; struct stump *h; for (int t = 1; t <= T; t++) { //struct list_haar *haar_tmp = larray; //float *tmp = w; h = best_stump(larray, w, nbex, 162336); for (i = 0; i < nbex; i++) { Et += w[i]; } if (Et == 0 && t == 1) write_data(h, 1); else { alpha = 0.5 * log ((1 - Et) / Et); for(j = 0; j < nbex; j++ ) w[j] = (w[j] / 2) * ((1 / Et) + (1 / (1 - Et))); } write_data(h, alpha); } }
void adaboost(t_couple_image *img_set, int T){ int count = 0; float error = 0; FILE *file = fopen("strong_classifier", "w"); for(int t = 0; t < T; t++){ t_dec_stump *ht = best_stump(img_set); t_feature *f = malloc(sizeof(t_feature)); f->i=ht->i; f->j=ht->j, f->w=ht->w; f->h=ht->h; f->type=ht->type; for(int i = 0; i<PICT_WITH_FACE+PICT_WITH_NO_FACE; i++) { feature_scaling(img_set[i].img, f); if(f->param<ht->threshold-ht->margin) { error+=img_set[i].weight; count++; } } count = 0; free(f); if(error == 0 && t==0) { fprintf(file, "%lf %d %d %d %d %d %d %d %d\n", ht->error, ht->threshold, ht->margin, ht->toggle, ht->i, ht->j, ht->w, ht->h, ht->type); free(ht); break; } else { for(int i = 0; i<PICT_WITH_FACE + PICT_WITH_NO_FACE; i++) { img_set[i].weight = (img_set[i].weight/2); if(ht->toggle!=img_set[i].face) img_set[i].weight*=1.0/error; else img_set[i].weight*=1.0/(1-error); } } fprintf(file, "%lf %d %d %d %d %d %d %d %d\n", ht->error, ht->threshold, ht->margin, ht->toggle, ht->i, ht->j, ht->w, ht->h, ht->type); printf("%lf %d %d %d %d %d %d %d %d\n", ht->error, ht->threshold, ht->margin, ht->toggle, ht->i, ht->j, ht->w, ht->h, ht->type); free(ht); } fclose(file); }