/** @param args the command line arguments */ public static void main(String[] args) throws IOException { String outputPath = ".//output.txt"; // Load a sequence database double support = 0.5; boolean keepPatterns = true; boolean verbose = false; AbstractionCreator abstractionCreator = AbstractionCreator_Qualitative.getInstance(); boolean dfs = true; IdListCreator idListCreator = IdListCreator_StandardMap.getInstance(); CandidateGenerator candidateGenerator = CandidateGenerator_Qualitative.getInstance(); SequenceDatabase sequenceDatabase = new SequenceDatabase(abstractionCreator, idListCreator); sequenceDatabase.loadFile(fileToPath("contextPrefixSpan.txt"), support); System.out.println(sequenceDatabase.toString()); AlgoSPADE algorithm = new AlgoSPADE(support, dfs, abstractionCreator); algorithm.runAlgorithm(sequenceDatabase, candidateGenerator, keepPatterns, verbose, outputPath); System.out.println("Minimum support (relative) = " + support); System.out.println(algorithm.getNumberOfFrequentPatterns() + " frequent patterns."); System.out.println(algorithm.printStatistics()); }
/** * Actual call to SPAM algorithm. The output can be either kept or ignore. Whenever we choose to * keep the patterns found, we can keep them in a file or in the main memory * * @param database Original database in where we want to search for the frequent patterns. * @param keepPatterns Flag indicating if we want to keep the output or not * @param verbose Flag for debugging purposes * @param outputFilePath Path of the file in which we want to store the frequent patterns. If this * value is null, we keep the patterns in the main memory. This argument is taken into account * just when keepPatterns is activated. * @throws IOException */ public void runAlgorithm( SequenceDatabase database, boolean keepPatterns, boolean verbose, String outputFilePath) throws IOException { // If we do no have any file path if (outputFilePath == null) { // The user wants to save the results in memory saver = new SaverIntoMemory(); } else { // Otherwise, the user wants to save them in the given file saver = new SaverIntoFile(outputFilePath); } this.minSupAbsolute = (int) Math.ceil(minSupRelative * database.size()); if (this.minSupAbsolute == 0) { // protection this.minSupAbsolute = 1; } // reset the stats about memory usage MemoryLogger.getInstance().reset(); // keeping the starting time start = System.currentTimeMillis(); // We run SPAM algorithm runSPAM(database, (long) minSupAbsolute, keepPatterns, verbose); // keeping the ending time end = System.currentTimeMillis(); // Search for frequent patterns: Finished saver.finish(); }
/** * The actual method for extracting frequent sequences. * * @param database The original database * @param minSupportAbsolute the absolute minimum support * @param keepPatterns flag indicating if we are interested in keeping the output of the algorithm * @param verbose Flag for debugging purposes */ protected void runSPAM( SequenceDatabase database, long minSupportAbsolute, boolean keepPatterns, boolean verbose) { // We get the equivalence classes formed by the frequent 1-patterns frequentItems = database.frequentItems(); // We extract their patterns Collection<Pattern> size1sequences = getPatterns(frequentItems); // If we want to keep the output if (keepPatterns) { for (Pattern atom : size1sequences) { // We keep all the frequent 1-patterns saver.savePattern(atom); } } database = null; // We define the root class EquivalenceClass rootClass = new EquivalenceClass(null); /*And we insert the equivalence classes corresponding to the frequent 1-patterns as its members*/ for (EquivalenceClass atom : frequentItems) { rootClass.addClassMember(atom); } // Inizialitation of the class that is in charge of find the frequent patterns FrequentPatternEnumeration_SPAM frequentPatternEnumeration = new FrequentPatternEnumeration_SPAM(minSupAbsolute, saver); // We execute the search frequentPatternEnumeration.execute(rootClass, keepPatterns, verbose); // Once we had finished, we keep the number of frequent patterns that we found numberOfFrequentPatterns = frequentPatternEnumeration.getFrequentPatterns(); // check the memory usage for statistics MemoryLogger.getInstance().checkMemory(); }