예제 #1
1
  /**
   * Calculates equation 1 variables
   *
   * @param d
   * @param v0
   * @param t
   * @param a
   * @param varNum
   * @return res
   */
  private static String calc1(double d, double v0, double t, double a, int varNum) {
    double res = 0;

    // Solve for appropriate variable
    if (varNum == 1) {
      res = v0 * t + .5 * a * Math.pow(t, 2);
      units = "meters";
    } else if (varNum == 2) {
      res = (d / t) - (.5 * a * t);
      units = "m/s";
    } else if (varNum == 3) {
      double quadA =
          ((-1 * v0) + Math.sqrt(Math.pow(v0, 2) - (4 * .5 * a * (-1 * d)))) / (2 * .5 * a);
      double quadB =
          ((-1 * v0) - Math.sqrt(Math.pow(v0, 2) - (4 * .5 * a * (-1 * d)))) / (2 * .5 * a);

      if (quadA >= 0) res = quadA;
      else res = quadB;
      units = "seconds";
    } else if (varNum == 4) {
      res = ((d / t) - v0) / .5 * t;
      units = "m/s^2";
    }

    return df.format(res);
  }
예제 #2
0
 @Test
 public void GetUnitVectorInSameDirectionTest_LegalCase() {
   Vector v = new Vector(Math.sqrt(2) / 2, Math.sqrt(2) / 2);
   Vector result = testVector1.getUnitVectorInDirection();
   assertTrue(Util.fuzzyEquals(v._X(), result._X()));
   assertTrue(Util.fuzzyEquals(v._Y(), result._Y()));
 }
예제 #3
0
 @Override
 public void reduce(
     Text moviePair, Iterator<Text> ratings, OutputCollector<Text, Text> output, Reporter reporter)
     throws IOException {
   ArrayList<Double> ratings1 = new ArrayList<Double>();
   ArrayList<Double> ratings2 = new ArrayList<Double>();
   double numRatings = 0;
   double totRating1 = 0, totrating2 = 0;
   while (ratings.hasNext()) {
     String[] rating = ratings.next().toString().split(",");
     ratings1.add(Double.parseDouble(rating[0]));
     ratings2.add(Double.parseDouble(rating[1]));
     totRating1 += Double.parseDouble(rating[0]);
     totrating2 += Double.parseDouble(rating[1]);
     numRatings += 1;
   }
   double avgRating1 = totRating1 / numRatings;
   double avgRating2 = totrating2 / numRatings;
   double sum1 = 0.0, sum2 = 0.0, sumProduct = 0.0;
   for (int i = 0; i < numRatings; i++) {
     sum1 += Math.pow((ratings1.get(i) - avgRating1), 2);
     sum2 += Math.pow((ratings2.get(i) - avgRating2), 2);
     sumProduct += (ratings1.get(i) - avgRating1) * (ratings2.get(i) - avgRating2);
   }
   double corr = sumProduct / (Math.sqrt(sum1) * Math.sqrt(sum2));
   System.out.println(sum1 + "," + sum2 + "," + sumProduct + "," + corr);
   if (Double.isNaN(corr)) {
     corr = 0;
   }
   output.collect(moviePair, new Text(corr + ""));
 }
예제 #4
0
  private double modelLevyAsian(double S, double K, double r, double div, double sig, double T) {
    double valueLevy = 0.0;
    double se = 0.0;
    double m = 0.0;
    double d = 0.0;
    double sv = 0.0;
    double xStar = 0.0;
    double d1, d2 = 0.0;
    double b = r - div; // cost of carry rate
    double t2 = T; // remaining time to maturity
    double sa = S; // Arithmetic Average price

    se = S / (T * b) * (Math.exp((b - r) * t2) - Math.exp(-r * t2));

    m =
        2
            * Math.pow(S, 2)
            / (b + Math.pow(sig, 2))
            * ((Math.exp((2 * b + Math.pow(sig, 2)) * t2) - 1) / (2 * b + Math.pow(sig, 2))
                - (Math.exp(b * t2) - 1) / b);
    d = m / Math.pow(T, 2);
    sv = Math.log(d) - 2 * (r * t2 + Math.log(se));
    xStar = K - ((T - t2) / T) * sa;
    d1 = 1 / Math.sqrt(sv) * (Math.log(d) / 2 - Math.log(xStar));
    d2 = d1 - Math.sqrt(sv);

    valueLevy = se * CND(d1) - xStar * Math.exp(-r * t2) * CND(d2);
    return valueLevy;
  }
