private boolean applyBeforeUpdateUndirected(Update u) {
    if (u instanceof NodeAddition) {
      Node n = (Node) ((NodeAddition) u).getNode();
      this.localCC.setValue(n.getIndex(), 0);
      this.nodePotentialCount =
          ArrayUtils.set(this.nodePotentialCount, n.getIndex(), 0, Long.MIN_VALUE);
      this.nodeTriangleCount =
          ArrayUtils.set(this.nodeTriangleCount, n.getIndex(), 0, Long.MIN_VALUE);
      this.averageCC = ArrayUtils.avgIgnoreNaN(this.localCC.getValues());
    } else if (u instanceof NodeRemoval) {
      UndirectedNode n = (UndirectedNode) ((NodeRemoval) u).getNode();

      UndirectedNode[] neighbors = new UndirectedNode[n.getDegree()];
      int index = 0;
      for (IElement eUncasted : n.getEdges()) {
        UndirectedEdge e = (UndirectedEdge) eUncasted;
        neighbors[index++] = e.getDifferingNode(n);
      }

      for (int i = 0; i < neighbors.length; i++) {
        for (int j = i + 1; j < neighbors.length; j++) {
          if (neighbors[i].hasEdge(new UndirectedEdge(neighbors[i], neighbors[j]))) {
            this.removeTriangle(n);
            this.removeTriangle(neighbors[i]);
            this.removeTriangle(neighbors[j]);
          }
        }
        this.removePotentials(neighbors[i], neighbors[i].getDegree() - 1);
      }

      this.removePotentials(n, n.getDegree() * (n.getDegree() - 1) / 2);

      this.localCC.setValue(n.getIndex(), NodeValueList.emptyValue);
      this.nodePotentialCount[n.getIndex()] = Long.MIN_VALUE;
      this.nodeTriangleCount[n.getIndex()] = Long.MIN_VALUE;
      this.localCC.truncate();
      this.nodePotentialCount = ArrayUtils.truncate(this.nodePotentialCount, Long.MIN_VALUE);
      this.nodeTriangleCount = ArrayUtils.truncate(this.nodeTriangleCount, Long.MIN_VALUE);
    } else if (u instanceof EdgeAddition) {
      UndirectedEdge e = (UndirectedEdge) ((EdgeAddition) u).getEdge();
      UndirectedNode a = e.getNode1();
      UndirectedNode b = e.getNode2();
      // new triangles
      for (IElement c_Uncasted : a.getEdges()) {
        UndirectedEdge c_ = (UndirectedEdge) c_Uncasted;
        UndirectedNode c = c_.getDifferingNode(a);
        if (c.hasEdge(new UndirectedEdge(c, b))) {
          this.addTriangle(a);
          this.addTriangle(b);
          this.addTriangle(c);
        }
      }
      // new potentials
      this.addPotentials(a, a.getDegree());
      this.addPotentials(b, b.getDegree());
    }
    return true;
  }
Esempio n. 2
0
  /**
   * Computes the average value of a list of values.
   *
   * @param list list of values to compute the average of.
   * @param name name for the computed value
   * @return average value of the given list of values.
   */
  public static Value average(Value[] list, String name) {
    double[] values = new double[list.length];

    for (int i = 0; i < list.length; i++) {
      values[i] = list[i].getValue();
    }

    return new Value(name, ArrayUtils.avg(values));
  }
Esempio n. 3
0
  /**
   * Calculates the maximum of Value objects of a list of Values objects.
   *
   * @param list list of Values object to compute the maximum for
   * @param name name of the new Values object
   * @return maximum Values object of the given list
   * @throws AggregationException
   */
  public static Values maximum(Values[] list, String name) throws AggregationException {
    Aggregation.test(list);

    double[][] values = new double[list[0].getValues().length][2];
    for (int i = 0; i < values.length; i++) {
      values[i][0] = list[0].getValues()[i][0];
      double[] temp = new double[list.length];
      for (int j = 0; j < list.length; j++) {
        temp[j] = list[j].getValues()[i][1];
      }
      values[i][1] = ArrayUtils.max(temp);
    }
    return new Values(values, name);
  }
