예제 #1
1
 /**
  * This method obtains a list of primes until the number and calculates the maximum power of each
  * prime present in the least common multiple.
  *
  * @param number The required argument, upto which the numbers be processed.
  * @return The solution obtained by optimization.
  */
 public static long cacheAndConquer(long number) {
   long product = 1;
   long limit = (long) sqrt(number);
   long[] primes = Primes.getPrimesUntil(Math.toIntExact(number));
   for (long prime : primes) {
     long power = 1;
     if (prime <= limit) {
       // The maximum power of this prime :
       power = (long) (log(number) / log(prime));
     }
     product *= (long) pow(prime, power);
   }
   return product;
 }
예제 #2
0
  /**
   * Computes the radical axis of the two circles.
   *
   * @since 0.11.1
   * @return the radical axis of the two circles.
   * @throws IllegalArgumentException if the two circles have same center
   */
  public static StraightLine2D radicalAxis(Circle2D circle1, Circle2D circle2) {

    // extract center and radius of each circle
    double r1 = circle1.radius();
    double r2 = circle2.radius();
    Point2D p1 = circle1.center();
    Point2D p2 = circle2.center();

    // compute horizontal angle of joining line
    double angle = Angle2D.horizontalAngle(p1, p2);

    // distance between centers
    double dist = p1.distance(p2);
    if (dist < Shape2D.ACCURACY) {
      throw new IllegalArgumentException("Input circles must have distinct centers");
    }

    // position of the radical axis on the joining line
    double d = (dist * dist + r1 * r1 - r2 * r2) * .5 / dist;

    // pre-compute trigonometric functions
    double cot = Math.cos(angle);
    double sit = Math.sin(angle);

    // compute parameters of the line
    double x0 = p1.x() + d * cot;
    double y0 = p1.y() + d * sit;
    double dx = -sit;
    double dy = cot;

    // update state of current line
    return new StraightLine2D(x0, y0, dx, dy);
  }
예제 #3
0
 /*Creates the equipment in all states to initiate the game */
 private void fillStates(int sAvail, int sRent, int sShop) {
   int[] statesSizes = {sAvail, sRent, sShop};
   int s = 1;
   for (int stateSize : statesSizes) {
     for (int t = 1; t <= TYPES; t++) {
       for (int i = 1; i <= stateSize; i++) {
         Equipment e = new Equipment();
         e.state = s;
         e.type = t;
         int sMax =
             Math.max(
                 s - 2, 0); /*formula to make sure identifiers resume counting and stay unique */
         int sMin =
             Math.min(
                 s - 1, 1); /*formula to make sure identifiers resume counting and stay unique */
         e.ident = i + (sMin) * sAvail + (sMax) * sRent;
         e.c = equipColor(e.type);
         switch (s) {
           case 1:
             availEquipment.add(e);
             break;
           case 2:
             rentEquipment.add(e);
             break;
           case 3:
             shopEquipment.add(e);
             break;
         }
       }
     }
     s++;
   }
   computeInitialTimes();
   assignShapes();
 }
  public boolean isIndependent(Node x, Node y, List<Node> z) {
    int[] all = new int[z.size() + 2];
    all[0] = variablesMap.get(x);
    all[1] = variablesMap.get(y);
    for (int i = 0; i < z.size(); i++) {
      all[i + 2] = variablesMap.get(z.get(i));
    }

    int sampleSize = data.get(0).rows();
    List<Double> pValues = new ArrayList<Double>();

    for (int m = 0; m < ncov.size(); m++) {
      TetradMatrix _ncov = ncov.get(m).getSelection(all, all);
      TetradMatrix inv = _ncov.inverse();
      double r = -inv.get(0, 1) / sqrt(inv.get(0, 0) * inv.get(1, 1));

      double fisherZ =
          sqrt(sampleSize - z.size() - 3.0) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r));
      double pValue;

      if (Double.isInfinite(fisherZ)) {
        pValue = 0;
      } else {
        pValue = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(fisherZ)));
      }

      pValues.add(pValue);
    }

    double _cutoff = alpha;

    if (fdr) {
      _cutoff = StatUtils.fdrCutoff(alpha, pValues, false);
    }

    Collections.sort(pValues);
    int index = (int) round((1.0 - percent) * pValues.size());
    this.pValue = pValues.get(index);

    //        if (this.pValue == 0) {
    //            System.out.println("Zero pvalue "+ SearchLogUtils.independenceFactMsg(x, y, z,
    // getPValue()));
    //        }

    boolean independent = this.pValue > _cutoff;

    if (verbose) {
      if (independent) {
        TetradLogger.getInstance()
            .log("independencies", SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
        //            System.out.println(SearchLogUtils.independenceFactMsg(x, y, z, getPValue()));
      } else {
        TetradLogger.getInstance()
            .log("dependencies", SearchLogUtils.dependenceFactMsg(x, y, z, getPValue()));
      }
    }

    return independent;
  }
