/* Speaker_Vote implements a 3-way ARTMAP voting system using Lars Linden's ART Gallery. It takes as input three trained networks and a pattern file and outputs the consensus on the identity of each speaker. (Networks should be fuzzy ARTMAPS with ART-B type set to NONE) Consensus is reached if two of the networks give the same identity to the speaker, otherwise the speaker is reported as unknown. */ #include #include "Art_Gal.h" /* Loads the network given in filename and returns it. Exits on error. */ netTYPE LoadNetwork(char* filename) { netTYPE net; int chopext = strlen(filename) - 4; /* Prepare to chop off extension */ int status; filename[chopext] = '\0'; status = LoadNet(&net,filename); if (status) { printf("Error loading %s.net!\n",filename); exit(1); } return net; } /* Loads the pattern given in filename. Exits on error. */ setTYPE LoadPattern(char* filename) { setTYPE pat; int status; int chopext = strlen(filename) - 4; /* Prepare to chop off extension */ filename[chopext] = '\0'; status = LoadSet(&pat,filename); if (status) { printf("Error loading %s.pat!\n",filename); exit(1); } return pat; } /* do_vote actually does the voting evaluation and prints out the results */ void do_vote(netTYPE net1, netTYPE net2, netTYPE net3, setTYPE pat) { int i=0; int j=0; int speaker_id = -1; int map1, map2, map3; /* temporary values for holding the map values*/ int num_speakers = net1.map.artB.nodes_used; int num_pats = pat.num_patterns; for (i = 0; i < num_pats; ++i) { speaker_id = -1; /* Initially unknown speaker */ ShowPat(&net1,&pat,i); ShowPat(&net2,&pat,i); ShowPat(&net3,&pat,i); for (j=0; j < num_speakers; ++j) { map1 = *(net1.map.map+j); map2 = *(net2.map.map+j); map3 = *(net3.map.map+j); /* If two of the networks agre on speaker, so be it */ if (map1 && map2 || map2 && map3 || map3 && map1) { speaker_id = j; } } printf("Pattern %d spoken by: ",i); if (speaker_id == -1) { printf("Unknown.\n"); } else { printf("Speaker %d.\n",speaker_id); } } } void usage() { printf("Usage: Speaker_Vote net1.net net2.net net3.net pattern.pat\n"); exit(1); } int main(int argc, char** argv) { netTYPE net1, net2, net3; setTYPE pat; if (argc != 5) { usage(); } net1 = LoadNetwork(argv[1]); net2 = LoadNetwork(argv[2]); net3 = LoadNetwork(argv[3]); pat = LoadPattern(argv[4]); do_vote(net1,net2,net3,pat); return 0; }