예제 #5
0
  private static void getRectangleSidesWithSquareAndPerimeter(
      Rectangle rectangle, double perimeter, double square) {
    double x;
    double y;
    double discriminant;

    double halfPerimeter = perimeter / 2;

    discriminant = (Math.pow(halfPerimeter, 2)) - (4 * 1 * square);

    if (discriminant > 0) {

      x = (halfPerimeter - Math.sqrt(discriminant)) / 2;
      rectangle.sideA = x;

      y = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideB = y;

    } else if (discriminant == 0) {

      x = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideA = x;

      y = (halfPerimeter + Math.sqrt(discriminant)) / 2;
      rectangle.sideB = y;

    } else {

      System.out.println("Maybe wrong data entered!");
    }
  }
예제 #6
0
 static void initBiasLFM(
     List<ArrayList<Double>> matrix,
     List<Double> biList,
     List<Double> bfList,
     List<ArrayList<Double>> pMatrix,
     List<ArrayList<Double>> qMatrix,
     int F) {
   for (int i = 0; i < matrix.size(); i++) {
     biList.add(0.0);
   }
   for (int j = 0; j < matrix.get(0).size(); j++) {
     bfList.add(0.0);
   }
   for (int i = 0; i < matrix.size(); i++) {
     ArrayList<Double> tempList = new ArrayList<Double>();
     for (int f = 0; f < F; f++) {
       tempList.add((double) (Math.random() / Math.sqrt((double) F)));
     }
     pMatrix.add(tempList);
   }
   for (int j = 0; j < matrix.get(0).size(); j++) {
     ArrayList<Double> tempList = new ArrayList<Double>();
     for (int f = 0; f < F; f++) {
       tempList.add((double) (Math.random() / Math.sqrt((double) F)));
     }
     qMatrix.add(tempList);
   }
 }
  /**
   * Apply the optimized MelCosine filter used in pocketsphinx to the given melspectrum.
   *
   * @param melspectrum the MelSpectrum data
   * @return MelCepstrum data produced by apply the MelCosine filter to the MelSpectrum data
   */
  @Override
  protected double[] applyMelCosine(double[] melspectrum) {

    // create the cepstrum
    double[] cepstrum = new double[cepstrumSize];
    double sqrt_inv_n = Math.sqrt(1.0 / numberMelFilters);
    double sqrt_inv_2n = Math.sqrt(2.0 / numberMelFilters);

    cepstrum[0] = melspectrum[0];
    for (int j = 1; j < numberMelFilters; j++) {
      cepstrum[0] += melspectrum[j];
    }

    cepstrum[0] *= sqrt_inv_n;

    if (numberMelFilters <= 0) {
      return cepstrum;
    }

    for (int i = 1; i < cepstrum.length; i++) {
      double[] melcosine_i = melcosine[i];
      int j = 0;
      cepstrum[i] = 0;
      for (j = 0; j < numberMelFilters; j++) {
        cepstrum[i] += (melspectrum[j] * melcosine_i[j]);
      }
      cepstrum[i] *= sqrt_inv_2n;
    }
    return cepstrum;
  }
예제 #8
0
  /** Return baselineparameters */
  private static void compute_B_Bpar_Bperp_Theta(
      BaselineComponents BBparBperptheta,
      final Point point,
      final Point master,
      final Point slave) {

    logger.trace("BBparBperpTheta method");
    BBparBperptheta.b =
        master.distance(slave); // baseline. abs. value (in plane master,point,slave)
    final double range1 = master.distance(point);
    final double range2 = slave.distance(point);
    BBparBperptheta.bpar = range1 - range2; // parallel baseline, sign ok
    final Point r1 = master.min(point); // points from P to M
    final Point r2 = slave.min(point);
    BBparBperptheta.theta = master.angle(r1); // viewing angle
    BBparBperptheta.bperp = sqr(BBparBperptheta.b) - sqr(BBparBperptheta.bpar);

    // check for the sign of Bperp
    if (BBparBperptheta.bperp < 0.0) {
      BBparBperptheta.bperp = 0.0;
    } else if (BBparBperptheta.theta > master.angle(r2)) { // perpendicular baseline, sign ok
      BBparBperptheta.bperp = Math.sqrt(BBparBperptheta.bperp);
    } else {
      BBparBperptheta.bperp = -Math.sqrt(BBparBperptheta.bperp);
    }
  }
예제 #9
0
  public void EMpar(Database db, double prior) {
    int j, np;
    double x, y, tmp, tmpx, tmpy, tmpsx, tmpsy, tmpsxy;

    np = db.nPoints();
    tmpsx = tmpsy = tmpsxy = kmx = kmy = 0;
    for (j = 0; j < np; j++) {
      x = db.xVal(j);
      y = db.yVal(j);
      kmx += probs[j] * x;
      kmy += probs[j] * y;
      tmpsx += probs[j] * x * x;
      tmpsy += probs[j] * y * y;
      tmpsxy += probs[j] * x * y;
    }
    tmp = np * weight;
    kmx /= tmp;
    kmy /= tmp;
    ksx = Math.sqrt(tmpsx / tmp - kmx * kmx);
    ksy = Math.sqrt(tmpsy / tmp - kmy * kmy);
    ksxy = tmpsxy / tmp - kmx * kmy;
    if (ksx < mins) ksx = mins;
    if (ksy < mins) ksy = mins;
    weight = 0.9 * weight + 0.1 * prior;
  }