예제 #5
0
  @Test
  public void testRandom() {
    Random random = new Random();

    //		System.out.println(random.nextInt());
    System.out.println(random.nextInt(10));
    System.out.println(Math.round(((double) Math.random() * 100)));
  }
예제 #6
0
  public static double getAngleBetween(Vector v1, Vector v2) {
    double scalarProd = scalarProd(v1, v2);
    double vectorProd = vectorProd(v1, v2);

    double sign = vectorProd == 0 ? Math.signum(scalarProd) : Math.signum(vectorProd);

    return Math.acos(scalarProd / (length(v1) * length(v2))) * sign;
  }
예제 #7
0
 /*Generates a random exponential distribution random time difference vs. timeIn based on the frequency lambda */
 private double nextRandomTime(double lambda) {
   double timeLag = 0;
   /*System.out.println("I am computing nextRandomTime");
   System.out.println("When I am getting timeIn of " +timeIn+" and lambda of "+lambda);*/
   double random = Math.random();
   timeLag = -Math.log(random) / (lambda / (LENGTHOFADAY * 1000));
   /*System.out.println("I am returning a time difference of "+timeLag);*/
   return timeLag;
 }
예제 #8
0
 public long deltaDCountComplete() {
   Iterator iter = idx.sigma.iterator();
   double count = 0;
   FuncSymb f;
   double qdsize = qd.size();
   while (iter.hasNext()) {
     f = (FuncSymb) iter.next();
     count = count + Math.pow(qdsize, (double) f.arity);
   }
   return Math.round(count);
 }
예제 #9
0
파일: LPN.java 프로젝트: piotr-obroslak/PEP
 /** epsilon efektywny wg skryptu Misiaszka - wzor dzielony */
 private double FEPSM(double er, double h, double w, double t) {
   if (w / h < 1) {
     return (er + 1) / 2
         + ((er - 1) / 2) * (1 / Math.sqrt(1 + 12 * h / w) + 0.04 * (1 - w / h) * (1 - w / h))
         - (er - 1) / 4.6 * t / (h * Math.sqrt(w / h));
   } else {
     return (er + 1) / 2
         + ((er - 1) / 2) / (Math.sqrt(1 + 12 * h / w))
         - (er - 1) / 4.6 * t / (h * Math.sqrt(w / h));
   }
 }
예제 #10
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
 static { // data[] is a bitmap image of the ball of radius R
   data = new byte[R * 2 * R * 2];
   for (int Y = -R; Y < R; Y++) {
     int x0 = (int) (Math.sqrt(R * R - Y * Y) + 0.5);
     for (int X = -x0; X < x0; X++) {
       // sqrt(x^2 + y^2) gives distance from the spot light
       int x = X + hx, y = Y + hy;
       int r = (int) (Math.sqrt(x * x + y * y) + 0.5);
       // set the maximal intensity to the maximal distance
       // (in pixels) from the spot light
       if (r > maxr) maxr = r;
       data[(Y + R) * (R * 2) + (X + R)] = (r <= 0) ? 1 : (byte) r;
     }
   }
 }
예제 #11
0
 private void normalize(double[] vector) {
   double length =
       Math.sqrt(vector[0] * vector[0] + vector[1] * vector[1] + vector[2] * vector[2]);
   vector[0] /= length;
   vector[1] /= length;
   vector[2] /= length;
 }
예제 #12
0
 public static void main(String[] args) {
   Scanner scanner = new Scanner(System.in);
   int resp;
   double randomNumberDown;
   double randomNumberTop;
   double randomNumber;
   System.out.println("Загадайте число від 1 до 100 і натисніть будь-яку клавішу");
   resp = Integer.parseInt(scanner.nextLine());
   randomNumberDown = 1;
   randomNumberTop = 101;
   while (resp != 2) {
     randomNumber = Math.floor((randomNumberDown + randomNumberTop) / 2);
     // число randomNumber мусить бути типу double тому, що воно інакше видає помилку
     // math.floor мусить бути, бо якщо (34+37)/2= 35,5
     System.out.println("Ваше число" + " " + randomNumber + "?");
     resp = Integer.parseInt(scanner.nextLine());
     if (resp == 2) {
       System.out.println("Вітаємо");
     } else if (resp == 1) {
       randomNumberDown = randomNumber;
       // число randomNumberDown теж має бути типу double бо інакше ми не зможемо присвоїти йому
       // число типу double
     } else if (resp == 0) {
       randomNumberTop = randomNumber;
       // тоже саме
     }
   }
 }
