List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:ch.algotrader.option.SABR.java
/** * Perfors a SABR calibartion based on specified volatilities. * * @return SABRSmileVO The SABR smile//from w w w . ja va 2 s .c o m */ public static SABRSmileVO calibrate(final Double[] strikes, final Double[] volatilities, final double atmVol, final double forward, final double years) throws SABRException { MultivariateRealFunction estimateRhoAndVol = x -> { double r = x[0]; double v = x[1]; double alpha = findAlpha(forward, forward, atmVol, years, beta, x[0], x[1]); double sumErrors = 0; for (int i = 0; i < volatilities.length; i++) { double modelVol = vol(forward, strikes[i], years, alpha, beta, r, v); sumErrors += Math.pow(modelVol - volatilities[i], 2); } if (Math.abs(r) > 1) { sumErrors = 1e100; } return sumErrors; }; NelderMead nelderMead = new NelderMead(); RealPointValuePair result; try { result = nelderMead.optimize(estimateRhoAndVol, GoalType.MINIMIZE, new double[] { -0.5, 2.6 }); } catch (MathException ex) { throw new SABRException(ex.getMessage(), ex); } double rho = result.getPoint()[0]; double volVol = result.getPoint()[1]; SABRSmileVO params = new SABRSmileVO(); params.setYears(years); params.setRho(rho); params.setVolVol(volVol); params.setAlpha(findAlpha(forward, forward, atmVol, years, beta, rho, volVol)); params.setAtmVol(atmVol); return params; }
From source file:com.opengamma.strata.math.impl.function.special.OrthonormalHermitePolynomialFunctionTest.java
@Test public void test() { final int n = 15; final DoubleFunction1D[] f1 = HERMITE.getPolynomials(n); final DoubleFunction1D[] f2 = ORTHONORMAL.getPolynomials(n); final double x = 3.4; for (int i = 0; i < f1.length; i++) { assertEquals(/*from w w w . ja v a2 s . c o m*/ f1[i].applyAsDouble(x) / Math .sqrt(CombinatoricsUtils.factorialDouble(i) * Math.pow(2, i) * Math.sqrt(Math.PI)), f2[i].applyAsDouble(x), EPS); } }
From source file:com.wormsim.tracking.ConstantDoubleInstance.java
@Override public double getOverallSquareMean() { return Math.pow(((ConstantDouble) parent).value, 2); }
From source file:IK.G.java
public static double dist(double x1, double y1, double x2, double y2) { return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); }
From source file:com.opengamma.analytics.math.statistics.descriptive.SampleMomentCalculator.java
/** * @param x The array of data, not null or empty * @return The sample raw moment/*from ww w . ja v a2 s.co m*/ */ @Override public Double evaluate(final double[] x) { Validate.notNull(x, "x was null"); Validate.isTrue(x.length > 0, "x was empty"); if (_n == 0) { return 1.; } double sum = 0; for (final Double d : x) { sum += Math.pow(d, _n); } return sum / (x.length - 1); }
From source file:Number.java
/** * Round a float to the specified number of decimal places. * /* w ww . ja v a 2s . c o m*/ * @param value * The value to round. * @param places * The number of decimal points. * @return The rounded value as a float. */ public static float Round(float value, int places) { float p = (float) Math.pow(10, places); value = value * p; float tmp = Math.round(value); return (float) tmp / p; }
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
/** * zeropads a long without throwing an ISOException (performs modulus operation) * * @param l the long//from w ww . j a va2 s . com * @param len the length * @return zeropadded value */ public static String zeropad(long l, int len) { try { return padleft(Long.toString((long) (l % Math.pow(10, len))), len, '0'); } catch (Exception ignored) { } return null; // should never happen }
From source file:com.opengamma.strata.math.impl.function.RealPolynomialFunction1DTest.java
@Test public void testDerivative() { final double x = RANDOM.nextDouble(); assertEquals(3 * C[3] * Math.pow(x, 2) + 2 * C[2] * x + C[1], F.derivative().applyAsDouble(x), EPS); }
From source file:lsafunctions.LSA.java
private static RealMatrix normalizeMatrix(RealMatrix M) { double sumColumn = 0; // Matrix row = new Matrix(1, M.getColumnDimension()); RealMatrix row = MatrixUtils.createRealMatrix(1, M.getColumnDimension()); for (int j = 0; j < M.getColumnDimension(); j++) { sumColumn = 0;// www . ja va 2s . c o m for (int k = 0; k < M.getRowDimension(); k++) { sumColumn += Math.pow(M.getEntry(k, j), 2); } sumColumn = Math.sqrt(sumColumn); row.setEntry(0, j, sumColumn); } for (int j = 0; j < M.getColumnDimension(); j++) { for (int k = 0; k < M.getRowDimension(); k++) { M.setEntry(k, j, M.getEntry(k, j) / row.getEntry(0, j)); } } return M; }