예제 #10
0
 public void inputMovement(Point2D.Float acceleration) {
   oldPosition = this.getPosition();
   if (acceleration.x == 0 && acceleration.y == 0) {
     velocity.x *= slowDown;
     velocity.y *= slowDown;
   } else {
     float accelerationAbs =
         (float) Math.sqrt(acceleration.x * acceleration.x + acceleration.y * acceleration.y);
     velocity.x += acceleration.x * accelerationScale / accelerationAbs;
     velocity.y += acceleration.y * accelerationScale / accelerationAbs;
     float speed = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
     if (speed > maxSpeed) {
       velocity.x = velocity.x * maxSpeed / speed;
       velocity.y = velocity.y * maxSpeed / speed;
     }
   }
   if (collision == null) {
   } else {
     // revert the position and bounce a little bit
     position.x += (position.x - collision.x) / 2;
     position.y += (position.y - collision.y) / 2;
     Point2D.Float proj = new Point2D.Float();
     float collisionDirection = getRadiansTo(collision);
     float movementDirection = (float) Math.atan2(velocity.y, velocity.x);
     float angleBetween = movementDirection - collisionDirection;
     float velocityAbs = (float) Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y);
     float cosAB = (float) Math.cos(angleBetween); // angle between
     velocity.x -= velocityAbs * cosAB * (float) Math.cos(collisionDirection) * 1.1;
     velocity.y -= velocityAbs * cosAB * (float) Math.sin(collisionDirection) * 1.1;
     resetCollision();
   }
   incrementPosition(velocity.x, velocity.y);
 }
예제 #11
0
  private static void calculateRegressionCoefficients(
      double[] x, double meanx, double[] y, double meany, Result r, int d, int p) {
    double beta;
    double alpha;
    double sxx = 0;
    double sxy = 0;
    double b = 0;

    for (int i = 0; i < y.length; i++) {
      sxx += ((x[i] - meanx) * (x[i] - meanx));
      sxy += ((y[i] - meany) * (x[i] - meanx));
    }

    beta = sxy / sxx;
    alpha = meany - beta * meanx;

    double ssxy = 0;
    for (int i = 0; i < y.length; i++) {
      double yexp = alpha + (beta * x[i]);
      ssxy += ((y[i] - yexp) * (y[i] - yexp));
    }

    double se = (Math.sqrt((ssxy) / (y.length - 2))) / Math.sqrt(sxx);
    r.beta[d][p] = beta;
    r.se[d][p] = se;
  }
 public void initialize() {
   super.initialize();
   if (Math.abs(Math.abs(projectionLatitude) - MapMath.HALFPI) < EPS10) {
     mode = projectionLatitude < 0. ? SOUTH_POLE : NORTH_POLE;
     sinphi0 = projectionLatitude < 0. ? -1. : 1.;
     cosphi0 = 0.;
   } else if (Math.abs(projectionLatitude) < EPS10) {
     mode = EQUATOR;
     sinphi0 = 0.;
     cosphi0 = 1.;
   } else {
     mode = OBLIQUE;
     sinphi0 = Math.sin(projectionLatitude);
     cosphi0 = Math.cos(projectionLatitude);
   }
   if (!spherical) {
     en = MapMath.enfn(es);
     switch (mode) {
       case NORTH_POLE:
         Mp = MapMath.mlfn(MapMath.HALFPI, 1., 0., en);
         break;
       case SOUTH_POLE:
         Mp = MapMath.mlfn(-MapMath.HALFPI, -1., 0., en);
         break;
       case EQUATOR:
       case OBLIQUE:
         N1 = 1. / Math.sqrt(1. - es * sinphi0 * sinphi0);
         G = sinphi0 * (He = e / Math.sqrt(one_es));
         He *= cosphi0;
         break;
     }
   }
 }
