net.seninp.util.StackTrace Java Examples

The following examples show how to use net.seninp.util.StackTrace. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrammarvizRuleChartPanel.java    From grammarviz2_src with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Highlight the original time series sequences of a rule.
 * 
 * @param index index of the rule in the sequitur table.
 */
protected void chartIntervalsForRule(ArrayList<String> newlySelectedRaw) {
  try {
    ArrayList<double[]> intervals = new ArrayList<double[]>();
    for (String str : newlySelectedRaw) {
      ArrayList<RuleInterval> arrPos = this.session.chartData
          .getRulePositionsByRuleNum(Integer.valueOf(str));
      for (RuleInterval saxPos : arrPos) {
        intervals.add(extractInterval(saxPos.getStart(), saxPos.getEnd()));
      }
    }
    chartIntervals(intervals);
  }
  catch (Exception e) {
    System.err.println(StackTrace.toString(e));
  }
}
 
Example #2
Source File: GrammarvizRuleChartPanel.java    From grammarviz2_src with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Highlight the original time series sequences of a sub-sequences class.
 * 
 * @param index index of the class in the sub-sequences class table.
 */
protected void chartIntervalsForClass(ArrayList<String> newlySelectedRaw) {
  try {
    ArrayList<double[]> intervals = new ArrayList<double[]>();
    for (String str : newlySelectedRaw) {
        ArrayList<RuleInterval> arrPos = this.session.chartData
            .getSubsequencesPositionsByClassNum(Integer.valueOf(str));
        for (RuleInterval saxPos : arrPos) {
          intervals.add(extractInterval(saxPos.getStart(), saxPos.getEnd()));
        }
      }
      chartIntervals(intervals);
    }
    catch (Exception e) {
      System.err.println(StackTrace.toString(e));
    }
}
 
Example #3
Source File: UserSession.java    From grammarviz2_src with GNU General Public License v2.0 6 votes vote down vote up
public UserSession() {

    super();

    this.saxWindow = DEFAULT_SAX_WINDOW;
    this.saxPAA = DEFAULT_SAX_PAA;
    this.saxAlphabet = DEFAULT_SAX_ALPHABET;
    this.useSlidingWindow = USE_SLIDING_WINDOW;
    this.numerosityReductionStrategy = DEFAULT_NUMEROSITY_REDUCTION_STRATEGY;
    this.normalizationThreshold = DEFAULT_NORMALIZATION_THRESHOLD_VALUE;
    this.giAlgorithm = DEFAULT_GI_ALGORITHM;
    this.countStrategy = DEFAULT_COUNT_STRATEGY;

    // attempt to fill the rule coverage name automatically
    //
    String filename = "";
    try {
      String currentPath = new File(".").getCanonicalPath();
      filename = currentPath + File.separator + "density_curve.txt";
    }
    catch (IOException e) {
      System.err.println(
          "Error has been thrown, unable to findout the current path: " + StackTrace.toString(e));
    }
    this.ruleDensityOutputFileName = filename;
  }
 
Example #4
Source File: DoublyLinkedSortedList.java    From SAX with GNU General Public License v2.0 5 votes vote down vote up
@Override
public T next() {
  try {
    if (null == current) {
      current = this.list.first;
      return current.data;
    }
    current = current.next;
    return current.data;
  }
  catch (Exception e) {
    throw new NoSuchElementException(
        "There was an exception thrown: " + StackTrace.toString(e));
  }
}
 
Example #5
Source File: TestStackTrace.java    From SAX with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests the Stack Tracing. Generates an exception, makes the Stack Trace, and checks to see if it
 * seems OK.
 */
@Test
public void testStackTrace() {
  String trace;
  try {
    throw new Exception("Test Exception");
  }
  catch (Exception e) {
    trace = StackTrace.toString(e);
  }
  assertTrue("Check trace", trace.startsWith("java.lang.Exception"));
}
 
Example #6
Source File: GrammarvizRuleChartPanel.java    From grammarviz2_src with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Charts a subsequence for a selected row in the anomaly table.
 * 
 * @param newlySelectedAnomalies
 */
private void chartIntervalForAnomaly(ArrayList<String> newlySelectedAnomalies) {
  try {
    ArrayList<double[]> intervals = new ArrayList<double[]>();
    for (String str : newlySelectedAnomalies) {
      DiscordRecord dr = this.session.chartData.getAnomalies().get(Integer.valueOf(str));
      intervals.add(extractInterval(dr.getPosition(), dr.getPosition() + dr.getLength()));
    }
    chartIntervals(intervals);
  }
  catch (Exception e) {
    System.err.println(StackTrace.toString(e));
  }
}
 
Example #7
Source File: SAXCLIConverter.java    From SAX with GNU General Public License v2.0 4 votes vote down vote up
/**
 * The main runnable.
 * 
 * @param args the command line parameters.
 */
