List of usage examples for org.apache.commons.math.stat.descriptive SummaryStatistics SummaryStatistics
public SummaryStatistics()
From source file:org.apache.hadoop.hive.ql.exec.tez.TestHostAffinitySplitLocationProvider.java
private double testHashDistribution(int locs, final int missCount, FileSplit[] splits, AtomicInteger errorCount) { // This relies heavily on what method determineSplits ... calls and doesn't. // We could do a wrapper with only size() and get() methods instead of List, to be sure. @SuppressWarnings("unchecked") List<String> partLocs = (List<String>) Mockito.mock(List.class); Mockito.when(partLocs.size()).thenReturn(locs); final AtomicInteger state = new AtomicInteger(0); Mockito.when(partLocs.get(Mockito.anyInt())).thenAnswer(new Answer<String>() { @Override//from w w w.j av a 2s .co m public String answer(InvocationOnMock invocation) throws Throwable { return (state.getAndIncrement() == missCount) ? "not-null" : null; } }); int[] hitCounts = new int[locs]; for (int splitIx = 0; splitIx < splits.length; ++splitIx) { state.set(0); int index = HostAffinitySplitLocationProvider.determineLocation(partLocs, splits[splitIx].getPath().toString(), splits[splitIx].getStart(), null); ++hitCounts[index]; } SummaryStatistics ss = new SummaryStatistics(); for (int hitCount : hitCounts) { ss.addValue(hitCount); } // All of this is completely bogus and mostly captures the following function: // f(output) = I-eyeballed-the(output) == they-look-ok. // It's pretty much a golden file... // The fact that stdev doesn't increase with increasing missCount is captured outside. double avg = ss.getSum() / ss.getN(), stdev = ss.getStandardDeviation(), cv = stdev / avg; double allowedMin = avg - 2.5 * stdev, allowedMax = avg + 2.5 * stdev; if (allowedMin > ss.getMin() || allowedMax < ss.getMax() || cv > 0.22) { LOG.info("The distribution for " + locs + " locations, " + missCount + " misses isn't to " + "our liking: avg " + avg + ", stdev " + stdev + ", cv " + cv + ", min " + ss.getMin() + ", max " + ss.getMax()); errorCount.incrementAndGet(); } return cv; }
From source file:org.apache.mahout.freqtermsets.fpgrowth.FPGrowth.java
/** * Internal TopKFrequentPattern Generation algorithm, which represents the * A's as integers and transforms features to use only integers * //from w w w. j a v a2 s . c om * @param transactions * Transaction database Iterator * @param attributeFrequency * array representing the Frequency of the corresponding * attribute id * @param minSupport * minimum support of the pattern to be mined * @param k * Max value of the Size of the Max-Heap in which Patterns are * held * @param featureSetSize * number of features * @param returnFeatures * the id's of the features for which Top K patterns have to be * mined * @param topKPatternsOutputCollector * the outputCollector which transforms the given Pattern in * integer format to the corresponding A Format */ private void generateTopKFrequentPatterns( // Iterator<Pair<int[], Long>> transactions, TransactionTree cTree, OpenObjectIntHashMap<A> attributeIdMapping, long[] attributeFrequency, long minSupport, int k, int featureSetSize, Collection<Integer> returnFeatures, TopKPatternsOutputConverter<A> topKPatternsOutputCollector, StatusUpdater updater) throws IOException { // YA: BONSAAAAAAAII { // FPTree tree = new FPTree(featureSetSize); FPTree tree = null; boolean change = true; int pruneIters = 0; IntArrayList pruneByContingencyCount = new IntArrayList(); IntArrayList pruneBySpreadCount = new IntArrayList(); while (change) { pruneByContingencyCount.add(0); pruneBySpreadCount.add(0); change = false; tree = new FPTree(featureSetSize); OpenIntLongHashMap[] childJointFreq; long[] sumChildSupport; if (BONSAI_PRUNE) { childJointFreq = new OpenIntLongHashMap[featureSetSize]; sumChildSupport = new long[featureSetSize]; } double supportGrandTotal = 0; // } YA: BONSAAAAAAAII for (int i = 0; i < featureSetSize; i++) { tree.addHeaderCount(i, attributeFrequency[i]); // YA: BONSAAAAAAAII { if (attributeFrequency[i] < 0) { continue; // this is an attribute not satisfying the // monotone constraint } if (BONSAI_PRUNE) { childJointFreq[i] = new OpenIntLongHashMap(); supportGrandTotal += attributeFrequency[i]; } // } YA: Bonsai } // Constructing initial FPTree from the list of transactions // YA Bonsai : To pass the tree itself the iterator now would work // only with ints.. the A type argument is // not checked in the constructor. TOD: remove the type argument and // force using ints only Iterator<Pair<int[], Long>> transactions = new IntTransactionIterator(cTree.iterator(), attributeIdMapping); int nodecount = 0; // int attribcount = 0; int i = 0; while (transactions.hasNext()) { Pair<int[], Long> transaction = transactions.next(); Arrays.sort(transaction.getFirst()); // attribcount += transaction.length; // YA: Bonsai { // nodecount += treeAddCount(tree, transaction.getFirst(), // transaction.getSecond(), minSupport, attributeFrequency); int temp = FPTree.ROOTNODEID; boolean addCountMode = true; for (int attribute : transaction.getFirst()) { if (attributeFrequency[attribute] < 0) { continue; // this is an attribute not satisfying the // monotone constraint } if (attributeFrequency[attribute] < minSupport) { break; } if (BONSAI_PRUNE && tree.attribute(temp) != -1) { // Root node childJointFreq[tree.attribute(temp)].put(attribute, childJointFreq[tree.attribute(temp)].get(attribute) + transaction.getSecond()); sumChildSupport[tree.attribute(temp)] += transaction.getSecond(); } int child; if (addCountMode) { child = tree.childWithAttribute(temp, attribute); if (child == -1) { addCountMode = false; } else { tree.addCount(child, transaction.getSecond()); temp = child; } } if (!addCountMode) { child = tree.createNode(temp, attribute, transaction.getSecond()); temp = child; nodecount++; } } // } YA Bonsai i++; if (i % 10000 == 0) { log.info("FPTree Building: Read {} Transactions", i); } } log.info("Number of Nodes in the FP Tree: {}", nodecount); // YA: BONSAAAAAAAII { if (BONSAI_PRUNE) { if (log.isTraceEnabled()) log.info("Bonsai prunining tree: {}", tree.toString()); for (int a = 0; a < tree.getHeaderTableCount(); ++a) { int attr = tree.getAttributeAtIndex(a); if (attributeFrequency[attr] < 0) { continue; // this is an attribute not satisfying the // monotone constraint } if (attributeFrequency[attr] < minSupport) { break; } // if (sumChildSupport[attr] < attributeFrequency[attr]) { // // the case of . (full stop) as the next child // childJointFreq[attr] // .put(-1, // (long) (attributeFrequency[attr] - sumChildSupport[attr])); // } float numChildren = childJointFreq[attr].size(); // if (numChildren < LEAST_NUM_CHILDREN_TO_VOTE_FOR_NOISE) { // continue; // } if (log.isTraceEnabled()) { log.trace("Voting for noisiness of attribute {} with number of children: {}", attr, numChildren); log.trace("Attribute support: {} - Total Children support: {}", attributeFrequency[attr], sumChildSupport[attr]); } // EMD and the such.. the threshold isn't easy to define, and it // also doesn't take into account the weights of children. // // double uniformProb = 1.0 / numChildren; // // double uniformProb = sumChildSupport[attr] / // supportGrandTotal; // double uniformFreq = attributeFrequency[attr] / numChildren; // IntArrayList childAttrArr = childJointFreq[attr].keys(); // // IntArrayList childAttrArr = new IntArrayList(); // // childJointFreq[attr].keysSortedByValue(childAttrArr); // double totalDifference = 0; // double sumOfWeights = 0; // // double emd = 0; // for (int c = childAttrArr.size() - 1; c >=0 ; --c) { // int childAttr = childAttrArr.get(c); // double childJF = childJointFreq[attr].get(childAttr); // double childWeight = attributeFrequency[childAttr]; // totalDifference += childWeight * Math.abs(childJF - // uniformFreq); // sumOfWeights += childWeight; // // // double jointProb = childJF / // // supportGrandTotal; // // double childProb = attributeFrequency[childAttr] / // // supportGrandTotal; // // double childConditional = childJF / // attributeFrequency[attr]; // // emd = childConditional + emd - uniformProb; // // emd = childJF + emd - uniformFreq; // // totalDifference += Math.abs(emd); // } // // Probability (D > observed ) = QKS Ne + 0.12 + 0.11/ Ne D // // double pNotUniform = totalDifference / attrSupport; // // double threshold = (numChildren * (numChildren - 1) * 1.0) // // / (2.0 * attributeFrequency[attr]); // double weightedDiff = totalDifference / sumOfWeights; // double threshold = sumOfWeights / 2.0; // each child can be // up to // // 1 over or below the // // uniform freq // boolean noise = weightedDiff < threshold; // log.info("EMD: {} - Threshold: {}", weightedDiff, threshold); // /////////////////////////////////// // Log odds.. this is my hartala, and it needs ot be shifted // according to the number of children // // // if there is one child then the prob of random choice // // will be // // // 1, so anything would be // // // noise // // // and if there are few then the probability that this is // // // actually noise declines // // if (numChildren >= LEAST_NUM_CHILDREN_TO_VOTE_FOR_NOISE) // // { // // log.info( // // // "Voting for noisiness of attribute {} with number of children: {}", // // currentAttribute, numChildren); // // log.info( // // "Attribute support: {} - Total Children support: {}", // // attrSupport, sumOfChildSupport); // // int noiseVotes = 0; // // double randomSelectionLogOdds = 1.0 / numChildren; // // randomSelectionLogOdds = Math.log(randomSelectionLogOdds // // / (1 - randomSelectionLogOdds)); // // randomSelectionLogOdds = // // Math.abs(randomSelectionLogOdds); // // // // IntArrayList childAttrArr = childJointFreq.keys(); // // for (int c = 0; c < childAttrArr.size(); ++c) { // // double childConditional = 1.0 // // * childJointFreq.get(childAttrArr.get(c)) // // / sumOfChildSupport; // attrSupport; // // double childLogOdds = Math.log(childConditional // // / (1 - childConditional)); // // if (Math.abs(childLogOdds) <= randomSelectionLogOdds) { // // // probability of the child given me is different // // // than // // // probability of choosing the // // // child randomly // // // from among my children.. using absolute log odds // // // because they are symmetric // // ++noiseVotes; // // } // // } // // log.info("Noisy if below: {} - Noise votes: {}", // // randomSelectionLogOdds, noiseVotes); // // noise = noiseVotes == numChildren; // //////////////////////////////////////////////////// // // Kullback-liebler divergence from the uniform distribution // double randomChild = 1.0 / numChildren; // IntArrayList childAttrArr = childJointFreq[attr].keys(); // // double klDivergence = 0; // for (int c = 0; c < childAttrArr.size(); ++c) { // double childConditional = 1.0 // * childJointFreq[attr].get(childAttrArr.get(c)) // / attributeFrequency[attr]; // if (childConditional == 0) { // continue; // a7a! // } // klDivergence += childConditional // * Math.log(childConditional / randomChild); // } // // boolean noise = Math.abs(klDivergence) < 0.05; // log.info("KL-Divergence: {} - Noise less than: {}", // klDivergence, 0.05); // ////////////////////////////////////// // Pair wise metric with different children SummaryStatistics metricSummary = new SummaryStatistics(); // double[] metric = new double[(int) numChildren]; // SummaryStatistics spreadSummary = new SummaryStatistics(); // double uniformSpread = attributeFrequency[attr] / // numChildren; double goodnessOfFit = 0.0; // If I don't take the . into account: sumChildSupport[attr] / // numChildren; double sumOfWeights = 0; IntArrayList childAttrArr = childJointFreq[attr].keys(); for (int c = 0; c < childAttrArr.size(); ++c) { int childAttr = childAttrArr.get(c); double[][] contingencyTable = new double[2][2]; if (childAttr == -1) { // this is meaningless, as yuleq will just be 1 contingencyTable[1][1] = childJointFreq[attr].get(childAttr); contingencyTable[1][0] = sumChildSupport[attr]; // equals attributeFrequency[attr] - // contingencyTable[1][1]; contingencyTable[0][1] = 0; contingencyTable[0][0] = supportGrandTotal - attributeFrequency[attr]; } else { contingencyTable[1][1] = childJointFreq[attr].get(childAttr); contingencyTable[1][0] = attributeFrequency[attr] - contingencyTable[1][1]; contingencyTable[0][1] = attributeFrequency[childAttr] - contingencyTable[1][1]; contingencyTable[0][0] = supportGrandTotal - attributeFrequency[attr] - attributeFrequency[childAttr] + contingencyTable[1][1]; // because of the meninglessness of yuleq in case of . } double ad = contingencyTable[0][0] * contingencyTable[1][1]; double bc = contingencyTable[0][1] * contingencyTable[1][0]; double yuleq = (ad - bc) / (ad + bc); double weight = attributeFrequency[childAttr]; sumOfWeights += weight; metricSummary.addValue(Math.abs(yuleq * weight)); // metricSummary.addValue(yuleq * yuleq * weight); } // spreadSummary.addValue(Math.abs(uniformSpread // - contingencyTable[1][1]) // / numChildren); // spreadSummary.addValue(contingencyTable[1][1]); // * // weight goodnessOfFit += contingencyTable[1][1] * contingencyTable[1][1]; } // double weightedquadraticMean = // Math.sqrt(metricSummary.getSum() / sumOfWeights); double weightedMean = (metricSummary.getSum() / sumOfWeights); boolean noise = false; // if (weightedMean < 0.5) { // pruneByContingencyCount.set(pruneIters, pruneByContingencyCount.get(pruneIters) + 1); // noise = true; // } else if (weightedMean < 0.95) { if (numChildren > 1) { double n = sumChildSupport[attr]; // attributeFrequency[attr]; goodnessOfFit /= (n / numChildren); goodnessOfFit -= n; ChiSquaredDistributionImpl chisqDist = new ChiSquaredDistributionImpl(numChildren - 1); double criticalPoint = -1; try { criticalPoint = chisqDist.inverseCumulativeProbability(1.0 - SIGNIFICANCE / 2.0); } catch (MathException e) { log.error(e.getMessage(), e); } if (goodnessOfFit < criticalPoint) { pruneBySpreadCount.set(pruneIters, pruneBySpreadCount.get(pruneIters) + 1); noise = true; } // // double spreadCentraltendency = (spreadSummary.getMax() // - // // spreadSummary.getMin()) / 2.0; // // spreadSummary.getMean(); // // double uniformSpread = sumChildSupport[attr] / // // numChildren; // // // noise = Math.abs(spreadCentraltendency - // uniformSpread) < // // 1e-4; // // double spreadCentraltendency = spreadSummary.getMean(); // // (spreadSummary.getMax() - // // spreadSummary.getMin()) / 2.0; // if(spreadCentraltendency < 1e-6){ // noise = true; // } // // if (!noise && numChildren > 0) { // // see if the difference is statitically significant // double spreadCI = getConfidenceIntervalHalfWidth( // spreadSummary, SIGNIFICANCE); // spreadCentraltendency -= spreadCI; // if (spreadCentraltendency < 0) { // noise = true; // } // // // noise if the CI contains the uniform spread // // threshold // // if (spreadCentraltendency > uniformSpread) { // // noise = (spreadCentraltendency - spreadCI) < // // uniformSpread; // // } else { // // noise = (spreadCentraltendency + spreadCI) > // // uniformSpread; // // } // } } change |= noise; if (noise) { if (log.isTraceEnabled()) log.info("Pruning attribute {} with child joint freq {}", attr, childJointFreq[attr]); returnFeatures.remove(attr); attributeFrequency[attr] = -1; } } } ++pruneIters; } if (log.isTraceEnabled()) { log.info("Pruned tree: {}", tree.toString()); log.info("Prune by contingency: {} - Prune by spread: {}", pruneByContingencyCount.toString(), pruneBySpreadCount.toString()); } // } YA: Bonsai fpGrowth(tree, minSupport, k, returnFeatures, topKPatternsOutputCollector, updater); }
From source file:org.apache.sling.engine.impl.RequestProcessorMBeanImplTest.java
/** * Asserts that the simple standard deviation algorithm used by the * RequestProcessorMBeanImpl is equivalent to the Commons Math * SummaryStatistics implementation./*from w w w. j a v a 2 s. co m*/ * * It also tests that resetStatistics method, actually resets all the statistics * * @throws NotCompliantMBeanException not expected */ @Test public void test_statistics() throws NotCompliantMBeanException { final SummaryStatistics durationStats = new SummaryStatistics(); final SummaryStatistics servletCallCountStats = new SummaryStatistics(); final SummaryStatistics peakRecursionDepthStats = new SummaryStatistics(); final RequestProcessorMBeanImpl bean = new RequestProcessorMBeanImpl(); assertEquals(0l, bean.getRequestsCount()); assertEquals(Long.MAX_VALUE, bean.getMinRequestDurationMsec()); assertEquals(0l, bean.getMaxRequestDurationMsec()); assertEquals(0.0, bean.getMeanRequestDurationMsec(), 0); assertEquals(0.0, bean.getStandardDeviationDurationMsec(), 0); assertEquals(Integer.MAX_VALUE, bean.getMinServletCallCount()); assertEquals(0l, bean.getMaxServletCallCount()); assertEquals(0.0, bean.getMeanServletCallCount(), 0); assertEquals(0.0, bean.getStandardDeviationServletCallCount(), 0); assertEquals(Integer.MAX_VALUE, bean.getMinPeakRecursionDepth()); assertEquals(0l, bean.getMaxPeakRecursionDepth()); assertEquals(0.0, bean.getMeanPeakRecursionDepth(), 0); assertEquals(0.0, bean.getStandardDeviationPeakRecursionDepth(), 0); final Random random = new Random(System.currentTimeMillis() / 17); final int num = 10000; final int min = 85; final int max = 250; for (int i = 0; i < num; i++) { final long durationValue = min + random.nextInt(max - min); final int callCountValue = min + random.nextInt(max - min); final int peakRecursionDepthValue = min + random.nextInt(max - min); durationStats.addValue(durationValue); servletCallCountStats.addValue(callCountValue); peakRecursionDepthStats.addValue(peakRecursionDepthValue); final RequestData requestData = context.mock(RequestData.class, "requestData" + i); context.checking(new Expectations() { { one(requestData).getElapsedTimeMsec(); will(returnValue(durationValue)); one(requestData).getServletCallCount(); will(returnValue(callCountValue)); one(requestData).getPeakRecusionDepth(); will(returnValue(peakRecursionDepthValue)); } }); bean.addRequestData(requestData); } assertEquals("Number of points must be the same", durationStats.getN(), bean.getRequestsCount()); assertEquals("Min Duration must be equal", (long) durationStats.getMin(), bean.getMinRequestDurationMsec()); assertEquals("Max Duration must be equal", (long) durationStats.getMax(), bean.getMaxRequestDurationMsec()); assertAlmostEqual("Mean Duration", durationStats.getMean(), bean.getMeanRequestDurationMsec(), num); assertAlmostEqual("Standard Deviation Duration", durationStats.getStandardDeviation(), bean.getStandardDeviationDurationMsec(), num); assertEquals("Min Servlet Call Count must be equal", (long) servletCallCountStats.getMin(), bean.getMinServletCallCount()); assertEquals("Max Servlet Call Count must be equal", (long) servletCallCountStats.getMax(), bean.getMaxServletCallCount()); assertAlmostEqual("Mean Servlet Call Count", servletCallCountStats.getMean(), bean.getMeanServletCallCount(), num); assertAlmostEqual("Standard Deviation Servlet Call Count", servletCallCountStats.getStandardDeviation(), bean.getStandardDeviationServletCallCount(), num); assertEquals("Min Peak Recursion Depth must be equal", (long) peakRecursionDepthStats.getMin(), bean.getMinPeakRecursionDepth()); assertEquals("Max Peak Recursion Depth must be equal", (long) peakRecursionDepthStats.getMax(), bean.getMaxPeakRecursionDepth()); assertAlmostEqual("Mean Peak Recursion Depth", peakRecursionDepthStats.getMean(), bean.getMeanPeakRecursionDepth(), num); assertAlmostEqual("Standard Deviation Peak Recursion Depth", peakRecursionDepthStats.getStandardDeviation(), bean.getStandardDeviationPeakRecursionDepth(), num); //check method resetStatistics //In the previous test, some requests have been processed, now we reset the statistics so everything statistic is reinitialized bean.resetStatistics(); //Simulate a single request final long durationValue = min + random.nextInt(max - min); final int callCountValue = min + random.nextInt(max - min); final int peakRecursionDepthValue = min + random.nextInt(max - min); final RequestData requestData = context.mock(RequestData.class, "requestDataAfterReset"); context.checking(new Expectations() { { one(requestData).getElapsedTimeMsec(); will(returnValue(durationValue)); one(requestData).getServletCallCount(); will(returnValue(callCountValue)); one(requestData).getPeakRecusionDepth(); will(returnValue(peakRecursionDepthValue)); } }); bean.addRequestData(requestData); //As only one request has been simulated since resetStatiscts: min, max and mean statistics should be equals to the request data assertEquals("After resetStatistics Number of requests must be one", 1, bean.getRequestsCount()); assertEquals("After resetStatistics Min Duration must be equal", bean.getMinRequestDurationMsec(), (long) durationValue); assertEquals("After resetStatistics Max Duration must be equal", bean.getMaxRequestDurationMsec(), (long) durationValue); assertEquals("After resetStatistics Mean Duration must be equal", bean.getMeanRequestDurationMsec(), (double) durationValue, 0d); assertEquals("After resetStatistics Min Servlet Call Count must be equal", bean.getMinServletCallCount(), callCountValue); assertEquals("After resetStatistics Max Servlet Call Count must be equal", bean.getMaxServletCallCount(), callCountValue); assertEquals("After resetStatistics Mean Servlet Call Count", bean.getMeanServletCallCount(), (double) callCountValue, 0d); assertEquals("After resetStatistics Min Peak Recursion Depth must be equal", bean.getMinPeakRecursionDepth(), peakRecursionDepthValue); assertEquals("After resetStatistics Max Peak Recursion Depth must be equal", bean.getMinPeakRecursionDepth(), peakRecursionDepthValue); assertEquals("After resetStatistics Mean Peak Recursion Depth", bean.getMeanPeakRecursionDepth(), (double) peakRecursionDepthValue, 0d); }
From source file:org.datacleaner.beans.DateAndTimeAnalyzerColumnDelegate.java
public DateAndTimeAnalyzerColumnDelegate(boolean descriptiveStatistics, RowAnnotationFactory annotationFactory) { _annotationFactory = annotationFactory; _nullAnnotation = _annotationFactory.createAnnotation(); _maxDateAnnotation = _annotationFactory.createAnnotation(); _minDateAnnotation = _annotationFactory.createAnnotation(); _maxTimeAnnotation = _annotationFactory.createAnnotation(); _minTimeAnnotation = _annotationFactory.createAnnotation(); _numRows = 0;//from www . ja v a2 s .c o m if (descriptiveStatistics) { _statistics = new DescriptiveStatistics(); } else { _statistics = new SummaryStatistics(); } }
From source file:org.datacleaner.beans.NumberAnalyzerColumnDelegate.java
public NumberAnalyzerColumnDelegate(boolean descriptiveStatistics, RowAnnotationFactory annotationFactory) { _annotationFactory = annotationFactory; _nullAnnotation = _annotationFactory.createAnnotation(); _maxAnnotation = _annotationFactory.createAnnotation(); _minAnnotation = _annotationFactory.createAnnotation(); if (descriptiveStatistics) { _statistics = new DescriptiveStatistics(); } else {// w w w . j a va 2 s .c o m _statistics = new SummaryStatistics(); } }
From source file:org.datacleaner.beans.NumberAnalyzerResultReducer.java
private SummaryStatistics buildStatistics(final String column, final NumberAnalyzerResult analyzerResult) { final SummaryStatistics stats = new SummaryStatistics() { private static final long serialVersionUID = 1L; private final InputColumn<Number> col = new MockInputColumn<Number>(column); @Override//ww w. j a v a2 s .com public long getN() { return analyzerResult.getRowCount(col).longValue(); } @Override public double getSum() { return analyzerResult.getSum(col).longValue(); } @Override public double getVariance() { return analyzerResult.getVariance(col).longValue(); } @Override public double getStandardDeviation() { return analyzerResult.getStandardDeviation(col).longValue(); } @Override public double getMean() { return analyzerResult.getMean(col).longValue(); } @Override public double getMin() { return analyzerResult.getLowestValue(col).longValue(); } @Override public double getMax() { return analyzerResult.getHighestValue(col).longValue(); } @Override public double getGeometricMean() { return analyzerResult.getGeometricMean(col).doubleValue(); } @Override public double getSecondMoment() { return analyzerResult.getSecondMoment(col).doubleValue(); } @Override public double getSumsq() { return analyzerResult.getSumOfSquares(col).doubleValue(); } }; return stats; }
From source file:org.dishevelled.analysis.examples.GraphSummary.java
@Override public void run() { try {//from w w w. j a v a 2s . c om GraphMLReader<Long, Double> reader = new GraphMLReader<Long, Double>(xmlReader); reader.setNodeValueHandler(new LongElementHandler()); reader.setEdgeValueHandler(new DoubleElementHandler()); Graph<Long, Double> graph = graphFile == null ? reader.read(System.in) : reader.read(graphFile); System.out.println("nodes=" + graph.nodeCount()); System.out.println("edges=" + graph.edgeCount()); SummaryStatistics summary = new SummaryStatistics(); for (Node<Long, Double> node : graph.nodes()) { summary.addValue(node.degree()); } System.out.println("min degree=" + summary.getMin()); System.out.println("mean degree=" + summary.getMean() + " +/- " + summary.getStandardDeviation()); System.out.println("max degree=" + summary.getMax()); summary.clear(); Set<Set<Node<Long, Double>>> connectedComponents = GraphUtils.connectedComponents(graph); System.out.println("connected components=" + connectedComponents.size()); for (Set<Node<Long, Double>> connectedComponent : connectedComponents) { summary.addValue(connectedComponent.size()); } System.out.println("min connected component size=" + summary.getMin()); System.out.println("mean connected component size=" + summary.getMean() + " +/- " + summary.getStandardDeviation()); System.out.println("max connected component size=" + summary.getMax()); } catch (IOException e) { e.printStackTrace(); } }
From source file:org.dishevelled.timer.Timer.java
/** * Create a new timer. */ public Timer() { summaryStatistics = new SummaryStatistics(); started = false; }
From source file:org.janusgraph.graphdb.JanusGraphPerformanceMemoryTest.java
@Test public void testMemoryLeakage() { long memoryBaseline = 0; SummaryStatistics stats = new SummaryStatistics(); int numRuns = 25; for (int r = 0; r < numRuns; r++) { if (r == 1 || r == (numRuns - 1)) { memoryBaseline = MemoryAssess.getMemoryUse(); stats.addValue(memoryBaseline); //System.out.println("Memory before run "+(r+1)+": " + memoryBaseline / 1024 + " KB"); }//from w ww . j ava 2s. co m for (int t = 0; t < 1000; t++) { graph.addVertex(); graph.tx().rollback(); JanusGraphTransaction tx = graph.newTransaction(); tx.addVertex(); tx.rollback(); } if (r == 1 || r == (numRuns - 1)) { memoryBaseline = MemoryAssess.getMemoryUse(); stats.addValue(memoryBaseline); //System.out.println("Memory after run " + (r + 1) + ": " + memoryBaseline / 1024 + " KB"); } clopen(); } System.out.println("Average: " + stats.getMean() + " Std. Dev: " + stats.getStandardDeviation()); assertTrue(stats.getStandardDeviation() < stats.getMin()); }
From source file:org.janusgraph.TestByteBuffer.java
public static void main(String[] args) { SummaryStatistics statObject = new SummaryStatistics(); SummaryStatistics statByte = new SummaryStatistics(); for (int i = 0; i < 10; i++) { statByte.addValue(testByte());/* w w w. jav a 2 s . co m*/ statObject.addValue(testObject()); } System.out.println("Time (ms) Object: " + statObject.getMean() + " | " + statObject.getStandardDeviation()); System.out.println("Time (ms) Byte: " + statByte.getMean() + " | " + statByte.getStandardDeviation()); }