예제 #13
0
  // Berechnung der Distanzen zwischen den Informationspunkten; Berechnung der Distanzen zwischen
  // den Informationspunkten und dem Interpolationspunkt
  public void calculateDistances() {

    numOfPoints = points.size();
    distanceData = new double[numOfPoints][numOfPoints];
    calcPointDistance = new double[numOfPoints];

    // Berechnung der Distanzen zwischen den Informationspunkten
    for (int i = 0; i < numOfPoints; i++) {
      for (int j = 0; j < numOfPoints; j++) {

        distanceData[i][j] =
            Math.sqrt(
                Math.pow(points.get(i).xCoordinate - points.get(j).xCoordinate, 2)
                    + Math.pow(points.get(i).yCoordinate - points.get(j).yCoordinate, 2));
      }
    }

    // Berechnung der Distanzen zwischen den Informationspunkten und dem Interpolationspunkt
    for (int i = 0; i < numOfPoints; i++) {
      calcPointDistance[i] =
          Math.sqrt(
              Math.pow(calcPoint.xCoordinate - points.get(i).xCoordinate, 2)
                  + Math.pow(calcPoint.yCoordinate - points.get(i).yCoordinate, 2));
    }
  }
예제 #14
0
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);

    int a, b, c;

    a = in.nextInt();
    b = in.nextInt();
    c = in.nextInt();

    int tmp;
    if (a < b) {
      tmp = a;
      a = b;
      b = tmp;
    }
    if (a < c) {
      tmp = a;
      a = c;
      c = tmp;
    }

    if (a >= b + c) {
      System.out.println("n");
    } else if (a == Math.sqrt(b * b + c * c)) {
      System.out.println("r");
    } else if (a > Math.sqrt(b * b + c * c)) {
      System.out.println("o");
    } else {
      System.out.println("a");
    }

    System.out.println();
  }
예제 #15
0
  /**
   * Uses the Haversine formula to calculate the distnace between to lat-long coordinates
   *
   * @param latitude1 The first point's latitude
   * @param longitude1 The first point's longitude
   * @param latitude2 The second point's latitude
   * @param longitude2 The second point's longitude
   * @return The distance between the two points in meters
   */
  public static double CalculateDistance(
      double latitude1, double longitude1, double latitude2, double longitude2) {
    /*
    Haversine formula:
    A = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
    C = 2.atan2(√a, √(1−a))
    D = R.c
    R = radius of earth, 6371 km.
    All angles are in radians
    */

    double deltaLatitude = Math.toRadians(Math.abs(latitude1 - latitude2));
    double deltaLongitude = Math.toRadians(Math.abs(longitude1 - longitude2));
    double latitude1Rad = Math.toRadians(latitude1);
    double latitude2Rad = Math.toRadians(latitude2);

    double a =
        Math.pow(Math.sin(deltaLatitude / 2), 2)
            + (Math.cos(latitude1Rad)
                * Math.cos(latitude2Rad)
                * Math.pow(Math.sin(deltaLongitude / 2), 2));

    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    return 6371 * c * 1000; // Distance in meters
  }
예제 #16
0
파일: Vec2.java 프로젝트: Sangheli/NeuroBot
  public static double getAngleToTarget(BaseModel t1, BaseModel t2) {
    Vec2 forVec =
        Vec2.getVector(
            t1.getPosX(),
            t1.getPosY(),
            t1.getPosX() + Math.cos(Math.toRadians(t1.getRotation())) * 10,
            t1.getPosY() + Math.sin(Math.toRadians(t1.getRotation())) * 10);
    Vec2 tarVec = Vec2.getVector(t1.getPosX(), t1.getPosY(), t2.getPosX(), t2.getPosY());

    double scalar = Vec2.getScalarMultip(forVec, tarVec);

    double modFV = Math.sqrt(forVec.vX * forVec.vX + forVec.vY * forVec.vY);
    double modTV = Math.sqrt(tarVec.vX * tarVec.vX + tarVec.vY * tarVec.vY);

    double cosa = scalar / (modFV * modTV);

    double ang = Math.toDegrees(Math.acos(cosa));

    double znak = getRelativePositionTarget(t1, t2);
    znak = znak / Math.abs(znak);

    if (Double.isNaN(znak)) {
      znak = 0;
    }

    if (Double.isNaN(ang)) {
      ang = 0;
    }

    return ang * znak;
  }
 public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) {
   if (mAnimator != null) {
     mAnimator.cancel();
   }
   final int w = mDetail.getWidth() - x;
   final int h = mDetail.getHeight() - y;
   int innerR = 0;
   if (x < 0 || w < 0 || y < 0 || h < 0) {
     innerR = Math.abs(x);
     innerR = Math.min(innerR, Math.abs(y));
     innerR = Math.min(innerR, Math.abs(w));
     innerR = Math.min(innerR, Math.abs(h));
   }
   int r = (int) Math.ceil(Math.sqrt(x * x + y * y));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y)));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h)));
   r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h)));
   if (in) {
     mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r);
   } else {
     mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR);
   }
   mAnimator.setDuration((long) (mAnimator.getDuration() * 1.5));
   if (listener != null) {
     mAnimator.addListener(listener);
   }
   if (in) {
     mBackground.startTransition((int) (mAnimator.getDuration() * 0.6));
     mAnimator.addListener(mVisibleOnStart);
   } else {
     mDetail.postDelayed(mReverseBackground, (long) (mAnimator.getDuration() * 0.65));
     mAnimator.addListener(mGoneOnEnd);
   }
   mAnimator.start();
 }
