/* ====================================================================== David W. Aha printing.c: Source for supporting the printing of results Topic: IB1, IB2, IB3, and now IB4 July, 1990 ====================================================================== */ #include "datastructures.h" /* ====================================================================== Prints unchanging info to outputfile. ====================================================================== */ void print_general_info(fp) FILE *fp; /* (Outputfile) */ { fprintf(fp,"Trainingfile: %s\n",trainingfile); fprintf(fp,"Testingfile: %s\n",testingfile); fprintf(fp,"Signif_accept: %3.2f percent\n",signif_accept_level); fprintf(fp,"Signif_drop: %3.2f percent\n",signif_drop_level); fprintf(fp,"Value of k: %d\n",k); fprintf(fp,"Algorithm: %s\n",algorithm_string); if (ib4) if (weight_method == SIMPLE) fprintf(fp,"Weight updating method: Simple\n"); else fprintf(fp,"Weight updating method: Probabilities\n"); fprintf(fp,"Normalization type: %s\n",normalization_string); fprintf(fp,"Missing type: %s\n",missing_string); } /* ====================================================================== On printing the results of the experiments. ====================================================================== */ void print_classification_results(current_output,testlast_flag) FILE *current_output; /*==== Either the outputfile or stdout ====*/ register int testlast_flag; { /*==== Subfunctions ====*/ extern void classify_test_set(), /*==== Testing ====*/ setup_for_testing(); /*==== Testing ====*/ void calculate_percentages(), print_heading(), print_test_accuracy(), print_training_accuracy(), print_recent_training_accuracy(), print_storage_requirements(), print_number_dropped(), print_attribute_weights(), print_predictors(); /*==== Local Variables ====*/ register int num_real_concepts; /*==== 2. Get ready to print. ====*/ if (ib4 && best_concept_only) num_real_concepts = 1; else num_real_concepts = number_of_predictees; /*==== 1. Classify now if needed ====*/ if (((instance_number % testrate) == 0) || testlast_flag) { setup_for_testing(); classify_test_set(); calculate_percentages(num_real_concepts); } /*==== 2. Print Testing Information to File ====*/ if (((instance_number % testrate) == 0) || testlast_flag) { fprintf(current_output, "%s Testing Summary after %d Training Instances:\n", algorithm_string,instance_number); print_heading(current_output,num_real_concepts); print_test_accuracy(current_output,num_real_concepts); print_training_accuracy(current_output,num_real_concepts); print_recent_training_accuracy(current_output,num_real_concepts); print_storage_requirements(current_output,num_real_concepts); print_number_dropped(current_output,num_real_concepts); if (ib4 && printweights) print_attribute_weights(current_output); } /*==== 3. Print Reporting Information to Screen ====*/ if (((instance_number % reportrate) == 0) || testlast_flag) { printf("\n%s Training Summary after %d Training Instances:\n", algorithm_string,instance_number); print_heading(stdout,num_real_concepts); if (((instance_number % testrate) == 0) || testlast_flag) print_test_accuracy(stdout,num_real_concepts); print_training_accuracy(stdout,num_real_concepts); print_recent_training_accuracy(stdout,num_real_concepts); print_storage_requirements(stdout,num_real_concepts); print_number_dropped(stdout,num_real_concepts); if (ib4 && printweights) print_attribute_weights(stdout); print_predictors(stdout,num_real_concepts); } } /* ====================================================================== Calculates the percentages of the outcomes (correct, incorrect) ====================================================================== */ void calculate_percentages(num_real_concepts) register int num_real_concepts; { /*==== Local Variables ====*/ register int c; /*==== A predictee ====*/ /*==== 1. Calculate percent correct predictions per predictee ====*/ for(c=0; c0) { if (total == 0) fprintf(current_output,"%5.1f",0.0); else fprintf(current_output,"%5.1f", 100.0 * (float)num_training_correct_in_alg/(float)total); i--; } fprintf(current_output,"\n"); } /* ====================================================================== Prints recent current training accuracy (since last test location). ====================================================================== */ void print_recent_training_accuracy(current_output,num_real_concepts) FILE *current_output; register int num_real_concepts; { register int total,c,i=1, index = (current_output == stdout); /* 0=file, 1=console */ /*==== 1. Heading ====*/ fprintf(current_output," Recently "); /*==== 2. Concept-dependent totals ====*/ if (ib4 && overlap) i=2; else for(c=0; c0) { if (total == 0) fprintf(current_output,"%5.1f",0.0); else fprintf(current_output,"%5.1f", 100.0 * (float)(num_training_correct_in_alg- num_training_correct_in_alg_previous[index])/ (float)total); i--; } fprintf(current_output,"\n"); num_training_correct_in_alg_previous[index] = num_training_correct_in_alg; num_training_incorrect_in_alg_previous[index]=num_training_incorrect_in_alg; } /* ====================================================================== Prints storage requirements. ====================================================================== */ void print_storage_requirements(current_output,num_real_concepts) FILE *current_output; register int num_real_concepts; { register int concept, i, total_saved = 0, total_accepted = 0, data_id; int saved_in_some_class[MAX_NUMBER_OF_INSTANCES+1], accepted_anywhere[MAX_NUMBER_OF_INSTANCES+1]; /*==== 0. Setup ====*/ for(i=0; i0) { fprintf(current_output,"%5d",total_saved); i--; } fprintf(current_output,"\n"); /*==== 3. Print number of accepteds ====*/ if ((instance_number % testrate) != 0) for(concept=0; concept0) { fprintf(current_output,"%5d",total_accepted); i--; } fprintf(current_output,"\n"); } /* ====================================================================== Prints info on the dropped instances. ====================================================================== */ void print_number_dropped(current_output,num_real_concepts) FILE *current_output; register int num_real_concepts; { register int total=0, concept, i=1; fprintf(current_output," Num Dropped "); for(concept=0; concept0) { fprintf(current_output,"%5.1f",(double)total/(double)num_real_concepts); i--; } fprintf(current_output,"\n"); } /* ====================================================================== Prints attribute weights. Output format depends on weighting method. ====================================================================== */ void print_attribute_weights(fp) FILE *fp; { /*==== Local Variables ====*/ register int predictor_a, predictee_a; char weight_method_string[20]; /*==== 1. Setup ====*/ if (weight_method == SIMPLE) strcpy(weight_method_string,"simple"); else strcpy(weight_method_string,"probabilities"); fprintf(fp,"\nNormalized Attribute Weights for %s: (%s method, %d predictees)\n", algorithm_string,weight_method_string,number_of_predictees); /*==== 2. Check for option and print weights accordingly. ====*/ if (weight_method == SIMPLE) { for(predictee_a=0; predictee_a