@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");
     }
     for (int t = 0; t < 1000; t++) {
       graph.addVertex(null);
       graph.rollback();
       TitanTransaction 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());
 }
Exemplo n.º 2
0
 @Override
 public double[] getResult() {
   double[] result = new double[3];
   result[0] = overallRes / overallQueries;
   result[1] = sumStats.getStandardDeviation();
   result[2] = sumStats.getVariance();
   return result;
 }
Exemplo n.º 3
0
  public static void main(String[] args) {
    Ordering ordering = new Ordering();
    ordering.prepare("ww3d", SequenceType.allen);

    SummaryStatistics ss = new SummaryStatistics();
    for (int i = 0; i < 100; ++i) {
      double value = ordering.experiment(SequenceType.allen, true);
      //			double value = ordering.orderingExperiment("ww3d", SequenceType.allen, true);
      System.out.println("..." + value);
      ss.addValue(value);
    }
    System.out.println("Summary " + ss.getMean() + " -- " + ss.getStandardDeviation());
  }
Exemplo n.º 4
0
  /**
   * Generates a random value from this distribution.
   *
   * @return the random value.
   * @throws IllegalStateException if the distribution has not been loaded
   */
  public double getNextValue() throws IllegalStateException {

    if (!loaded) {
      throw MathRuntimeException.createIllegalStateException("distribution not loaded");
    }

    // Start with a uniformly distributed random number in (0,1)
    double x = Math.random();

    // Use this to select the bin and generate a Gaussian within the bin
    for (int i = 0; i < binCount; i++) {
      if (x <= upperBounds[i]) {
        SummaryStatistics stats = binStats.get(i);
        if (stats.getN() > 0) {
          if (stats.getStandardDeviation() > 0) { // more than one obs
            return randomData.nextGaussian(stats.getMean(), stats.getStandardDeviation());
          } else {
            return stats.getMean(); // only one obs in bin
          }
        }
      }
    }
    throw new MathRuntimeException("no bin selected");
  }
  private GeoSegment getQQLineSegment() {

    SummaryStatistics stats = new SummaryStatistics();
    for (int i = 0; i < sortedData.length; i++) {
      stats.addValue(sortedData[i]);
    }
    double sd = stats.getStandardDeviation();
    double mean = stats.getMean();
    double min = stats.getMin();
    double max = stats.getMax();

    // qq line: y = (1/sd)x - mean/sd

    GeoPoint startPoint = new GeoPoint(cons);
    startPoint.setCoords(min, (min / sd) - mean / sd, 1.0);
    GeoPoint endPoint = new GeoPoint(cons);
    endPoint.setCoords(max, (max / sd) - mean / sd, 1.0);
    GeoSegment seg = new GeoSegment(cons, startPoint, endPoint);
    seg.calcLength();

    return seg;
  }
Exemplo n.º 6
0
  /** Iterate through the graph, calculating rank. */
  protected void iterateGraph(final int max_iterations) {
    final double[] rankList = new double[nodeList.length];

    // either run through N iterations, or until the standard
    // error converges below a threshold
    for (int k = 0; k < max_iterations; k++) {
      distStats.clear();

      // calculate the next rank for each node
      for (int i = 0; i < nodeList.length; i++) {
        final Node n1 = nodeList[i];
        double rank = 0.0D;

        for (Node n2 : n1.edges) {
          rank += n2.rank / (double) n2.edges.size();
        }

        rank *= TEXTRANK_DAMPING_FACTOR;
        rank += 1.0D - TEXTRANK_DAMPING_FACTOR;

        rankList[i] = rank;
        distStats.addValue(Math.abs(n1.rank - rank));
        // System.out.println("node : " + n1.key + " rank : " + Math.abs((n1.rank - rank)));
      }

      final double standard_error =
          distStats.getStandardDeviation() / Math.sqrt((double) distStats.getN());

      // swap in new rank values
      for (int i = 0; i < nodeList.length; i++) {
        nodeList[i].rank = rankList[i];
      }

      if (standard_error < STANDARD_ERROR_THRESHOLD) {
        break;
      }
    }
  }
Exemplo n.º 7
0
  /**
   * Calculates the rank weighting scores for all the nodes in the graph. Iterative calculates over
   * the graph until convergence at the standard error threshold or until max iterations.
   *
   * @param maxIterations Max number of iterations allowed for calculating rank scores
   * @param language Language of the text to calculate rank weighting scores for Available
   *     languages: Icelandic and English
   */
  public void weigthingScore(int maxIterations, Language language) {

    LinkedList<Node> nodes = new LinkedList<Node>();

    // Add nodes to LinkedList, we need them to stay in order
    for (int i = 0; i < nodeList.length; i++) {
      nodes.add(nodeList[i]);
    }

    /*

    WS(Vi) = ( 1 - d) + d * Sum(VjIn)  ________Wij________ * WS(Vj)
    									  Sum(Vk outVj) Wjk

    */
    for (int k = 0; k < maxIterations; k++) {
      distStats.clear();

      // Use dynamic programming to calculate the scores
      double previousWSScore[] = new double[nodes.size()];

      // Read in scores already calculated for nodes
      for (Node s : nodeList) {
        previousWSScore[nodes.indexOf(s)] = s.rank;
      }

      // For all nodes in the graph
      for (Node sentence_i : nodes) {
        double resultSumVji = 0;

        // For all in-coming edges of Vi
        for (Node sentence_j : sentence_i.edgesIN) {

          // Do not compare a sentence to it self, we do not allow self voting here
          if (!sentence_j.value.text.equalsIgnoreCase(sentence_i.value.text)) {

            // Calculate the sum of all similarity measurements
            // from all Vj nodes with outgoing edges to Vk nodes, see Wjk in equation
            double sumWjk = getSumWjk(sentence_j, language);

            if (sumWjk != 0) {
              double Wji = 0.0;
              if (language.equals(Language.ICELANDIC)) {
                // Calculate Wij, similarity between two sentences
                Wji = sentence_i.similarity(sentence_j);

              } else if (language.equals(Language.ENGLISH)) {
                // Calculate Wij, similarity between two sentences
                Wji = sentence_i.similarityEN(sentence_j);
              }
              // Get the score for the previous node
              double WSVj = previousWSScore[nodes.indexOf(sentence_j)];

              // Sum all (j in Vj)
              resultSumVji += ((Wji / sumWjk) * WSVj);
            }
          }
        }
        // Calculate weighting score WS(Vi)
        double WSVi = (1.0 - TEXTRANK_DAMPING_FACTOR) + TEXTRANK_DAMPING_FACTOR * resultSumVji;
        distStats.addValue(Math.abs(sentence_i.rank - WSVi));
        sentence_i.rank = WSVi;
      }
      // Calculate the Standard Error of the Mean
      final double standard_error =
          distStats.getStandardDeviation() / Math.sqrt((double) distStats.getN());

      // if std error of the mean is less than threshold
      // the graph has converged and we break
      if (standard_error < STANDARD_ERROR_THRESHOLD) {
        break;
      }
    }
  }
Exemplo n.º 8
0
 /** Calculate a threshold for the ranked results. */
 public double getRankThreshold() {
   return distStats.getMean() + (distStats.getStandardDeviation() * INCLUSIVE_COEFF);
 }