예제 #18
0
 /**
  * Returns a {@linkplain Stats Stats} object containing statistics of this series.
  *
  * @return Statistics.
  */
 public Stats stats() {
   int n = length();
   double sumX = 0.0;
   double sumY = 0.0;
   for (int i = 0; i < n; ++i) {
     sumX += x(i);
     sumY += y(i);
   }
   double meanX = sumX / n;
   double sumdevX = 0.0;
   double sumdevsqrX = 0.0;
   double meanY = sumY / n;
   double sumdevY = 0.0;
   double sumdevsqrY = 0.0;
   for (int i = 0; i < n; ++i) {
     double devX = x(i) - meanX;
     double devsqrX = devX * devX;
     sumdevX += devX;
     sumdevsqrX += devsqrX;
     double devY = y(i) - meanY;
     double devsqrY = devY * devY;
     sumdevY += devY;
     sumdevsqrY += devsqrY;
   }
   double varX = (sumdevsqrX - sumdevX * sumdevX / n) / (n - 1);
   double stddevX = Math.sqrt(varX);
   double varY = (sumdevsqrY - sumdevY * sumdevY / n) / (n - 1);
   double stddevY = Math.sqrt(varY);
   return new Stats(meanX, varX, stddevX, meanY, varY, stddevY);
 }
예제 #19
0
 public void mouseReleased(MouseEvent e) {
   left_mouse_pressed = false;
   double kvadrat = Math.sqrt(angleX * angleX + angleY * angleY);
   double tempx = angleX / kvadrat;
   double tempy = Math.sqrt(1 - tempx * tempx);
   if (angleY < 0) tempy = -tempy;
   Bullet b = new Bullet();
   boolean next = false;
   if (type_bullet1 == true && count_sphere > 0) {
     b = new Sphere();
     count_sphere--;
     next = true;
   }
   if (type_bullet2 == true && count_fireball > 0) {
     b = new FireBall();
     count_fireball--;
     next = true;
   }
   if (type_bullet3 == true && count_rocket > 0) {
     b = new Rocket();
     count_rocket--;
     next = true;
   }
   if (next == true) {
     b.bullet_x = player.getX() + 52 + 5 * Math.cos(angle); // + 50; //koef;
     b.bullet_y = player.getY() + 49 + 5 * Math.sin(angle); // player.getY() + 35; //25;
     b.current_direction_x = tempx;
     b.current_direction_y = tempy;
     bullet.addElement(b);
     allow_shoot = false;
   }
 }
예제 #20
0
  public static double calcDistFromLonmLatm(
      double lonm1, double latm1, double lonm2, double latm2) {
    double lon1R = lonm1 * .000001 / 180 * Math.PI;
    double lat1R = latm1 * .000001 / 180 * Math.PI;
    double lon2R = lonm2 * .000001 / 180 * Math.PI;
    double lat2R = latm2 * .000001 / 180 * Math.PI;

    // from http://www.movable-type.co.uk/scripts/latlong.html
    //		var R = 6371; // km
    //		var dLat = (lat2-lat1).toRad();
    //		var dLon = (lon2-lon1).toRad();
    //		var lat1 = lat1.toRad();
    //		var lat2 = lat2.toRad();
    //
    //		var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    //		        Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
    //		var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    //		var d = R * c;

    double dLatR = lat2R - lat1R;
    double dLonR = lon2R - lon1R;

    double a =
        Math.sin(dLatR / 2) * Math.sin(dLatR / 2)
            + Math.sin(dLonR / 2) * Math.sin(dLonR / 2) * Math.cos(lat1R) * Math.cos(lat2R);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return EARTH_RADIUS_M * c;
  }
예제 #21
0
  public double getT(Ray r, RenderObject o) {

    Matrix m = new Matrix();
    double[][] u = r.u3;
    double[][] ut = m.tMatrix(u);
    double[][] p = r.p0C.subtract(r.p0C, o.getOrigin()).toArray3D();
    double[][] pt = m.tMatrix(p);

    double[][] aa = m.multiplyMatrix(ut, u);
    double a = aa[0][0];

    double bb[][] = m.multiplyMatrix(ut, p);
    double b = bb[0][0] * 2;

    double cc[][] = m.multiplyMatrix(pt, p);
    double cee = cc[0][0] - (o.getRadius() * o.getRadius());
    double existance = (b * b) - (4 * a * cee);
    if (existance < 0) {
      return -1;
    } else {
      double t1 = ((-1 * b) + Math.sqrt(existance)) / (2 * a);
      double t2 = ((-1 * b) - Math.sqrt(existance)) / (2 * a);
      if (t1 < 0 && t2 < 0) {
        return -1;
      } else if (t1 < 0) {
        return t2;
      } else if (t2 < 0) {
        return t1;
      } else {
        return Math.min(t1, t2);
      }
    }
  }
