Пример #1
0
  /**
   * 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();
  }
Пример #2
0
 /** It clears all the attributes of AlgoSpam class */
 public void clear() {
   frequentItems.clear();
   if (saver != null) {
     saver.clear();
     saver = null;
   }
 }
Пример #3
0
 public String printStatistics() {
   StringBuilder sb = new StringBuilder(200);
   sb.append("=============  Algorithm - STATISTICS =============\n Total time ~ ");
   sb.append(getRunningTime());
   sb.append(" ms\n");
   sb.append(" Frequent sequences count : ");
   sb.append(numberOfFrequentPatterns);
   sb.append('\n');
   sb.append(" Max memory (mb):");
   sb.append(MemoryLogger.getInstance().getMaxMemory());
   sb.append('\n');
   sb.append(saver.print());
   sb.append("\n===================================================\n");
   return sb.toString();
 }
Пример #4
0
  /**
   * 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();
  }