コード例 #1
0
ファイル: MMBean2.java プロジェクト: vivekvenkris/Gravatar
  public void findIntersections2(PKBean refPKBean, Double refSigma, Double minSigma)
      throws InvalidBoundsException {
    Double startX = null;
    Double endX = null;
    XYPair positiveStartPair = null;
    XYPair negativeStartPair = null;
    XYPair positiveEndPair = null;
    XYPair negativeEndPair = null;
    boolean insideMinSigma = false;
    boolean signChanged = false;
    List<XYPair> positiveRefCurve = refPKBean.getCurveForSigma(refSigma);
    List<XYPair> negativeRefCurve = refPKBean.getCurveForSigma(-refSigma);
    if (positiveRefCurve.size() > 0)
      for (int i = 1; i < positiveRefCurve.size(); i++) {
        XYPair positivePt = positiveRefCurve.get(i);
        XYPair negativePt = negativeRefCurve.get(i);

        XYPair positivePtPrev = positiveRefCurve.get(i - 1);
        XYPair negativePtPrev = negativeRefCurve.get(i - 1);

        double positiveMaxSigma = getMaxSigma(positivePt);
        double negativeMaxSigma = getMaxSigma(negativePt);

        double positiveMaxSigmaPrev = getMaxSigma(positivePtPrev);
        double negativeMaxSigmaPrev = getMaxSigma(negativePtPrev);
        if ((positiveMaxSigmaPrev <= 0 && positiveMaxSigma >= 0
            || positiveMaxSigmaPrev >= 0 && positiveMaxSigma <= 0
            || negativeMaxSigmaPrev <= 0 && negativeMaxSigma >= 0
            || negativeMaxSigmaPrev >= 0 && negativeMaxSigma <= 0)) {
          signChanged = true;
          /* sign of sigma changes but no point is within minsigma*/
          if (startX == null) {
            startX = Math.min(positivePtPrev.getX(), negativePtPrev.getX());
            positiveStartPair = positivePtPrev;
            negativeStartPair = negativePtPrev;
          }

          endX = Math.min(positivePt.getX(), negativePt.getX());
          positiveEndPair = positivePt;
          negativeEndPair = negativePt;

          Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
          PKBean subRefPKBean =
              new PKBean(leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);

          System.err.println(
              "sign changed:"
                  + positiveMaxSigma
                  + " "
                  + +positiveMaxSigmaPrev
                  + " "
                  + positiveMaxSigma
                  + " "
                  + negativeMaxSigmaPrev
                  + " minSigma: "
                  + minSigma);
          findIntersections(subRefPKBean, refSigma, minSigma);
          startX = null;
        }

        System.err.println(
            "positiveMaxSigma: "
                + positiveMaxSigma
                + " negativeMaxSigma: "
                + negativeMaxSigma
                + " minSigma: "
                + minSigma);
        if ((Math.abs(positiveMaxSigma) < minSigma || Math.abs(negativeMaxSigma) < minSigma)) {
          insideMinSigma = true;
          if (startX == null) {
            startX = Math.min(positivePtPrev.getX(), negativePtPrev.getX());
            positiveStartPair = positivePtPrev;
            negativeStartPair = negativePtPrev;
            System.err.println(
                "Selected start"
                    + " positiveMaxSigma: "
                    + positiveMaxSigmaPrev
                    + " negativeMaxSigma: "
                    + negativeMaxSigmaPrev
                    + " minSigma: "
                    + minSigma);
          }

        } else {
          if (startX != null && insideMinSigma) {
            insideMinSigma = false;
            endX = Math.min(positivePt.getX(), negativePt.getX());
            System.err.println(
                "Selected end"
                    + " positiveMaxSigma: "
                    + positiveMaxSigma
                    + " negativeMaxSigma: "
                    + negativeMaxSigma
                    + " minSigma: "
                    + minSigma);
            positiveEndPair = positivePt;
            negativeEndPair = negativePt;
            if (minSigma > 1) {
              System.err.println(
                  "minSigma:" + minSigma + " " + Math.abs((startX - endX) / inp.numPts));
              if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
                Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);

                findIntersections(subRefPKBean, refSigma, minSigma - 1);
                startX = null;
              } else {
                Bounds bounds =
                    new Bounds(
                        startX,
                        endX,
                        Math.round((float) (Math.abs((startX - endX)) / epsilon)),
                        false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
                findIntersections(subRefPKBean, refSigma, 1.0);
                startX = null;
              }
            } else {
              if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
                Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
                PKBean subRefPKBean =
                    new PKBean(
                        leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
                findIntersections(subRefPKBean, refSigma, 1.0);
                startX = null;

              } else {
                Polygon polygon = new Polygon();
                polygon
                    .getPoints()
                    .addAll(
                        new Double[] {
                          positiveStartPair.getX(), positiveStartPair.getY(),
                          positiveEndPair.getX(), positiveEndPair.getY(),
                          negativeStartPair.getX(), negativeStartPair.getY(),
                          negativeEndPair.getX(), negativeEndPair.getY()
                        });
                intersectionList.add(polygon);
              }
            }
          }
        }
      }
  }