예제 #22
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    final float ratio = calculateRatio();
    float radius;

    // Darkening background
    canvas.drawColor(Color.argb((int) (200 * calculateRatio()), 0, 0, 0));

    if (mRadiusAimed) {

      // Indicate that target radius is aimed.
      mPaint.setAlpha(35);
      radius = (float) Math.sqrt(mRadius / 70) * 70;
      canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint);
    }

    // Draw unlock circle
    mPaint.setAlpha((int) (255 * Math.pow(ratio, 0.33f)));
    radius = (float) Math.sqrt(mRadius / 50) * 50;
    canvas.drawCircle(mPoint[0], mPoint[1], radius, mPaint);

    // Draw unlock icon at the center of circle
    float scale = 0.5f + 0.5f * ratio;
    canvas.save();
    canvas.translate(
        mPoint[0] - mDrawable.getMinimumWidth() / 2 * scale,
        mPoint[1] - mDrawable.getMinimumHeight() / 2 * scale);
    canvas.scale(scale, scale);
    mDrawable.draw(canvas);
    canvas.restore();
  }
예제 #23
0
  /**
   * Input W must be initialized to a nonzero vector, output is {U,V,W}, an orthonormal basis. A
   * hint is provided about whether or not W is already unit length.
   *
   * @param kU DOCUMENT ME!
   * @param kV DOCUMENT ME!
   * @param kW DOCUMENT ME!
   * @param bUnitLengthW DOCUMENT ME!
   */
  static void generateOrthonormalBasis(
      MjVector3f kU, MjVector3f kV, MjVector3f kW, boolean bUnitLengthW) {

    if (!bUnitLengthW) {
      kW.normalizeSafe();
    }

    float fInvLength;

    if (Math.abs(kW.x) >= Math.abs(kW.y)) {

      // W.x or W.z is the largest magnitude component, swap them
      fInvLength = 1.0f / (float) Math.sqrt((kW.x * kW.x) + (kW.z * kW.z));
      kU.x = -kW.z * fInvLength;
      kU.y = 0.0f;
      kU.z = +kW.x * fInvLength;
    } else {

      // W.y or W.z is the largest magnitude component, swap them
      fInvLength = 1.0f / (float) Math.sqrt((kW.y * kW.y) + (kW.z * kW.z));
      kU.x = 0.0f;
      kU.y = +kW.z * fInvLength;
      kU.z = -kW.y * fInvLength;
    }

    kV.cross(kW, kU);
  }
예제 #24
0
 public static String calc_distance(Context context, String start_longlat, String end_longlat) {
   double sLat = Double.parseDouble(start_longlat.substring(0, start_longlat.indexOf(",") - 1));
   double sLng = Double.parseDouble(start_longlat.substring(start_longlat.indexOf(",") + 1));
   double eLat = Double.parseDouble(end_longlat.substring(0, end_longlat.indexOf(",") - 1));
   double eLng = Double.parseDouble(end_longlat.substring(end_longlat.indexOf(",") + 1));
   double dis;
   double jrk;
   String distance = null;
   double d2r = (Math.PI / 180);
   double dLat = (eLat - sLat) * d2r;
   double dLon = (eLng - sLng) * d2r;
   double a =
       Math.sin(dLat / 2) * Math.sin(dLat / 2)
           + Math.cos(sLat * d2r) * Math.cos(eLat * d2r) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
   double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
   dis = EARTH_RADIUS_KM * c * 1000;
   if (dis > 10000) {
     jrk = Double.valueOf(Math.round(dis / 1000));
     distance = Double.toString(jrk) + " Km";
   } else if (dis > 0 && dis < 100) {
     jrk = Double.valueOf(Math.round(dis));
     distance = Double.toString(jrk) + " m";
   } else if (dis > 200 && dis < 1000) {
     jrk = Double.valueOf(Math.round(dis / 10));
     distance = Double.toString(jrk) + " Km";
   } else {
     jrk = Double.valueOf(Math.round(dis / 1000));
     distance = Double.toString(jrk) + " Km";
   }
   return distance;
 }