public static void main(String[] args) {

  try {

    SAXCLIParameters params = new SAXCLIParameters();
    JCommander jct = new JCommander(params, args);

    if (0 == args.length) {
      jct.usage();
    }
    else {
      // get params printed
      //
      StringBuffer sb = new StringBuffer(1024);
      sb.append("SAX CLI converter v.1").append(CR);
      sb.append("parameters:").append(CR);

      sb.append("  input file:                  ").append(SAXCLIParameters.IN_FILE).append(CR);
      sb.append("  output file:                 ").append(SAXCLIParameters.OUT_FILE).append(CR);
      sb.append("  SAX sliding window size:     ").append(SAXCLIParameters.SAX_WINDOW_SIZE)
          .append(CR);
      sb.append("  SAX PAA size:                ").append(SAXCLIParameters.SAX_PAA_SIZE)
          .append(CR);
      sb.append("  SAX alphabet size:           ").append(SAXCLIParameters.SAX_ALPHABET_SIZE)
          .append(CR);
      sb.append("  SAX numerosity reduction:    ").append(SAXCLIParameters.SAX_NR_STRATEGY)
          .append(CR);
      sb.append("  SAX normalization threshold: ").append(SAXCLIParameters.SAX_NORM_THRESHOLD)
          .append(CR);
      sb.append("  threads to use:              ").append(SAXCLIParameters.THREADS_NUM)
          .append(CR);

      String dataFName = SAXCLIParameters.IN_FILE;
      double[] ts = TSProcessor.readFileColumn(dataFName, 0, 0);

      Integer slidingWindowSize = Integer.valueOf(SAXCLIParameters.SAX_WINDOW_SIZE);
      Integer paaSize = Integer.valueOf(SAXCLIParameters.SAX_PAA_SIZE);
      Integer alphabetSize = Integer.valueOf(SAXCLIParameters.SAX_ALPHABET_SIZE);

      NumerosityReductionStrategy nrStrategy = SAXCLIParameters.SAX_NR_STRATEGY;

      Double nThreshold = SAXCLIParameters.SAX_NORM_THRESHOLD;

      NormalAlphabet na = new NormalAlphabet();
      SAXProcessor sp = new SAXProcessor();

      Integer threadsNum = SAXCLIParameters.THREADS_NUM;
      
      SAXRecords res = null;

      if (threadsNum > 1) {
        ParallelSAXImplementation ps = new ParallelSAXImplementation();
        res = ps.process(ts, threadsNum, slidingWindowSize, paaSize, alphabetSize, nrStrategy,
            nThreshold);
      }
      else {
        res = sp.ts2saxViaWindow(ts, slidingWindowSize, paaSize, na.getCuts(alphabetSize),
            nrStrategy, nThreshold);
      }

      ArrayList<Integer> indexes = new ArrayList<Integer>();
      indexes.addAll(res.getIndexes());
      Collections.sort(indexes);

      BufferedWriter bw = new BufferedWriter(new FileWriter(new File(SAXCLIParameters.OUT_FILE)));
      for (Integer idx : indexes) {
        bw.write(idx + COMMA + String.valueOf(res.getByIndex(idx).getPayload()) + CR);
      }
      bw.close();

    }
  }
  catch (IOException | SAXException e) {
    System.err.println("error occured while parsing parameters " + Arrays.toString(args) + CR
        + StackTrace.toString(e));
    System.exit(-1);
  }

}
 
Example #8
Source File: TestMotifDiscovery.java    From SAX with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testEMMA() {
  MotifRecord motifsBF;
  MotifRecord motifsEMMA;
  try {

    // Date start = new Date();
    BruteForceMotifImplementation.distCounter = 0;
    BruteForceMotifImplementation.eaCounter = 0;
    motifsBF = BruteForceMotifImplementation.series2BruteForceMotifs(series, MOTIF_SIZE,
        MOTIF_RANGE, ZNORM_THRESHOLD);
    // System.out.println(
    // "brute force: " + SAXProcessor.timeToString(start.getTime(), new Date().getTime()) + " : "
    // + motifsBF + ", dist calls: " + BruteForceMotifImplementation.distCounter
    // + ", early abandoned: " + BruteForceMotifImplementation.eaCounter);

    // start = new Date();
    EMMAImplementation.distCounter = 0;
    EMMAImplementation.eaCounter = 0;
    motifsEMMA = EMMAImplementation.series2EMMAMotifs(series, MOTIF_SIZE, MOTIF_RANGE, 6, 4,
        ZNORM_THRESHOLD);
    // System.out.println("emma: " + SAXProcessor.timeToString(start.getTime(), new
    // Date().getTime())
    // + " : " + motifsEMMA + ", dist calls: " + EMMAImplementation.distCounter
    // + ", early abandoned: " + EMMAImplementation.eaCounter);

    assertEquals("Asserting motif frequency", motifsBF.getFrequency(), motifsEMMA.getFrequency());

    for (Integer m : motifsBF.getOccurrences()) {
      // System.out.println("asserting at " + m);
      assertTrue("Asserting motif locations", motifsEMMA.getOccurrences().contains(m));
    }

    // for (int i = 0; i < 3; i++) {
    // long tstamp0 = System.currentTimeMillis();
    // for (int j = 0; j < 100; j++) {
    // motifsEMMA = EMMAImplementation.series2EMMAMotifs(series, MOTIF_SIZE, MOTIF_RANGE, 5, 5,
    // 0.001);
    // }
    // System.out.println("** " + (System.currentTimeMillis() - tstamp0));
    // }
    //
    // for (int i = 0; i < 3; i++) {
    // long tstamp0 = System.currentTimeMillis();
    // for (int j = 0; j < 100; j++) {
    // motifsBF = BruteForceMotifImplementation.series2BruteForceMotifs(series, MOTIF_SIZE,
    // MOTIF_RANGE, ZNORM_THRESHOLD);
    // }
    // System.out.println("* " + (System.currentTimeMillis() - tstamp0));
    // }

  }
  catch (Exception e) {
    fail("It shouldnt fail, but failed with " + StackTrace.toString(e));
  }
}