コード例 #2
0
ファイル: MMBean2.java プロジェクト: vivekvenkris/Gravatar
  public void findIntersections(PKBean refPKBean, Double refSigma, Double minSigma)
      throws InvalidBoundsException {
    Double startX = null;
    Double endX = null;

    List<XYPair> posRef = refPKBean.getCurveForSigma(refSigma);
    List<XYPair> negRef = refPKBean.getCurveForSigma(-refSigma);

    List<Double> posMaxSig = new ArrayList<Double>();
    List<Double> negMaxSig = new ArrayList<Double>();

    for (int i = 0; i < posRef.size(); i++) {
      posMaxSig.add(getMaxSigma(posRef.get(i)));
      negMaxSig.add(getMaxSigma(negRef.get(i)));
    }

    if (posRef.size() > 0 && negRef.size() > 0 && posRef.size() == negRef.size()) {
      for (int i = 1; i < posRef.size() - 1; i++) {
        XYPair posNow = posRef.get(i);
        XYPair negNow = negRef.get(i);

        double posMaxSigNow = posMaxSig.get(i);
        double negMaxSigNow = negMaxSig.get(i);

        XYPair posNext = posRef.get(i + 1);
        XYPair negNext = negRef.get(i + 1);

        double posMaxSigNext = posMaxSig.get(i + 1);
        double negMaxSigNext = negMaxSig.get(i + 1);

        XYPair posPrev = posRef.get(i - 1);
        XYPair negPrev = negRef.get(i - 1);

        double posMaxSigPrev = posMaxSig.get(i - 1);
        double negMaxSigPrev = negMaxSig.get(i - 1);

        // find if the difference changes sign meaning the intersecting curve is changing course.
        // System.err.println(posPrev + " "+ posNow+ " "+posNext + " "+posMaxSigPrev + "
        // "+posMaxSigNow + " "+posMaxSigNext + " "
        // +Math.signum(posMaxSigPrev-posMaxSigNow)+ " "+Math.signum(posMaxSigNow-posMaxSigNext));
        if ((Math.signum(posMaxSigPrev - posMaxSigNow) != Math.signum(posMaxSigNow - posMaxSigNext))
            || (Math.signum(negMaxSigPrev - negMaxSigNow)
                != Math.signum(negMaxSigNow - negMaxSigNext))) {

          startX = Math.min(posPrev.getX(), negPrev.getX());
          endX = Math.min(posNext.getX(), negNext.getX());
          // System.err.println("Turns! "+posMaxSigPrev + " "+posMaxSigNow + " "+posMaxSigNext + "
          // "+startX+" "+endX + " " +Math.abs((startX-endX)/inp.numPts));

          if (Math.abs((startX - endX) / inp.numPts) > epsilon) {
            Bounds bounds = new Bounds(startX, endX, inp.getNumPts(), false);
            PKBean subRefPKBean =
                new PKBean(leastErrorPKName, refPKBean.getValue(), refPKBean.getError(), bounds);
            findIntersections(subRefPKBean, refSigma, minSigma);
            // System.err.println("came out"+ startX+ " " + endX);
          } else {
            if (posMaxSigNow < 1 || negMaxSigNow < 1) {
              Polygon polygon = new Polygon();
              polygon
                  .getPoints()
                  .addAll(
                      new Double[] {
                        posPrev.getX(), posPrev.getY(),
                        posNext.getX(), posNext.getY(),
                        negPrev.getX(), negPrev.getY(),
                        negNext.getX(), negNext.getY()
                      });
              // System.err.println("Polygon" + polygon.getPoints());
              intersectionList.add(polygon);
            } else {
              System.err.println(posMaxSigNow + " " + negMaxSigNow);
            }
          }
        }
        /* find if the individual sigma changes sign*/
        //				else if( (Math.signum(posMaxSigPrev)==Math.signum(posMaxSigNow)) ||
        // (Math.signum(negMaxSigPrev)==Math.signum(negMaxSigNow)) ){
        //
        //				}

      }
    }
  }