Esempio n. 4
0
  /**
   * Aggregates over the given inputData.
   *
   * @param inputData
   * @return double array containing the aggregated data
   */
  public static double[] aggregate(int[] inputData) {
    // aggregated array structure: { avg, min, max, median, variance,
    // variance-low, variance-up, confidence-low, confidence-up }
    double avg = ArrayUtils.avg(inputData);
    double[] varLowUp = ArrayUtils.varLowUp(inputData, avg);
    double[] conf = ArrayUtils.conf(inputData);
    double[] temp = {
      avg,
      ArrayUtils.min(inputData),
      ArrayUtils.max(inputData),
      ArrayUtils.med(inputData),
      varLowUp[0],
      varLowUp[1],
      varLowUp[2],
      conf[0],
      conf[1]
    };

    return temp;
  }
  private boolean applyBeforeUpdateDirected(Update u) {
    if (u instanceof NodeAddition) {
      Node n = (Node) ((NodeAddition) u).getNode();
      this.localCC.setValue(n.getIndex(), 0);
      this.nodePotentialCount =
          ArrayUtils.set(this.nodePotentialCount, n.getIndex(), 0, Long.MIN_VALUE);
      this.nodeTriangleCount =
          ArrayUtils.set(this.nodeTriangleCount, n.getIndex(), 0, Long.MIN_VALUE);
      this.averageCC = ArrayUtils.avgIgnoreNaN(this.localCC.getValues());
    } else if (u instanceof NodeRemoval) {

      DirectedNode n = (DirectedNode) ((NodeRemoval) u).getNode();

      DirectedNode[] neighbors = new DirectedNode[n.getNeighborCount()];
      int index = 0;
      for (IElement neighbor : n.getNeighbors()) {
        neighbors[index++] = (DirectedNode) neighbor;
      }

      for (int i = 0; i < neighbors.length; i++) {
        for (int j = i + 1; j < neighbors.length; j++) {
          if (neighbors[i].hasEdge(new DirectedEdge(neighbors[i], neighbors[j]))
              && neighbors[i].hasEdge(new DirectedEdge(neighbors[j], neighbors[i]))) {
            this.removeTriangle(n);
            this.removeTriangle(neighbors[i]);
            this.removeTriangle(neighbors[j]);
          }
        }
        this.removePotentials(neighbors[i], neighbors[i].getNeighborCount() - 1);
      }

      this.removePotentials(n, n.getNeighborCount() * (n.getNeighborCount() - 1) / 2);

      this.localCC.setValue(n.getIndex(), NodeValueList.emptyValue);
      this.nodePotentialCount[n.getIndex()] = Long.MIN_VALUE;
      this.nodeTriangleCount[n.getIndex()] = Long.MIN_VALUE;
      this.localCC.truncate();
      this.nodePotentialCount = ArrayUtils.truncate(this.nodePotentialCount, Long.MIN_VALUE);
      this.nodeTriangleCount = ArrayUtils.truncate(this.nodeTriangleCount, Long.MIN_VALUE);

      this.averageCC = ArrayUtils.avgIgnoreNaN(this.localCC.getValues());

    } else if (u instanceof EdgeAddition) {
      DirectedEdge e = (DirectedEdge) ((EdgeAddition) u).getEdge();
      DirectedNode a = e.getSrc();
      DirectedNode b = e.getDst();
      if (a.hasEdge(new DirectedEdge(b, a))) {
        // new triangles
        for (IElement cUncasted : a.getNeighbors()) {
          DirectedNode c = (DirectedNode) cUncasted;
          if (b.hasNeighbor(c)) {
            this.addTriangle(a);
            this.addTriangle(b);
            this.addTriangle(c);
          }
        }
        // new potentials
        this.addPotentials(a, a.getNeighborCount());
        this.addPotentials(b, b.getNeighborCount());
      }
    }
    return true;
  }