public void run() { Runtime runtime = Runtime.getRuntime(); timer.start(); while (true) { peak = Math.max(peak, runtime.totalMemory() - runtime.freeMemory()); if (timer.report() > logFrequency) { log(); timer.restart(); } try { Thread.sleep(pollFrequency); } catch (InterruptedException e) { log(); throw new RuntimeInterruptedException(e); } } }
@Override protected CRFLogConditionalObjectiveFunction getObjectiveFunction(int[][][][] data, int[][] labels) { int[][][][] unsupDropoutData = null; if (unsupDocs != null) { Timing timer = new Timing(); timer.start(); List<Triple<int[][][], int[], double[][][]>> unsupDataAndLabels = documentsToDataAndLabelsList(unsupDocs); unsupDropoutData = new int[unsupDataAndLabels.size()][][][]; for (int q=0; q<unsupDropoutData.length; q++) unsupDropoutData[q] = unsupDataAndLabels.get(q).first(); long elapsedMs = timer.stop(); log.info("Time to read unsupervised dropout data: " + Timing.toSecondsString(elapsedMs) + " seconds, read " + unsupDropoutData.length + " files"); } return new CRFLogConditionalObjectiveFunctionWithDropout(data, labels, windowSize, classIndex, labelIndices, map, flags.priorType, flags.backgroundSymbol, flags.sigma, null, flags.dropoutRate, flags.dropoutScale, flags.multiThreadGrad, flags.dropoutApprox, flags.unsupDropoutScale, unsupDropoutData); }
/** Returns the number of seconds passed since the timer started in the form "d.d". */ public String toSecondsString() { return toSecondsString(report()); }
Timing total = new Timing(); Timing current = new Timing(); total.start(); current.start(); for (k = 0; k<maxIterations ; k++) { try{ double curVal = dfunction.valueAt(x); say(" TrueValue{ " + curVal + " } "); file.println(k + " , " + curVal + " , " + total.report() ); if (total.report() >= maxTime){ sayln("Stochastic Optimization complete. Stopped after max time"); x = newX; say("[" + ( total.report() )/1000.0 + " s " ); say("{" + (current.restart()/1000.0) + " s}] "); say(" "+dfunction.lastValue()); infoFile.println(( total.report() )/1000.0 + "; Completion Time"); infoFile.println(dfunction.valueAt(x) + "; Finalvalue"); say("Completed in: " + ( total.report() )/1000.0 + " s");
public static Map<String,String> loadWordClusters(String file, String format) { Timing.startDoing("Loading distsim lexicon from " + file); Map<String,String> lexicon = new LcMap<>(); if ("terryKoo".equals(format)) { for (String line : ObjectBank.getLineIterator(file)) { String[] bits = line.split("\\t"); String word = bits[1]; // for now, always lowercase, but should revisit this word = word.toLowerCase(); String wordClass = bits[0]; lexicon.put(word, wordClass); } } else { // "alexClark" for (String line : ObjectBank.getLineIterator(file)) { String[] bits = line.split("\\s+"); String word = bits[0]; // for now, always lowercase, but should revisit this word = word.toLowerCase(); lexicon.put(word, bits[1]); } } Timing.endDoing(); return lexicon; }
@Override public void run() { try { Timing t = new Timing(); TestClassifier testClassifier = new TestClassifier(tagger); long millis = t.stop(); resultsString = testClassifier.resultsString(tagger); System.out.println("Thread " + threadName + " took " + millis + " milliseconds to tag " + testClassifier.getNumWords() + " words.\n" + resultsString); } catch(IOException e) { throw new RuntimeException(e); } } } // end class TaggerThread
/** * Run the pipeline on an input annotation. * The annotation is modified in place. * * @param annotation The input annotation, usually a raw document */ @Override public void annotate(Annotation annotation) { Iterator<MutableLong> it = accumulatedTime.iterator(); Timing t = new Timing(); for (Annotator annotator : annotators) { if (Thread.interrupted()) { // Allow interrupting throw new RuntimeInterruptedException(); } if (TIME) { t.start(); } annotator.annotate(annotation); if (TIME) { long elapsed = t.stop(); MutableLong m = it.next(); m.incValue(elapsed); } } }
/** * Loads treebank grammar from first argument and prints it. * Just a demonstration of functionality. * <p> * {@code usage: java MemoryTreebank treebankFilesPath} * * @param args array of command-line arguments */ public static void main(String[] args) { Timing.startTime(); Treebank treebank = new MemoryTreebank(PennTreeReader::new); treebank.loadPath(args[0]); Timing.endTime(); System.out.println(treebank); }
@Override public void dumpFeatures(Collection<List<IN>> docs) { if (flags.exportFeatures != null) { Timing timer = new Timing(); CRFFeatureExporter<IN> featureExporter = new CRFFeatureExporter<>(this); featureExporter.printFeatures(flags.exportFeatures, docs); long elapsedMs = timer.stop(); log.info("Time to export features: " + Timing.toSecondsString(elapsedMs) + " seconds"); } }
/** * Print elapsed time on (static) timer to * {@code System.err} (without stopping timer). * * @param str Additional prefix string to be printed * @return Number of milliseconds elapsed */ public static long endTime(String str) { return endTime(str, System.err); }
public void annotate(Annotation annotation) { if (VERBOSE) { timer.start(); log.info("Normalizing quantifiable entities..."); } if (annotation.containsKey(CoreAnnotations.SentencesAnnotation.class)) { List<CoreMap> sentences = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); annotateTokens(tokens); } if (VERBOSE) { timer.stop("done."); log.info("output: " + sentences + '\n'); } } else if (annotation.containsKey(CoreAnnotations.TokensAnnotation.class)) { List<CoreLabel> tokens = annotation.get(CoreAnnotations.TokensAnnotation.class); annotateTokens(tokens); } else { throw new RuntimeException("unable to find sentences in: " + annotation); } }
public static <T> T readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(Redwood.RedwoodChannels log, String msg, String path) { T obj; try { Timing timing = new Timing(); obj = IOUtils.readObjectFromURLOrClasspathOrFileSystem(path); log.info(msg + ' ' + path + " ... done [" + timing.toSecondsString() + " sec]."); } catch (IOException | ClassNotFoundException e) { throw new RuntimeIOException(e); } return obj; }
/** * Print elapsed time to {@code System.err} and restart timer. * * @param str Additional prefix string to be printed * @return Number of milliseconds elapsed */ public long restart(String str) { return this.restart(str, System.err); }