예제 #25
0
  private double vegaArithmetic(double S, double K, double T, double r, double div, double sig) {
    double vegaAr = 0.0;
    double m1 = 0.0;
    double m2 = 0.0;
    double ba = 0.0;
    double b = r - div;
    double tau = 0.0;
    double va = 0.0;
    double d1, d2 = 0.0;

    m1 = (Math.exp(b * T) - Math.exp(b * tau)) / (b * (T - tau));

    m2 =
        2
                * Math.exp((2 * b + Math.pow(sig, 2)) * T)
                / ((b + Math.pow(sig, 2)) * (2 * b + Math.pow(sig, 2)) * Math.pow((T - tau), 2))
            + 2
                * Math.exp((2 * b + Math.pow(sig, 2)) * tau)
                / (b * Math.pow((T - tau), 2))
                * (1 / (2 * b + Math.pow(sig, 2))
                    - Math.exp(b * (T - tau)) / (b + Math.pow(sig, 2)));
    System.out.println("M:" + m2);
    ba = Math.log(m1) / T;
    va = Math.sqrt(Math.log(m2) / T - 2 * ba);

    d1 = (Math.log(S / K) + (ba + Math.pow(va, 2) / 2) * T) / (va * Math.sqrt(T));
    // d2 = d1 - (sig*Math.sqrt(T));

    vegaAr = S * Math.exp((ba - r) * T) * ND(d1) * Math.sqrt(T);
    return vegaAr;
  }
예제 #26
0
 private float calcXLocationInWheel(float x, float cos, float radius) {
   if (x > (getMeasuredWidth() / 2)) {
     return (float) (getWidth() / 2 + Math.sqrt(1 - cos * cos) * radius);
   } else {
     return (float) (getWidth() / 2 - Math.sqrt(1 - cos * cos) * radius);
   }
 }
예제 #27
0
  @Override
  public boolean onTouchEvent(MotionEvent event) {
    int action = event.getActionMasked();
    int P = event.getPointerCount();
    // int N = event.getHistorySize();
    if (action != MotionEvent.ACTION_MOVE) {
      if (action == MotionEvent.ACTION_DOWN) {
        // startX = mCurX * mScale; // event.getX();
        // startY = mCurY * mScale; // event.getY();
        sX1 = mCurX * mScale - event.getX(0);
        sY1 = mCurY * mScale - event.getY(0);
        return true;
      }
      if (action == MotionEvent.ACTION_POINTER_DOWN) {
        // Toast.makeText(mContext,
        // Float.toString(sX1)+"apd",
        // Toast.LENGTH_SHORT).show();

        if (P == 2) {
          float sX2 = event.getX(0) - event.getX(1);
          float sY2 = event.getY(0) - event.getY(1);
          sD = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);
          mBitmapViewWidthInitial = mBitmapViewWidth;
          return true;
        } else if (P == 3) {
          sMx = (float) mCenterX - event.getX(2);
          sMy = (float) mCenterY - event.getY(2);
          return true;
        }
        return false;
      }
    } else {
      if (P == 1) {
        float a = Math.abs(sX1 + event.getX()) % mX;
        float b = Math.abs(sY1 + event.getY()) % mY;
        mCurX = (int) (a / mScale); // *(int)(event.getHistoricalX(0)-event.getHistoricalX(1));
        mCurY = (int) (b / mScale); // *(int)(event.getHistoricalY(0)-event.getHistoricalY(1));
      } else if (P == 2) {
        float sX2 = event.getX(0) - event.getX(1);
        float sY2 = event.getY(0) - event.getY(1);
        float sD2 = (float) Math.sqrt(sX2 * sX2 + sY2 * sY2);

        int r = mBitmapViewWidthInitial + Math.round(sD2 - sD);
        if (r < mScreenRadius) r = mScreenRadius;
        setViewBitmapSizes(r);
      } else if (P == 3) {
        mCenterX = (int) (sMx + event.getX(2));
        mCenterY = (int) (sMy + event.getY(2));
      } else {
        return false;
      }

      drawIntoBitmap();
      invalidate();
      if (use3D) {
        updateTexture();
      }
    }
    return true;
  }
