コード例 #1
0
  /**
   * Transform:
   *
   * <p>MDs Values<br>
   * (0, 1)<br>
   * (10, 1)<br>
   * (15, 2)<br>
   * (20, 3)<br>
   * (30, 3)<br>
   * (50, 3)<br>
   *
   * <p>to
   *
   * <p>([0, 15], 1)<br>
   * ([15, 20], 2)<br>
   * ([20, 50], 3)
   */
  public static IntervalFilteredHolder filter(
      final double[][] intervals, final int begin, final int length) {
    int size = length;
    int start = begin + size;
    int endIndex = 0;

    // Look for the first value which is not a novalue
    for (int i = 0; i < size; i++) {
      if (NoValues.isDoubleNoValue(intervals[2][i]) == false) {
        start = i;
        break;
      }
    }

    // Only no values?
    if (start == size) {
      return new IntervalFilteredHolder(new double[3][0], 0, -1);
    }

    int end = 0;

    // Look for the last value which is not a novalue
    for (int i = size - 1; i >= 0; i--) {
      if (NoValues.isDoubleNoValue(intervals[2][i]) == false) {
        end = i;
        break;
      }
    }

    // Only one value?
    if (start == end) {
      endIndex = 0;
      intervals[0][endIndex] = intervals[0][start];
      intervals[1][endIndex] = intervals[1][start];
      intervals[2][endIndex] = intervals[2][start];
      return new IntervalFilteredHolder(intervals, 0, 0);
    }

    endIndex = -1;

    boolean out = false;
    int idx1 = start;
    int idx2 = start + 1;
    while (true) {
      while (idx2 <= end
          && NoValues.isDoubleNoValue(intervals[2][idx2]) == false
          && MathUtils.isApproximatelyEqual(intervals[2][idx1], intervals[2][idx2])) {
        idx2++;
      }
      if (idx2 > end) {
        out = true;
      }

      endIndex++;
      intervals[0][endIndex] = intervals[0][idx1];
      intervals[1][endIndex] = intervals[1][idx2 - 1];
      intervals[2][endIndex] = intervals[2][idx1];

      idx1 = idx2;

      // skip novalues
      while (idx1 <= end && NoValues.isDoubleNoValue(intervals[2][idx1]) == true) {
        idx1++;
      }

      idx2 = idx1 + 1;

      if (idx2 > end) {
        if (out == false) { // one more time
          endIndex++;
          intervals[0][endIndex] = intervals[0][idx1];
          intervals[1][endIndex] = intervals[1][idx2 - 1];
          intervals[2][endIndex] = intervals[2][idx1];
        }
        break;
      }
    }

    if (endIndex == -1) {
      return new IntervalFilteredHolder(new double[3][0], 0, -1);
    }

    return new IntervalFilteredHolder(intervals, 0, endIndex);
  }
コード例 #2
0
  /**
   * Transform:
   *
   * <p>([0,15], 100)<br>
   * ([15,20], 150)<br>
   * ([30,38], 200)<br>
   * ([40,50], 173)<br>
   *
   * <p>to
   *
   * <p>MDs Values<br>
   * 0 100<br>
   * 15 150<br>
   * 20 NonValeur<br>
   * 30 200<br>
   * 38 NonValeur<br>
   * 40 173<br>
   * 50 NonValeur<br>
   */
  public static double[][] buildSimpleArray(
      final double[] tops, double[] bottoms, double[]... vals) {
    int intervalCount = Math.min(tops.length, bottoms.length);
    for (int i = 0; i < vals.length; i++) {
      intervalCount = Math.min(intervalCount, vals[i].length);
    }
    int size = intervalCount * 2;

    double[] mds = new double[size];
    double[][] values = new double[vals.length][size];

    double prev = 0.0;

    int idx = 0;
    for (int i = 0; i < intervalCount; i++) {
      double top = tops[i];
      double bot = bottoms[i];

      if (i == 0) {
        mds[idx] = top;
        mds[idx + 1] = bot;
        for (int n = 0; n < vals.length; n++) {
          values[n][idx] = vals[n][i];
        }
        idx++;
        prev = bot;
        continue;
      }

      if (MathUtils.isApproximatelyEqual(top, prev) == false) {
        mds[idx] = prev;
        mds[idx + 1] = top;
        for (int j = 0; j < vals.length; j++) {
          values[j][idx] = NoValues.DOUBLE_NOVALUE;
        }
        idx++;
      }

      mds[idx] = top;
      mds[idx + 1] = bot;
      for (int n = 0; n < vals.length; n++) {
        values[n][idx] = vals[n][i];
      }
      idx++;

      prev = bot;
    }

    // Fill last one
    for (int n = 0; n < vals.length; n++) {
      values[n][idx] = NoValues.DOUBLE_NOVALUE;
    }

    // resize
    double[] newMds = ArrayUtils.subarray(mds, 0, idx + 1);
    double[][] newValues = new double[vals.length][];
    for (int j = 0; j < vals.length; j++) {
      newValues[j] = ArrayUtils.subarray(values[j], 0, idx + 1);
    }

    double[][] results = new double[vals.length + 1][];
    results[0] = newMds;
    for (int n = 1; n < results.length; n++) {
      results[n] = newValues[n - 1];
    }

    return results;
  }