/************************************************************** [The MARVIN project - Modest-encoding AlgoRithm with Vocal IdentificatioN] Copyright (C) 2002 LAGACHERIE Matthieu This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Author: LAGACHERIE Matthieu Paper mail : 7 rue Delescluzes 94280 LE KREMLIN BICETRE, FRANCE E-mail : lagach_m@epita.fr ***************************************************************/ #include #include #include #include "/usr/lib/ocaml/caml/mlvalues.h" #include "/usr/lib/ocaml/caml/callback.h" #include "/usr/lib/ocaml/caml/memory.h" #include "/usr/lib/ocaml/caml/alloc.h" /************************************************************** Version actuelle : clefs à 12 bits *************************************************************** ->regognition : fonction de reconnaissance d'empreinte, 2 paramètres : l'empreinte et le nom d'utilisateur. Renvoie la clef. ->tdnn : fonction d'apprentissage de l'empreinte, 3 paramètres : l'empreinte, clef, nom utilisateur. ***************************************************************/ double *recognition (double *emp, char *s) { value temp, t, tcle; double *res; int i; res = (double *) malloc (sizeof (double) * 12); t = alloc (24, 0); tcle = alloc (24, Double_array_tag); for (i = 0; i < 12; i++) Store_double_field (tcle, i, 0); temp = alloc (24, Double_array_tag); for (i = 0; i < 12; i++) Store_double_field (temp, i, emp[i]); t = callback3 (*caml_named_value ("test"), temp, tcle, copy_string (s)); for (i = 0; i < 12; i++) res[i] = Double_field (t, i); return res; } int tdnn (double *emp, double *cle, char *s, double erreur) { value temp, tcle; int i; tcle = alloc (26, Double_array_tag); for (i = 0; i < 12; i++) Store_double_field (tcle, i, cle[i]); Store_double_field (tcle, 12, erreur); temp = alloc (24, Double_array_tag); for (i = 0; i < 12; i++) Store_double_field (temp, i, emp[i]); return callback3 (*caml_named_value ("apprentissage"), temp, tcle, copy_string (s)); } /************************************************************** Fonction de préselection des empreintes vocales *************************************************************** -> renvoie l'empreinte ***************************************************************/ int verif_cle(double *cle, double *test) { int i = 0; int bool = 1; while ((i < 12) && bool) { bool = (cle[i]==test[i]); i++; } return bool; } int neural (double **emp, double *cle, char *s, double erreur) { char temp[2]; int i = 0; int j = 0; int compteur = 0; int courant = 0; int **selection; int maxnb = 0; int maxi = 0; int tempmaxnb = 0; double *efinal; char *t; double *res; efinal = calloc(sizeof(double),12); selection = (int**)malloc(sizeof(int*)*10); for (i=0;i<10;i++) selection[i] = calloc (sizeof(int),10); i = 0; /*temp = (char*)malloc(sizeof(char)*2); while (s[i] != '\0') { temp[i] = s[i]; i++; } temp[i] = '0'; temp[i+1] = '\0'; */ temp[0] = '0'; temp[1] = '\0'; tdnn(emp[0],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) { res = recognition(emp[j],temp); if ((j != 0) && (verif_cle(cle,res))) selection[0][compteur++] = j+1; } tdnn(emp[1],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 1) && (verif_cle(cle,recognition(emp[j],temp)))) selection[1][compteur++] = j+1; tdnn(emp[2],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 2) && (verif_cle(cle,recognition(emp[j],temp)))) selection[2][compteur++] = j+1; tdnn(emp[3],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 3) && (verif_cle(cle,recognition(emp[j],temp)))) selection[3][compteur++] = j+1; tdnn(emp[4],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 4) && (verif_cle(cle,recognition(emp[j],temp)))) selection[4][compteur++] = j+1; tdnn(emp[5],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 5) && (verif_cle(cle,recognition(emp[j],temp)))) selection[5][compteur++] = j+1; tdnn(emp[6],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 6) && (verif_cle(cle,recognition(emp[j],temp)))) selection[6][compteur++] = j+1; tdnn(emp[7],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 7) && (verif_cle(cle,recognition(emp[j],temp)))) selection[7][compteur++] = j+1; tdnn(emp[8],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 8) && (verif_cle(cle,recognition(emp[j],temp)))) selection[8][compteur++] = j+1; tdnn(emp[9],cle,temp,erreur); compteur = 0; for (j = 0; j < 10; j++) if ((j != 9) && (verif_cle(cle,recognition(emp[j],temp)))) selection[9][compteur++] = j+1; for (i = 0; i < 10; i++) { tempmaxnb = 0; while ((selection[i][tempmaxnb] != 0) && (tempmaxnb < 10)) tempmaxnb++; if (tempmaxnb > maxnb) { maxi = i; maxnb = tempmaxnb; } } i = 0; while ((selection[maxi][i] != 0) && (i < 9)) { j = 0; while (j < 12) { efinal[j] += emp[selection[maxi][i]-1][j]; j++; } i++; } for (i=0; i < 10; i++) printf("sel = %d",selection[maxi][i]); for (i=0; i < 12; i++) efinal[i] += emp[maxi][i]; for (i = 0; i < 12; i++) efinal[i] /= maxnb+1; tdnn(efinal,cle,s,erreur); return 0; }