예제 #28
0
  private static double Correlationlogppl1(ArrayList<Double> sent, ArrayList<Double> word) {
    // TODO Auto-generated method stub
    double result = 0, SumScr_x = 0, SumScr_y = 0;
    double sum_sq_x = 0;
    double sum_sq_y = 0;
    double sum_coproduct = 0;
    double mean_x = 0;
    double mean_y = 0;
    for (int i = 0; i < sent.size(); i++) {
      SumScr_x += sent.get(i);
      SumScr_y += word.get(i);
    }
    mean_x = SumScr_x / sent.size();
    mean_y = SumScr_y / sent.size();

    for (int i = 0; i < sent.size(); i++) {

      double delta_x = sent.get(i) - mean_x;
      double delta_y = word.get(i) - mean_y;
      sum_sq_x += delta_x * delta_x;
      sum_sq_y += delta_y * delta_y;
      sum_coproduct += delta_x * delta_y;
    }
    double pop_sd_x = (double) Math.sqrt(sum_sq_x);
    double pop_sd_y = (double) Math.sqrt(sum_sq_y);
    result = sum_coproduct / (pop_sd_x * pop_sd_y);

    return result;
  }
  @Override
  public Component getVisualizationComponent(Object renderable, IOContainer ioContainer) {
    TTestSignificanceTestResult result = (TTestSignificanceTestResult) renderable;

    PerformanceVector[] allVectors = result.getAllVectors();
    StringBuffer buffer = new StringBuffer();
    Color bgColor = SwingTools.LIGHTEST_YELLOW;
    String bgColorString =
        Integer.toHexString(bgColor.getRed())
            + Integer.toHexString(bgColor.getGreen())
            + Integer.toHexString(bgColor.getBlue());

    buffer.append("<table bgcolor=\"" + bgColorString + "\" border=\"1\">");
    buffer.append("<tr><td></td>");
    for (int i = 0; i < result.getAllVectors().length; i++) {
      buffer.append(
          "<td>"
              + Tools.formatNumber(allVectors[i].getMainCriterion().getAverage())
              + " +/- "
              + Tools.formatNumber(Math.sqrt(allVectors[i].getMainCriterion().getVariance()))
              + "</td>");
    }
    buffer.append("</tr>");
    for (int i = 0; i < allVectors.length; i++) {
      buffer.append(
          "<tr><td>"
              + Tools.formatNumber(allVectors[i].getMainCriterion().getAverage())
              + " +/- "
              + Tools.formatNumber(Math.sqrt(allVectors[i].getMainCriterion().getVariance()))
              + "</td>");
      for (int j = 0; j < allVectors.length; j++) {
        buffer.append("<td>");
        if (!Double.isNaN(result.getProbMatrix()[i][j])) {
          double prob = result.getProbMatrix()[i][j];
          if (prob < result.getAlpha()) {
            buffer.append("<b>");
          }
          buffer.append(Tools.formatNumber(prob));
          if (prob < result.getAlpha()) {
            buffer.append("</b>");
          }
        }
        buffer.append("</td>");
      }
      buffer.append("</tr>");
    }
    buffer.append("</table>");
    buffer.append(
        "<br>Probabilities for random values with the same result.<br>Bold values are smaller than alpha="
            + Tools.formatNumber(result.getAlpha())
            + " which indicates a probably significant difference between the actual mean values!");

    JEditorPane textPane =
        new ExtendedHTMLJEditorPane(
            "text/html", "<html><h1>" + getName() + "</h1>" + buffer.toString() + "</html>");
    textPane.setBackground((new JLabel()).getBackground());
    textPane.setBorder(javax.swing.BorderFactory.createEmptyBorder(11, 11, 11, 11));
    textPane.setEditable(false);
    return new ExtendedJScrollPane(textPane);
  }
    /**
     * Gradient
     *
     * @param x a <code>double[]</code> input vector
     * @return
     */
    @Override
    public double[] gradient(double[] x) {
      double[] sqrtPsi = new double[nVariables];
      double[] invSqrtPsi = new double[nVariables];
      for (int i = 0; i < nVariables; i++) {
        x[i] = Math.max(0.005, x[i]); // ensure that no parameters are negative
        sqrtPsi[i] = Math.sqrt(x[i]);
        invSqrtPsi[i] = 1.0 / Math.sqrt(x[i]);
      }
      DiagonalMatrix diagPsi = new DiagonalMatrix(x);
      DiagonalMatrix diagSqtPsi = new DiagonalMatrix(sqrtPsi);
      DiagonalMatrix SC = new DiagonalMatrix(invSqrtPsi);

      RealMatrix Sstar = SC.multiply(R2).multiply(SC);

      EigenDecomposition E = new EigenDecomposition(Sstar);
      RealMatrix L = E.getV().getSubMatrix(0, nVariables - 1, 0, nFactors - 1);
      double[] ev = new double[nFactors];
      for (int i = 0; i < nFactors; i++) {
        ev[i] = Math.sqrt(Math.max(E.getRealEigenvalue(i) - 1, 0));
      }
      DiagonalMatrix M = new DiagonalMatrix(ev);
      RealMatrix LOAD = L.multiply(M);

      RealMatrix LL = diagSqtPsi.multiply(LOAD);
      RealMatrix G = LL.multiply(LL.transpose()).add(diagPsi).subtract(R2);

      double[] gradient = new double[nVariables];
      for (int i = 0; i < nVariables; i++) {
        gradient[i] = G.getEntry(i, i) / (x[i] * x[i]);
      }
      return gradient;
    }