예제 #13
0
  /** Fill in the finalScore attribute for every choice. */
  private static void calculateFinalScores(
      List<Choice> choices, List<Characteristic> characs, double[][] crossRankings) {
    double[] scores = new double[choices.size()];
    double max = 0.0;
    for (int i = 0; i < choices.size(); i++) {
      for (int j = 0; j < characs.size(); j++) {
        scores[i] += characs.get(j).getRank() * crossRankings[i][j];
        choices.get(i).setFinalScore((int) Math.round(crossRankings[i][j] * 100));
      }
      if (scores[i] > max) max = scores[i];
    }

    for (int i = 0; i < scores.length; i++) {
      choices.get(i).setFinalScore((int) (Math.round(scores[i] / max * 100)));
    }
  }
예제 #14
0
  public static double getDist(Atom a, Atom b) {
    double xDist = a.getPoint().x - b.getPoint().x;
    double yDist = a.getPoint().y - b.getPoint().y;

    double dist = Math.sqrt((xDist * xDist) + (yDist * yDist));
    return dist;
  }
예제 #15
0
 public static float taxicab(float[] v1, float[] v2) {
   float result = 0;
   for (int i = 0; i < v1.length; i++) {
     result += Math.abs(v1[i] - v2[i]);
   }
   return result;
 }
예제 #16
0
  public int getOverDrones(EcState s) {
    int overDrones = ((s.productionTime() / 17) + s.usedDrones()) * overDroneEfficiency / 100;

    overDrones = Math.min(overDrones, maxOverDrones);

    return overDrones;
  }
예제 #17
0
  public static void main(String[] args) {
    double a = -191.635;
    double b = 43.74;
    int c = 16, d = 45;

    System.out.printf("The absolute value " + "of %.3f is %.3f%n", a, abs(a));

    System.out.printf("The ceiling of " + "%.2f is %.0f%n", b, Math.ceil(b));

    System.out.printf("The floor of " + "%.2f is %.0f%n", b, Math.floor(b));

    System.out.printf("The rint of %.2f " + "is %.0f%n", b, Math.rint(b));

    System.out.printf("The max of %d and " + "%d is %d%n", c, d, Math.max(c, d));

    System.out.printf("The min of of %d " + "and %d is %d%n", c, d, Math.min(c, d));
  }
 public int minkeys() {
   // if node is the root, minkey is 1
   if (getParent() == null) {
     return 1;
   } else {
     return (int) (Math.ceil(degree / 2.0) - 1);
   }
 }
예제 #19
0
  /* (non-Javadoc)
   * @see math.geom2d.curve.ContinuousCurve2D#asPolyline(int)
   */
  public Polyline2D asPolyline(int n) {

    // compute increment value
    double dt = Math.abs(this.angleExtent) / n;

    // allocate array of points, and compute each value.
    // Computes also value for last point.
    Point2D[] points = new Point2D[n + 1];
    for (int i = 0; i < n + 1; i++) points[i] = this.point(i * dt);

    return new Polyline2D(points);
  }
