Material::~Material() { traceIn(Material::~Material); FreeParameters(); traceOut; }
int main(int argc, char **argv) { Parameters *parameters; ULONG FP = 0; ULONG FN = 0; ULONG TP = 0; ULONG TN = 0; double FPRate; double TPRate; double error; if (argc != 3) { fprintf(stderr, "USAGE: %s <subsfile> <graphfile>\n", argv[0]); exit(1); } parameters = GetParameters(argc, argv); Test(argv[1], argv[2], parameters, &TP, &TN, &FP, &FN); // compute and output stats FPRate = ((double) FP) / ((double) (TN+FP)); TPRate = ((double) TP) / ((double) (FN+TP)); error = ((double) (FP+FN)) / ((double) (TP+TN+FP+FN)); fprintf(stdout, "TP = %lu\nTN = %lu\nFP = %lu\nFN = %lu\n", TP, TN, FP, FN); fprintf(stdout, "(TP+FN) = %lu\n(TN+FP) = %lu\n", (TP+FN), (TN+FP)); fprintf(stdout, "(TP+TN+FP+FN) = %lu\n", (TP+TN+FP+FN)); fprintf(stdout, "(FP/(TN+FP)) = %f\n", FPRate); fprintf(stdout, "(TP/(FN+TP)) = %f\n", TPRate); fprintf(stdout, "Error = %f\n", error); fflush(stdout); FreeParameters(parameters); return 0; }
int main(int argc, char **argv) { struct tms tmsstart, tmsend; clock_t startTime, endTime; static long clktck = 0; time_t iterationStartTime; time_t iterationEndTime; SubList *subList; Substructure *normSub = NULL; Parameters *parameters; FILE *outputFile; ULONG iteration; BOOLEAN done; clktck = sysconf(_SC_CLK_TCK); startTime = times(&tmsstart); printf("GBAD %s\n\n", GBAD_VERSION); parameters = GetParameters(argc, argv); // compress positive graphs with predefined subs, if given if (parameters->numPreSubs > 0) CompressWithPredefinedSubs(parameters); PrintParameters(parameters); if (parameters->iterations > 1) printf("----- Iteration 1 -----\n\n"); iteration = 1; parameters->currentIteration = iteration; done = FALSE; while ((iteration <= parameters->iterations) && (!done)) { iterationStartTime = time(NULL); if (iteration > 1) printf("----- Iteration %lu -----\n\n", iteration); printf("%lu positive graphs: %lu vertices, %lu edges", parameters->numPosEgs, parameters->posGraph->numVertices, parameters->posGraph->numEdges); if (parameters->evalMethod == EVAL_MDL) printf(", %.0f bits\n", parameters->posGraphDL); else printf("\n"); printf("%lu unique labels\n", parameters->labelList->numLabels); printf("\n"); if ((parameters->prob) && (iteration > 1)) { // // If GBAD-P option chosen, after the first iteration, we no longer // care about minsize of maxsize after the first iteration (if the // user specified these parameters), as we are just dealing with // single extensions from the normative - so set it to where we // just look at substructures that are composed of the normative // pattern (SUB_) and the single vertex extension. // parameters->minVertices = 1; parameters->maxVertices = 2; } // // If the user has specified a normative pattern, on the first iteration // need to save the top-N substructures, where N is what the user // specified with the -norm parameter. // ULONG saveNumBestSubs = parameters->numBestSubs; if ((iteration == 1) && (!parameters->noAnomalyDetection) && (parameters->norm > parameters->numBestSubs)) parameters->numBestSubs = parameters->norm; // // -prune is useful to get to the initial normative pattern, but // possibly detremental to discovering anomalies... so, turn off // pruning (in case it was turned on), so that it is not used in // future iterations. // if ((parameters->prob) && (iteration > 1)) { parameters->prune = FALSE; } subList = DiscoverSubs(parameters, iteration); // // Now that we have the best substructure(s), return the user // specified number of best substructures to its original value. // if (iteration == 1) parameters->numBestSubs = saveNumBestSubs; if (subList->head == NULL) { done = TRUE; printf("No substructures found.\n\n"); } else { // // GBAD-MDL // if (parameters->mdl) GBAD_MDL(subList,parameters); // // GBAD-MPS // if (parameters->mps) { GBAD_MPS(subList,parameters); } // // GBAD-P // if (parameters->prob) { normSub = GBAD_P(subList,iteration,parameters); } // write output to stdout if (parameters->outputLevel > 1) { printf("\nBest %lu substructures:\n\n", CountSubs (subList)); PrintSubList(subList, parameters); } else { printf("\nBest substructure: "); if ((CountSubs(subList) > 0) && (subList->head->sub != NULL)) PrintSub(subList->head->sub, parameters); else printf("None."); printf("\n\n"); } // write machine-readable output to file, if given if (parameters->outputToFile) { outputFile = fopen(parameters->outFileName, "a"); if (outputFile == NULL) { printf("WARNING: unable to write to output file %s,", parameters->outFileName); printf("disabling\n"); parameters->outputToFile = FALSE; } WriteGraphToFile(outputFile, subList->head->sub->definition, parameters->labelList, 0, 0, subList->head->sub->definition->numVertices, TRUE); fclose(outputFile); } if (iteration < parameters->iterations) { // Another iteration? if (parameters->evalMethod == EVAL_SETCOVER) { printf("Removing positive examples covered by"); printf(" best substructure.\n\n"); RemovePosEgsCovered(subList->head->sub, parameters); } else { // // For the GBAD-P algorithm, multiple iterations will need // to be performed, and if it is the first iteration // AND the user has specified a different normative // pattern (other than the best one), we need to // use the substructure that was set above. // if ((iteration == 1) && (parameters->prob)) { printf("Compressing graph by best substructure (%lu):\n", parameters->norm); PrintSub(normSub,parameters); printf("\n"); CompressFinalGraphs(normSub, parameters, iteration, FALSE); } else CompressFinalGraphs(subList->head->sub, parameters, iteration, FALSE); } // check for stopping condition // if set-covering, then no more positive examples // if MDL or size, then positive graph contains no edges if (parameters->evalMethod == EVAL_SETCOVER) { if (parameters->numPosEgs == 0) { done = TRUE; printf("Ending iterations - "); printf("all positive examples covered.\n\n"); } } else { if (parameters->posGraph->numEdges == 0) { done = TRUE; printf("Ending iterations - graph fully compressed.\n\n"); } } } if ((iteration == parameters->iterations) && (parameters->compress)) { if (parameters->evalMethod == EVAL_SETCOVER) WriteUpdatedGraphToFile(subList->head->sub, parameters); else WriteCompressedGraphToFile(subList->head->sub, parameters, iteration); } } // // Need to store information regarding initial best substructure, for use // in future GBAD-P calculations // if ((parameters->prob) && (iteration == 1) && (subList->head != NULL)) { parameters->numPreviousInstances = subList->head->sub->numInstances; } if ((parameters->prob) && (iteration > 1) && (subList->head != NULL)) parameters->numPreviousInstances = subList->head->sub->numInstances; FreeSubList(subList); if (parameters->iterations > 1) { iterationEndTime = time(NULL); printf("Elapsed time for iteration %lu = %lu seconds.\n\n", iteration, (iterationEndTime - iterationStartTime)); } iteration++; parameters->currentIteration = iteration; } FreeParameters(parameters); endTime = times(&tmsend); printf("\nGBAD done (elapsed CPU time = %7.2f seconds).\n", (endTime - startTime) / (double) clktck); return 0; }
int main(int argc, char **argv) { Parameters *parameters; ULONG numLabels; Graph *g1; Graph *g2; Graph *g2compressed; InstanceList *instanceList; ULONG numInstances; ULONG subSize, graphSize, compressedSize; double subDL, graphDL, compressedDL; double value; Label label; parameters = GetParameters(argc, argv); g1 = ReadGraph(argv[argc - 2], parameters->labelList, parameters->directed); g2 = ReadGraph(argv[argc - 1], parameters->labelList, parameters->directed); instanceList = FindInstances(g1, g2, parameters); numInstances = CountInstances(instanceList); printf("Found %lu instances.\n\n", numInstances); g2compressed = CompressGraph(g2, instanceList, parameters); // Compute and print compression-based measures subSize = GraphSize(g1); graphSize = GraphSize(g2); compressedSize = GraphSize(g2compressed); value = ((double) graphSize) / (((double) subSize) + ((double) compressedSize)); printf("Size of graph = %lu\n", graphSize); printf("Size of substructure = %lu\n", subSize); printf("Size of compressed graph = %lu\n", compressedSize); printf("Value = %f\n\n", value); // Compute and print MDL based measures numLabels = parameters->labelList->numLabels; subDL = MDL(g1, numLabels, parameters); graphDL = MDL(g2, numLabels, parameters); numLabels++; // add one for new "SUB" vertex label if ((parameters->allowInstanceOverlap) && (InstancesOverlap(instanceList))) numLabels++; // add one for new "OVERLAP" edge label compressedDL = MDL(g2compressed, numLabels, parameters); // add extra bits to describe where external edges connect to instances compressedDL += ExternalEdgeBits(g2compressed, g1, numInstances); value = graphDL / (subDL + compressedDL); printf("DL of graph = %f\n", graphDL); printf("DL of substructure = %f\n", subDL); printf("DL of compressed graph = %f\n", compressedDL); printf("Value = %f\n\n", value); if (parameters->outputToFile) { // first, actually add "SUB" and "OVERLAP" labels label.labelType = STRING_LABEL; label.labelValue.stringLabel = SUB_LABEL_STRING; StoreLabel(& label, parameters->labelList); label.labelValue.stringLabel = OVERLAP_LABEL_STRING; StoreLabel(& label, parameters->labelList); parameters->posGraph = g2compressed; WriteGraphToDotFile(parameters->outFileName, parameters); printf("Compressed graph written to dot file %s\n", parameters->outFileName); } FreeGraph(g2compressed); FreeInstanceList(instanceList); FreeGraph(g1); FreeGraph(g2); FreeParameters(parameters); return 0; }