List of usage examples for java.lang Math round
public static long round(double a)
From source file:Main.java
/** bitmap downsample utils **/ public static int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { final int heightRatio = Math.round((float) height / (float) reqHeight); final int widthRatio = Math.round((float) width / (float) reqWidth); inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; }//from w w w .j a v a 2 s. com return inSampleSize; }
From source file:javatranslation.matlab.dfa.java
public static void dfafunction(double[] tau, double MinBox, double MaxBox, int DFAorder) { double[] incoef = null; double[] l = null; l = new double[50]; incoef = new double[50]; for (int i = 0; i < 50; i++) { l = logspace(MinBox, MaxBox);//from w ww . j a va2 s . com //System.out.println(l[i]); incoef[i] = Math.round(l[i]); } double xx = mean(tau); for (int i = 0; i < tau.length; i++) { tau[i] = tau[i] - xx; } double[] Y = cumsum(tau, dfa.mean(tau)); double maxnumseg = incoef.length; double[] winlen = null; winlen = new double[50]; for (int truta = 0; truta < 50; truta++) { winlen[truta] = incoef[truta]; } Arrays.sort(winlen); ArrayUtils.reverse(winlen); double Ylength = Y.length; double F[][] = new double[(int) maxnumseg][1]; for (int k = 0; k < maxnumseg; k++) { F[k][0] = 0; } double[] timevec = new double[50]; for (int kk = 0; kk < maxnumseg; kk++) { timevec[kk] = winlen[kk]; double numsegm = Math.floor(Ylength / winlen[kk]); double tempY[][] = new double[1][(int) numsegm]; for (int k = 0; k < numsegm; k++) { tempY[0][k] = 0; } for (int zz = 0; zz < numsegm; zz++) { double overflowtest = zz * winlen[kk]; if (overflowtest <= Ylength) { double[] tempvec = null; int ko = 0; for (double p = ((zz - 1) * winlen[kk] + 1); p <= (zz * winlen[kk]); p = ((zz - 1) * winlen[kk] + 1) + 1) { // there are some errors in this loop tempvec[ko] = Y[(int) p]; System.out.println(tempvec[(int) p]); ko++; } //double temppol = polyfit(timevec,tempvec,DFAorder); MultivariateVectorOptimizer optimizer; optimizer = null; PolynomialFitter x = new PolynomialFitter(optimizer); // error here too double[] temppol = x.fit(DFAorder, timevec); double[] temppol2 = x.fit(DFAorder, tempvec); double[] arrayOfCoefficients = new double[temppol2.length]; arrayOfCoefficients = temppol2; int len = arrayOfCoefficients.length; double retAnswer = 0; double ret = 0; for (int i = 0; i < len; i++) { retAnswer = retAnswer + Math.pow(arrayOfCoefficients[i], i); } for (int i = 0; i < tempvec.length; i++) { ret = tempvec[i] - (Math.pow(retAnswer, 2)); } tempY[0][zz] = ((ret) / winlen[kk]); } } int k; double[] kopp = new double[(int) maxnumseg]; for (k = 0; k < maxnumseg; k++) { kopp[k] = tempY[0][k]; } double nonzerotempY = dfa.sum2(kopp); F[kk][0] = Math.sqrt(dfa.sum(kopp) / nonzerotempY); } double[] LF; LF = new double[(int) maxnumseg]; double[] LN; LN = new double[(int) maxnumseg]; for (int i = 0; i < maxnumseg; i++) { LF[i] = Math.log10(F[i][0]); LN[i] = Math.log10(winlen[i]); } double[][] XLN = new double[LN.length][LN.length]; for (int i = 0; i < LN.length; i++) { XLN[i][0] = 1; XLN[i][1] = LN[i]; } SimpleRegression x; x = new SimpleRegression(); x.addObservations(XLN, LF); // and probably error in this one too RegressionResults b = x.regress(); // System.out.println(b.getParameterEstimates()); //double LF=Math.log10(F); % log fluctuations //double LN=Math.log10(winlen); }
From source file:com.jennifer.ui.util.StringUtil.java
public static String createId(String key) { return key + "-" + System.currentTimeMillis() + "-" + (Math.round(Math.random() * 100) % 100); }
From source file:eu.transkribus.swt_canvas.util.GeomUtils.java
/** * Returns closest point on segment to point * /*w w w . ja va 2s. co m*/ * @param sx1 * segment x coord 1 * @param sy1 * segment y coord 1 * @param sx2 * segment x coord 2 * @param sy2 * segment y coord 2 * @param px * point x coord * @param py * point y coord * @return closets point on segment to point */ public static Point getClosestPointOnSegment(int sx1, int sy1, int sx2, int sy2, int px, int py) { double xDelta = sx2 - sx1; double yDelta = sy2 - sy1; if ((xDelta == 0) && (yDelta == 0)) { // segment is a point -> return this point as it must be the closest one! return new Point(sx1, sy1); // throw new IllegalArgumentException("Segment start equals segment end"); } double u = ((px - sx1) * xDelta + (py - sy1) * yDelta) / (xDelta * xDelta + yDelta * yDelta); final Point closestPoint; if (u < 0) { closestPoint = new Point(sx1, sy1); } else if (u > 1) { closestPoint = new Point(sx2, sy2); } else { closestPoint = new Point((int) Math.round(sx1 + u * xDelta), (int) Math.round(sy1 + u * yDelta)); } return closestPoint; }
From source file:com.nebhale.gpxconverter.GoogleMapsEncoder.java
@Override public String encode(List<Point> points) { StringBuilder encoded = new StringBuilder(); Long previousLatitude = 0L;//from w w w . j ava 2s .c o m Long previousLongitude = 0L; List<Point> filtered = filter(points, MAX_SIZE); for (Point point : filtered) { Long e5Latitude = Math.round(1e5 * point.getLatitude()); Long e5Longitude = Math.round(1e5 * point.getLongitude()); Long differenceLatitude = e5Latitude - previousLatitude; Long differenceLongitude = e5Longitude - previousLongitude; previousLatitude = e5Latitude; previousLongitude = e5Longitude; String encodedLatitude = encodeSignedNumber(differenceLatitude); String encodedLongitude = encodeSignedNumber(differenceLongitude); encoded.append(encodedLatitude).append(encodedLongitude); } return encoded.toString(); }
From source file:Main.java
/** * Method is available if specific dimensions are specified * @param path// w ww . jav a2s .c o m * @param destWidth * @param destHeight * @return */ public static Bitmap getScaledBitmap(String path, int destWidth, int destHeight) { // Read in the dimensions of the image on disk BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(path, options); float srcWidth = options.outWidth; float srcHeight = options.outHeight; // Figure out how much to scale down by int inSampleSize = 1; if (srcHeight > destHeight || srcWidth > destWidth) { if (srcWidth > srcHeight) { inSampleSize = Math.round(srcHeight / destHeight); } else { inSampleSize = Math.round(srcWidth / destWidth); } } options = new BitmapFactory.Options(); options.inSampleSize = inSampleSize; //Read in and create final bitmap return BitmapFactory.decodeFile(path, options); }
From source file:cc.recommenders.evaluation.data.Averager.java
public int getIntAverage() { return (int) Math.round(getAverage()); }
From source file:io.seldon.vw.VwFeatureHash.java
public VwFeatureHash(int bits, int oaa) { mask = Math.round((float) Math.pow(2, bits) - 1); stride = Math.round((float) Math.pow(2, Math.ceil(log2(oaa, 2)))); System.out.println("Stide is " + stride); }
From source file:Main.java
private static int dpToPx(Context mContext, int dp) { float density = mContext.getResources().getDisplayMetrics().density; return Math.round((float) dp * density); }
From source file:geogebra.kernel.statistics.AlgoPascal.java
protected final void compute() { if (input[0].isDefined() && input[1].isDefined() && input[2].isDefined() && input[3].isDefined()) { int param = (int) Math.round(a.getDouble()); double param2 = b.getDouble(); double val = c.getDouble(); try {// w ww . j a va 2 s .com PascalDistribution dist = getPascalDistribution(param, param2); if (isCumulative.getBoolean()) num.setValue(dist.cumulativeProbability(val)); // P(X <= val) else num.setValue(dist.probability(val)); // P(X = val) } catch (Exception e) { num.setUndefined(); } } else num.setUndefined(); }