예제 #20
0
 /**
  * @return weekly payment
  * @throws InvalidDurationException
  * @throws NegativeLoanFieldException
  */
 public double weeklyPayment() throws InvalidDurationException, NegativeLoanFieldException {
   double weeklyPayment;
   if (interestRate > 0) {
     weeklyPayment =
         loanAmount
             * ((interestRate / 100) / 52)
             / (1 - Math.pow((1 + (interestRate / 100) / 52), (-durationYears * 52)));
   } else {
     weeklyPayment = loanAmount / (durationYears * 52);
   }
   return weeklyPayment;
 }
 public YIntervalSeries getYIntervalSeries(String rowname, long factor) {
   YIntervalSeries mydataset = new YIntervalSeries(rowname);
   double sdcount = 0;
   double total = 0;
   Vector<Double> totalvalues = new Vector<Double>();
   double avgtotal = 0;
   double minus = 0;
   double plus = 0;
   double zero = 0;
   for (Integer key : ysum.keySet()) {
     Double value = ysum.get(key) / (double) count.get(key);
     Double point = (double) xsum.get(key) / (double) count.get(key);
     Vector<Double> listofvalues = values.get(key);
     double sumofdiff = 0.0;
     for (Double onevalue : listofvalues) {
       sumofdiff += Math.pow(onevalue - value, 2);
       sdcount++;
       total += Math.pow(onevalue, 2);
       avgtotal += onevalue;
       totalvalues.add(onevalue);
       if (onevalue == 1) {
         plus++;
       }
       ;
       if (onevalue == -1) {
         minus++;
       }
       ;
       if (onevalue == 0) {
         zero++;
       }
       ;
     }
     double sd = Math.sqrt(sumofdiff / count.get(key));
     // mydataset.add(point/factor, value,value+sd,value-sd);
     // mydataset.add(point/factor, value,value,value);
     mydataset.add(
         point / factor,
         value,
         value + 1.96 * (sd / Math.sqrt(count.get(key))),
         value - 1.96 * (sd / Math.sqrt(count.get(key))));
   }
   double sdtotal = 0;
   double avgsd = total / sdcount;
   double test = 0;
   for (Double onevalue : totalvalues) {
     sdtotal += Math.pow(Math.pow(onevalue, 2) - (total / sdcount), 2);
     test += onevalue;
   }
   // System.out.println(rowname+" mean square: "+avgsd+"
   // +/-95%:"+1.96*Math.sqrt(sdtotal/sdcount)/Math.sqrt(sdcount));
   // System.out.println("total -1:"+minus+" total +1:"+plus+" zero: "+zero
   // +" total:"+sdcount);
   return mydataset;
 }
예제 #22
0
 /**
  * @return biweekly payment
  * @throws InvalidDurationException
  * @throws NegativeLoanFieldException
  */
 public double biweeklyPayment() throws InvalidDurationException, NegativeLoanFieldException {
   double biPayment;
   // biPayment = ((interestRate * 100) * 12) / 26;
   if (interestRate > 0) {
     biPayment =
         loanAmount
             * ((interestRate / 26) / 100)
             / (1 - Math.pow((1 + (interestRate / 26) / 100), (-durationYears * 26)));
   } else {
     biPayment = loanAmount / (durationYears * 26);
   }
   return biPayment;
 }
예제 #23
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  /** Rotate theta degrees around the y axis */
  void yrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nxx = (xx * ct + zx * st);
    double Nxy = (xy * ct + zy * st);
    double Nxz = (xz * ct + zz * st);
    double Nxo = (xo * ct + zo * st);

    double Nzx = (zx * ct - xx * st);
    double Nzy = (zy * ct - xy * st);
    double Nzz = (zz * ct - xz * st);
    double Nzo = (zo * ct - xo * st);

    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
예제 #24
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  /** Rotate theta degrees about the z axis */
  void zrot(double theta) {
    theta *= pi / 180;
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + xx * st);
    double Nyy = (yy * ct + xy * st);
    double Nyz = (yz * ct + xz * st);
    double Nyo = (yo * ct + xo * st);

    double Nxx = (xx * ct - yx * st);
    double Nxy = (xy * ct - yy * st);
    double Nxz = (xz * ct - yz * st);
    double Nxo = (xo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    xo = Nxo;
    xx = Nxx;
    xy = Nxy;
    xz = Nxz;
  }
