List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:com.kylinolap.common.hll.HyperLogLogPlusCounter.java
/** The larger p is, the more storage (2^p bytes), the better accuracy */ private HyperLogLogPlusCounter(int p, HashFunction hashFunc) { this.p = p;//from ww w . ja v a 2 s . com this.m = (int) Math.pow(2, p); this.hashFunc = hashFunc; this.registers = new byte[m]; }
From source file:com.amplify.gcm.hack.NTPClient.java
/** * Process <code>TimeInfo</code> object and print its details. * * @param info <code>TimeInfo</code> object. *//* w w w . j a v a 2 s .c om*/ public static void processResponse(TimeInfo info) { NtpV3Packet message = info.getMessage(); int stratum = message.getStratum(); String refType; if (stratum <= 0) refType = "(Unspecified or Unavailable)"; else if (stratum == 1) refType = "(Primary Reference; e.g., GPS)"; // GPS, radio clock, etc. else refType = "(Secondary Reference; e.g. via NTP or SNTP)"; // stratum should be 0..15... System.out.println(" Stratum: " + stratum + " " + refType); int version = message.getVersion(); int li = message.getLeapIndicator(); System.out.println(" leap=" + li + ", version=" + version + ", precision=" + message.getPrecision()); System.out.println(" mode: " + message.getModeName() + " (" + message.getMode() + ")"); int poll = message.getPoll(); // poll value typically btwn MINPOLL (4) and MAXPOLL (14) System.out.println( " poll: " + (poll <= 0 ? 1 : (int) Math.pow(2, poll)) + " seconds" + " (2 ** " + poll + ")"); double disp = message.getRootDispersionInMillisDouble(); System.out.println(" rootdelay=" + numberFormat.format(message.getRootDelayInMillisDouble()) + ", rootdispersion(ms): " + numberFormat.format(disp)); int refId = message.getReferenceId(); String refAddr = NtpUtils.getHostAddress(refId); String refName = null; if (refId != 0) { if (refAddr.equals("127.127.1.0")) { refName = "LOCAL"; // This is the ref address for the Local Clock } else if (stratum >= 2) { // If reference id has 127.127 prefix then it uses its own reference clock // defined in the form 127.127.clock-type.unit-num (e.g. 127.127.8.0 mode 5 // for GENERIC DCF77 AM; see refclock.htm from the NTP software distribution. if (!refAddr.startsWith("127.127")) { try { InetAddress addr = InetAddress.getByName(refAddr); String name = addr.getHostName(); if (name != null && !name.equals(refAddr)) refName = name; } catch (UnknownHostException e) { // some stratum-2 servers sync to ref clock device but fudge stratum level higher... (e.g. 2) // ref not valid host maybe it's a reference clock name? // otherwise just show the ref IP address. refName = NtpUtils.getReferenceClock(message); } } } else if (version >= 3 && (stratum == 0 || stratum == 1)) { refName = NtpUtils.getReferenceClock(message); // refname usually have at least 3 characters (e.g. GPS, WWV, LCL, etc.) } // otherwise give up on naming the beast... } if (refName != null && refName.length() > 1) refAddr += " (" + refName + ")"; TimeStamp refNtpTime = message.getReferenceTimeStamp(); // Originate Time is time request sent by client (t1) TimeStamp origNtpTime = message.getOriginateTimeStamp(); long destTime = info.getReturnTime(); long localDestTime = System.currentTimeMillis(); // Receive Time is time request received by server (t2) TimeStamp rcvNtpTime = message.getReceiveTimeStamp(); // Transmit time is time reply sent by server (t3) TimeStamp xmitNtpTime = message.getTransmitTimeStamp(); // Destination time is time reply received by client (t4) TimeStamp destNtpTime = TimeStamp.getNtpTime(destTime); info.computeDetails(); // compute offset/delay if not already done Long offsetValue = info.getOffset(); Long delayValue = info.getDelay(); String delay = (delayValue == null) ? "N/A" : delayValue.toString(); String offset = (offsetValue == null) ? "N/A" : offsetValue.toString(); clockOffset = offsetValue != null ? offsetValue.longValue() : 0L; Log.i(TAG, " Reference Identifier:\t" + refAddr); Log.i(TAG, " Reference Timestamp:\t" + refNtpTime + " " + refNtpTime.toDateString()); Log.i(TAG, " Originate Timestamp:\t" + origNtpTime + " " + origNtpTime.toDateString()); Log.i(TAG, " Receive Timestamp:\t" + rcvNtpTime + " " + rcvNtpTime.toDateString()); Log.i(TAG, " Transmit Timestamp:\t" + xmitNtpTime + " " + xmitNtpTime.toDateString()); Log.i(TAG, " Destination Timestamp:\t" + destNtpTime + " " + destNtpTime.toDateString()); Log.i(TAG, " Roundtrip delay(ms)=" + delay + ", clock offset(ms)=" + offset); }
From source file:ArrayUtil.java
public static int binaryToInt(int bin[]) { int r = 0, pos = 0; for (int i = bin.length - 1; i >= 0; i--) r += bin[i] * Math.pow(2, pos++); return r;/* w w w . ja va 2 s.co m*/ }
From source file:com.amindorost.searchalgorithms.MainSearch.java
protected double heuristics(Node node) { switch (this.heuristicsType) { case 0:/*ww w. jav a 2 s. c om*/ return 0; case 1: //SLD return Math.sqrt(Math.pow(node.getLocation().width - this.dst.getLocation().width, 2) + Math.pow(node.getLocation().height - this.dst.getLocation().height, 2)); default: return 0; } }
From source file:jurls.core.approximation.WeightedInterpolationFunction.java
private double weight(ArrayRealVector a, ArrayRealVector b) { double d = a.getL1Distance(b); return Math.pow(1 / (1 + d), power); }
From source file:gr.eap.LSHDB.HammingKey.java
public int getLc() { double p = 1 - (t * 1.0) / (this.size * 1.0); p = Math.pow(p, k); double exp = (L * p); double std = Math.sqrt(exp * (1 - p)); int C = (int) Math.round(exp - std); double x = (Math.sqrt(Math.log(delta) * Math.log(delta) - 2 * C * Math.log(delta)) - Math.log(delta) + C) / p;//w w w. j a v a2s. c o m int Lc = (int) Math.ceil(x); double b = Lc * p; if (C > b) System.out.println("does not apply C > np."); BinomialDistribution bd1 = new BinomialDistribution(L, p); for (int l = L; l < L * 2; l++) { bd1 = new BinomialDistribution(l, p); double result = bd1.cumulativeProbability(C - 1); if (result < delta) { Lc = l; break; } } System.out.println("Lc reduced to=" + Lc); return Lc; }
From source file:com.metamx.collections.spatial.search.RadiusBound.java
@Override public boolean contains(float[] otherCoords) { double total = 0.0; for (int i = 0; i < coords.length; i++) { total += Math.pow(otherCoords[i] - coords[i], 2); }//from www . j av a 2 s . c om return (total <= Math.pow(radius, 2)); }
From source file:com.opengamma.analytics.financial.var.parametric.DeltaGammaCovarianceMatrixSkewnessCalculator.java
@Override public Double evaluate(final Map<Integer, ParametricVaRDataBundle> data) { Validate.notNull(data, "data"); final ParametricVaRDataBundle firstOrderData = data.get(1); Validate.notNull(firstOrderData, "first order data"); final ParametricVaRDataBundle secondOrderData = data.get(2); if (secondOrderData == null) { return 0.; }/*w w w . j a v a 2s. c om*/ final DoubleMatrix1D delta = (DoubleMatrix1D) firstOrderData.getSensitivities(); final Matrix<?> gamma = secondOrderData.getSensitivities(); if (gamma == null || gamma.getNumberOfElements() == 0) { return 0.; } final DoubleMatrix2D gammaMatrix = (DoubleMatrix2D) gamma; final DoubleMatrix2D deltaCovariance = firstOrderData.getCovarianceMatrix(); if (gammaMatrix.getNumberOfColumns() != deltaCovariance.getNumberOfColumns()) { throw new IllegalArgumentException("Gamma matrix and covariance matrix were incompatible sizes"); } final Matrix<?> product = _algebra.multiply(gammaMatrix, deltaCovariance); final double numerator = _algebra.getTrace(_algebra.getPower(product, 3)) + 3 * _algebra .getInnerProduct(delta, _algebra.multiply(_algebra.multiply(deltaCovariance, product), delta)); final double denominator = Math.pow(0.5 * _algebra.getTrace(_algebra.getPower(product, 2)) + _algebra.getInnerProduct(delta, _algebra.multiply(deltaCovariance, delta)), 1.5); return numerator / denominator; }
From source file:adams.data.utils.SavitzkyGolay.java
/** * Determines the coefficients for the smoothing, with optional debugging * output./* ww w . j av a 2 s .c om*/ * * @param numLeft the number of points to the left * @param numRight the number of points to the right * @param polyOrder the polynomial order * @param derOrder the derivative order * @param debug whether to output debugging information * @return the coefficients */ public static double[] determineCoefficients(int numLeft, int numRight, int polyOrder, int derOrder, boolean debug) { double[] result; RealMatrix A; int i; int j; int k; float sum; RealMatrix b; LUDecomposition lu; RealMatrix solution; result = new double[numLeft + numRight + 1]; // no window? if (result.length == 1) { result[0] = 1.0; return result; } // Note: "^" = superscript, "." = subscript // {A^T*A}.ij = Sum[k:-nl..nr](k^(i+j)) A = new Array2DRowRealMatrix(polyOrder + 1, polyOrder + 1); for (i = 0; i < A.getRowDimension(); i++) { for (j = 0; j < A.getColumnDimension(); j++) { sum = 0; for (k = -numLeft; k <= numRight; k++) sum += Math.pow(k, i + j); A.setEntry(i, j, sum); } } if (debug) System.out.println("A:\n" + A); // LU decomp for inverse matrix b = new Array2DRowRealMatrix(polyOrder + 1, 1); b.setEntry(derOrder, 0, 1.0); if (debug) System.out.println("b:\n" + b); lu = new LUDecompositionImpl(A); solution = lu.getSolver().solve(b); if (debug) System.out.println("LU decomp. - solution:\n" + solution); // coefficients: c.n = Sum[m:0..M]((A^T*A)^-1).0m * n^m with n=-nl..nr for (i = -numLeft; i <= numRight; i++) { sum = 0; for (j = 0; j <= polyOrder; j++) sum += solution.getEntry(j, 0) * Math.pow(i, j); result[i + numLeft] = sum; } if (debug) System.out.println("Coefficients:\n" + Utils.arrayToString(result)); return result; }
From source file:org.openmrs.module.reportingdemo.definition.data.evaluator.BmiPatientDataEvaluatorTest.java
@Test public void shouldCorrectlyComputeBmi() throws Exception { // We can use the openmrs-contrib-testutils library to easily create test data to validate against Patient p1 = data.randomPatient().save(); // We can use the metadatadeploy tools to retrive existing metadata from our database by uuid Concept weightConcept = MetadataUtils.existing(Concept.class, MetadataConstants.WEIGHT); Concept heightConcept = MetadataUtils.existing(Concept.class, MetadataConstants.HEIGHT); Double wt1 = 50.0; // This is kg Double ht1 = 140.0; // This is cm Double expectedBmi1 = wt1 / (Math.pow(ht1 / 100, 2)); Obs o1 = data.obs().person(p1).concept(weightConcept).value(wt1) .obsDatetime(DateUtil.getDateTime(2015, 6, 1)).save(); Obs o2 = data.obs().person(p1).concept(heightConcept).value(ht1) .obsDatetime(DateUtil.getDateTime(2015, 6, 1)).save(); BmiPatientDataDefinition bmiDefinition = new BmiPatientDataDefinition(); Double actualBmi1 = DataUtil.evaluateForPatient(bmiDefinition, p1.getId(), Double.class); Assert.assertEquals(expectedBmi1, actualBmi1); }