mconfusion_matrix.c

00001 /*
00002 *    Copyright (c) 2007. The BATI team. All right reserved.
00003 *
00004 *    This file is part of BATI library.
00005 *
00006 *    BATI library is free software: you can redistribute it and/or modify
00007 *    it under the terms of the GNU General Public License as published by
00008 *    the Free Software Foundation, either version 3 of the License, or
00009 *    (at your option) any later version.
00010 *
00011 *    BATI library  is distributed in the hope that it will be useful,
00012 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *    GNU General Public License for more details.
00015 *
00016 *    You should have received a copy of the GNU General Public License
00017 *    along with BATI library.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 #include <stdio.h>
00020 #include "image.h"
00021 #include "proto2D.h"
00022 #include "classifier.h"
00023 #include "confusion_matrix.h"
00024 
00025 main(int argc, char *argv[])
00026 {
00027   int i,j,k,r;
00028   int x,y,z;
00029   int somme;
00030   float taux;
00031   char question[500];
00032 
00033   param par0, *ptp;
00034 
00035   //char fich[20];
00036   confusion_matrix_t *desc;
00037   int **matrice;
00038 
00039 
00040  
00041 
00042   /* ************************ LECTURE PARAMETRES************************* */
00043 
00044   /* debut: OBLIGATOIRE pour compatibilite avec les 3 modes de lecture de param */
00045   param_debut(argc, argv, &par0);
00046   ptp = &par0;      /* regle : ptp pointe sur la structure du parametre suivant */
00047 
00048   desc=(confusion_matrix_t *)malloc(sizeof(confusion_matrix_t));
00049 
00050   ptp=confusion_matrix_lect(desc, ptp, " ");
00051 
00052 
00053 
00054   /* fin: sauvegarde des parametres utilises en mode MANUEL ou FICHIER */
00055   param_fin(argc, argv, &par0);
00056 
00057 
00058 
00059   /* ***************************INITIALISATION************************* */
00060 
00061 
00062   confusion_matrix_init(desc);
00063 
00064   printf("Init OK\n");
00065 
00066   matrice=(int **)malloc((desc->nb_region_etudiee+1)*sizeof(int *));
00067   for(i=0;i<(desc->nb_region_etudiee+1);i++)
00068     matrice[i]=(int *)malloc((desc->nb_region_etudiee+1)*sizeof(int ));
00069 
00070 
00071  for(i=0;i<(desc->nb_region_etudiee+1);i++)
00072      for(j=0;j<(desc->nb_region_etudiee+1);j++)
00073        matrice[i][j]=0;
00074        
00075   /* ***************************************CALCUL**************************** */
00076 
00077 
00078   confusion_matrix_calc(desc, matrice);
00079 
00080   for(j=0;j<(desc->nb_region_etudiee+1);j++)
00081     printf("R%d\t",j);
00082 
00083   printf("\n");
00084 
00085  for(i=1;i<(desc->nb_region_etudiee+1);i++)
00086    {
00087      for(j=0;j<(desc->nb_region_etudiee+1);j++)
00088        printf("%d\t",matrice[i][j]);
00089 
00090      printf("R%d\n",i);
00091    }
00092 
00093   somme=0;
00094   for(i=0;i<(desc->nb_region_etudiee+1);i++)
00095      for(j=0;j<(desc->nb_region_etudiee+1);j++)
00096        somme=somme+matrice[i][j];
00097   
00098  taux=0.0;
00099  for(i=1;i<(desc->nb_region_etudiee+1);i++)
00100    taux=taux+((float)matrice[i][i])/somme;
00101 
00102   printf("Taux de bonne classification: %3.2f %\n",taux*100);
00103 
00104  taux=0.0;
00105  for(i=1;i<(desc->nb_region_etudiee+1);i++)
00106    taux=taux+((float)matrice[i][0])/somme;
00107 
00108 
00109   printf("Taux de rejet: %3.2f %\n",taux*100.0);
00110 
00111 
00112   for(i=1;i<desc->nb_region_etudiee+1;i++)
00113     {
00114       somme=0;
00115       for(j=0;j<desc->nb_region_etudiee+1;j++)
00116         somme=somme+matrice[i][j];
00117 
00118       printf("Rappel de la classe R%d: %3.2f %\n",i,100*((float)matrice[i][i]/somme));
00119 
00120     }
00121 
00122   for(i=1;i<desc->nb_region_etudiee+1;i++)
00123     {
00124       somme=0;
00125       for(j=1;j<desc->nb_region_etudiee+1;j++)
00126         somme=somme+matrice[j][i];
00127 
00128       printf("Precision de la classe R%d: %3.2f %\n",i,100*((float)matrice[i][i]/somme));
00129 
00130     }
00131 
00132 
00133   //Fermeture
00134   confusion_matrix_ferm(desc);
00135 
00136   for(i=0;i<(desc->nb_region_etudiee+1);i++)
00137     free(matrice[i]);
00138   free(matrice);
00139 
00140   free(desc);
00141   
00142   //free(desc);
00143 }

Generated on Tue Apr 22 13:31:04 2008 for ima2D by  doxygen 1.5.3