예제 #25
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  /** Rotate theta degrees about the x axis */
  void xrot(double theta) {
    theta *= (pi / 180);
    double ct = Math.cos(theta);
    double st = Math.sin(theta);

    double Nyx = (yx * ct + zx * st);
    double Nyy = (yy * ct + zy * st);
    double Nyz = (yz * ct + zz * st);
    double Nyo = (yo * ct + zo * st);

    double Nzx = (zx * ct - yx * st);
    double Nzy = (zy * ct - yy * st);
    double Nzz = (zz * ct - yz * st);
    double Nzo = (zo * ct - yo * st);

    yo = Nyo;
    yx = Nyx;
    yy = Nyy;
    yz = Nyz;
    zo = Nzo;
    zx = Nzx;
    zy = Nzy;
    zz = Nzz;
  }
  public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    int xStart;
    int xEnd;
    int flingDist;
    int myWidth;
    int yStart;
    int yEnd;
    int minDeltaX;

    Xlog.d(MmsApp.TXN_TAG, "MsgContentSlideView.onFling");

    if (mFlingListener == null) {
      Xlog.d(MmsApp.TXN_TAG, "MsgNumSlideView.onFling, no listener");
      return true;
    }

    if (e1 == null || e2 == null) {
      if (e1 == null) Xlog.d(MmsApp.TXN_TAG, "e1 null");
      else Xlog.d(MmsApp.TXN_TAG, "e2 null");
      return false;
    }
    xStart = (int) e1.getX();
    xEnd = (int) e2.getX();
    flingDist = xStart - xEnd;
    myWidth = getWidth();
    minDeltaX = myWidth / 10;

    Xlog.d(MmsApp.TXN_TAG, "e1=" + xStart + "e2=" + xEnd);

    // yStart = (int)e1.getY();
    // yEnd = (int)e2.getY();
    // Log.i("MsgContentSlideView", "onFling, y1=" +yStart  + "y2=" + yEnd);
    if (Math.abs(xEnd - xStart) <= minDeltaX) {
      return false;
    }

    if (flingDist > 0 && flingDist > myWidth / 3) {
      Xlog.d(MmsApp.TXN_TAG, "left");
      mFlingListener.onSlideToNext();
    } else if (flingDist < 0 && (-flingDist) > myWidth / 3) {
      Xlog.d(MmsApp.TXN_TAG, "right");
      mFlingListener.onSlideToPrev();
    }

    return true;
  }
예제 #27
0
 public long deltaDCount() {
   double count = 0;
   double tcount;
   double argsize;
   double qdsize = qd.size();
   ArrayList<LinkedHashSet<LinkedHashSet<String>>> lhs;
   for (int i = 0; i < deltad.size(); i++) {
     lhs = deltad.get(i).lhs;
     tcount = 1.0;
     for (int j = 0; j < lhs.size(); j++) {
       argsize = lhs.get(j).size();
       if (argsize == 0) {
         argsize = qdsize; // don't care argument
       }
       tcount = tcount * argsize;
     }
     count = count + tcount;
   }
   return Math.round(count);
 }
예제 #28
0
 static int squareroot2(double x) {
   double a = 1;
   double b = 1;
   double c, d, e, f, g, h, dif;
   double difference = 1;
   double bstart = 1;
   while (difference > 0.001) {
     bstart = b;
     c = b * b;
     d = c - x;
     e = 2 * b;
     f = d / e;
     a = b - f;
     b = a;
     dif = bstart - b;
     difference = Math.abs(dif);
   }
   int answer = (int) b;
   return answer;
 }
예제 #29
0
  // APPLY LIGHTING CALCULATIONS TO VERTEX USING ITS MATERIAL
  private void lightPoint(double[] vertex, Material material) {

    // NORMAL AT THE VERTEX
    double[] normal = {vertex[3], vertex[4], vertex[5]};

    // RESET TEMPORARY COLOR ARRAY
    for (int i = 0; i < tmpCol.length; i++) {
      tmpCol[i] = 0.0;
    }

    // FOR EACH LIGHT SOURCE
    for (int i = 0; i < lights.length; i++) {

      // LIGHT DIRECTION
      double[] lDir = lights[i][0];

      // REFLECTION DIRECTION
      for (int k = 0; k < lDir.length; k++) {
        tmpVec[k] = 2 * (dot(lDir, normal)) * normal[k] - lDir[k];
      }
      double[] rDir = tmpVec;
      normalize(rDir);

      // FOR EACH COLOR IN RGB
      for (int j = 0; j < 3; j++) {
        tmpCol[j] +=
            tmpMaterial.getAmbientColor()[j]
                + lights[i][1][j]
                    * (tmpMaterial.getDiffuseColor()[j] * Math.max(0.0, dot(lDir, normal))
                        + tmpMaterial.getSpecularColor()[j]
                            * Math.pow(
                                Math.max(0.0, dot(rDir, eyeDir)), tmpMaterial.getSpecularPower()));
      }
    }

    // GAMMA CORRECTION

    if (!showNormals) {
      vertex[6] = 255.0 * Math.pow(tmpCol[0], 0.45);
      vertex[7] = 255.0 * Math.pow(tmpCol[1], 0.45);
      vertex[8] = 255.0 * Math.pow(tmpCol[2], 0.45);
    } else {
      vertex[6] = mapRGB(normal[0]);
      vertex[7] = mapRGB(normal[1]);
      vertex[8] = mapRGB(normal[2]);
    }
  }
예제 #30
0
 public static double length(Vector vector) {
   return Math.sqrt(vector.getA() * vector.getA() + vector.getB() * vector.getB());
 }