List of usage examples for java.lang Math sqrt
@HotSpotIntrinsicCandidate public static double sqrt(double a)
From source file:com.opengamma.analytics.financial.model.option.pricing.analytic.formula.NormalPriceFunction.java
@Override public Function1D<NormalFunctionData, Double> getPriceFunction(final EuropeanVanillaOption option) { Validate.notNull(option, "option"); final double strike = option.getStrike(); final double t = option.getTimeToExpiry(); return new Function1D<NormalFunctionData, Double>() { @SuppressWarnings("synthetic-access") @Override//from w ww. j a va 2s.c o m public final Double evaluate(final NormalFunctionData data) { Validate.notNull(data, "data"); final double forward = data.getForward(); final double numeraire = data.getNumeraire(); final double sigma = data.getNormalVolatility(); final double sigmaRootT = sigma * Math.sqrt(t); final int sign = option.isCall() ? 1 : -1; if (sigmaRootT < 1e-16) { final double x = sign * (forward - strike); return (x > 0 ? numeraire * x : 0.0); } final double arg = sign * (forward - strike) / sigmaRootT; return numeraire * (sign * (forward - strike) * NORMAL.getCDF(arg) + sigmaRootT * NORMAL.getPDF(arg)); } }; }
From source file:Estadistica.java
/** * Metodo para calcular r//from www .j a v a 2 s . c o m * param dos listas de valores (xArrayList,ArrayList) * @return el valor de r */ public static double calR(ArrayList<Double> xArrayList, ArrayList<Double> yArrayList) { double cal = 0; cal = xArrayList.size() * multiple(xArrayList, yArrayList) - multiple(xArrayList) * multiple(yArrayList); double minus = 0; minus = xArrayList.size() * multiple(xArrayList, xArrayList) - multiple(xArrayList) * multiple(xArrayList); minus *= yArrayList.size() * multiple(yArrayList, yArrayList) - multiple(yArrayList) * multiple(yArrayList); cal = cal / Math.sqrt(minus); return cal; }
From source file:com.test.zmisc.App.java
public static double standardDeviation(double[] a, double avg) { double aStdDev = 0; for (int i = 0; i < a.length; i++) { double tmp = (a[i] - avg); aStdDev += tmp * tmp;//from ww w .j a v a 2 s . c o m } aStdDev = Math.sqrt(aStdDev / (a.length)); return aStdDev; }
From source file:de.tud.kom.p2psim.impl.overlay.dht.kademlia2.measurement.file.ConfidenceCalculator.java
/** * @return 0: mean, 1: standard deviation, 2: delta (half interval width), * 3: lower bound, 4: upper bound of confidence interval. */// w w w. j a v a 2 s .c om protected static double[] calc(double[] sample, double alpha) { double mean, standardDeviation, delta, ivLow, ivHigh; mean = StatUtils.mean(sample); standardDeviation = Math.sqrt(StatUtils.variance(sample, mean)); delta = ConfidenceInterval.getDeltaBound(standardDeviation, sample.length, alpha); ivLow = mean - delta; ivHigh = mean + delta; return new double[] { mean, standardDeviation, delta, ivLow, ivHigh }; }
From source file:Main.java
public static double transformlat(double lng, double lat) { double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng)); ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 * Math.sin(2.0 * lng * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(lat * pi) + 40.0 * Math.sin(lat / 3.0 * pi)) * 2.0 / 3.0; ret += (160.0 * Math.sin(lat / 12.0 * pi) + 320 * Math.sin(lat * pi / 30.0)) * 2.0 / 3.0; return ret;/*from w ww . j av a 2 s . com*/ }
From source file:com.itemanalysis.psychometrics.factoranalysis.PrincipalComponentsMethod.java
public double estimateParameters() { EigenDecomposition eigen = new EigenDecomposition(R); RealMatrix eigenVectors = eigen.getV().getSubMatrix(0, nVariables - 1, 0, nFactors - 1); double[] ev = new double[nFactors]; for (int i = 0; i < nFactors; i++) { ev[i] = Math.sqrt(eigen.getRealEigenvalue(i)); }/*from w w w . j a va 2s . co m*/ DiagonalMatrix evMatrix = new DiagonalMatrix(ev);//USE Apache version of Diagonal matrix when upgrade to version 3.2 RealMatrix LOAD = eigenVectors.multiply(evMatrix); //rotate factor loadings if (rotationMethod != RotationMethod.NONE) { GPArotation gpa = new GPArotation(); RotationResults results = gpa.rotate(LOAD, rotationMethod); LOAD = results.getFactorLoadings(); } Sum[] colSums = new Sum[nFactors]; Sum[] colSumsSquares = new Sum[nFactors]; for (int j = 0; j < nFactors; j++) { colSums[j] = new Sum(); colSumsSquares[j] = new Sum(); } factorLoading = new double[nVariables][nFactors]; communality = new double[nVariables]; uniqueness = new double[nVariables]; for (int i = 0; i < nVariables; i++) { for (int j = 0; j < nFactors; j++) { factorLoading[i][j] = LOAD.getEntry(i, j); colSums[j].increment(factorLoading[i][j]); colSumsSquares[j].increment(Math.pow(factorLoading[i][j], 2)); communality[i] += Math.pow(factorLoading[i][j], 2); } } //check sign of factor double sign = 1.0; for (int i = 0; i < nVariables; i++) { for (int j = 0; j < nFactors; j++) { if (colSums[j].getResult() < 0) { sign = -1.0; } else { sign = 1.0; } factorLoading[i][j] = factorLoading[i][j] * sign; } uniqueness[i] = 1.0 - communality[i]; } double totSumOfSquares = 0.0; sumsOfSquares = new double[nFactors]; proportionOfExplainedVariance = new double[nFactors]; proportionOfVariance = new double[nFactors]; for (int j = 0; j < nFactors; j++) { sumsOfSquares[j] = colSumsSquares[j].getResult(); totSumOfSquares += sumsOfSquares[j]; } for (int j = 0; j < nFactors; j++) { proportionOfExplainedVariance[j] = sumsOfSquares[j] / totSumOfSquares; proportionOfVariance[j] = sumsOfSquares[j] / nVariables; } return 0.0; }
From source file:com.cloudera.oryx.app.batch.mllib.als.Evaluation.java
/** * Computes root mean squared error of {@link Rating#rating()} versus predicted value. *//*from w w w . jav a2s . c o m*/ static double rmse(MatrixFactorizationModel mfModel, JavaRDD<Rating> testData) { JavaPairRDD<Tuple2<Integer, Integer>, Double> testUserProductValues = testData .mapToPair(rating -> new Tuple2<>(new Tuple2<>(rating.user(), rating.product()), rating.rating())); @SuppressWarnings("unchecked") RDD<Tuple2<Object, Object>> testUserProducts = (RDD<Tuple2<Object, Object>>) (RDD<?>) testUserProductValues .keys().rdd(); JavaRDD<Rating> predictions = testData.wrapRDD(mfModel.predict(testUserProducts)); double mse = predictions .mapToPair(rating -> new Tuple2<>(new Tuple2<>(rating.user(), rating.product()), rating.rating())) .join(testUserProductValues).values().mapToDouble(valuePrediction -> { double diff = valuePrediction._1() - valuePrediction._2(); return diff * diff; }).mean(); return Math.sqrt(mse); }
From source file:de.termininistic.serein.examples.benchmarks.functions.multimodal.SchwefelFunction.java
@Override public double map(RealVector v) { double[] x = v.toArray(); int n = x.length; double fx = 418.9829 * n; for (int i = 0; i < n; i++) { fx += -x[i] * Math.sin((Math.sqrt(Math.abs(x[i])))); }/*w w w . j a v a2s . c o m*/ return fx; }
From source file:hyperheuristics.algorithm.moeadfrrmab.UCBSelector.java
protected double equation(LowLevelHeuristic op, HashMap<String, Double> frr, HashMap<String, Integer> nt, double sumNt) { /* KE LI code//from w w w.j av a 2 s . c o m http://www.cs.cityu.edu.hk/~51888309/code/bandits.zip temp1 = 2 * Math.log(total_usage); temp2 = temp1 / strategy_usage[i]; temp3 = Math.sqrt(temp2); quality[i] = rewards[i] + scale_ * temp3; */ double numerator = 2 * Math.log(((int) sumNt)); double denominator = nt.get(op.getName()); double fraction = numerator / denominator; double sqrt = Math.sqrt(fraction); double frr_value = frr.get(op.getName()); return frr_value + this.C * sqrt; }
From source file:ComplexNumber.java
/** Compute the magnitude of a complex number */ public double magnitude() { return Math.sqrt(x * x + y * y); }