List of usage examples for java.lang Math pow
@HotSpotIntrinsicCandidate public static double pow(double a, double b)
From source file:com.exzogeni.dk.graphics.Bitmaps.java
public static int calculateInSampleSize(BitmapFactory.Options ops, int hwSize) { final int outHeight = ops.outHeight; final int outWidth = ops.outWidth; if (outWidth > hwSize || outHeight > hwSize) { final double ratio = Math.max(Math.round((double) outWidth / (double) hwSize), Math.round((double) outHeight / (double) hwSize)); return ratio > 0 ? (int) Math.pow(2, Math.floor(Math.log(ratio) / LN_2)) : 1; }//from ww w . ja v a 2s . com return 1; }
From source file:libra.preprocess.stage2.KmerIndexBuilderReducer.java
@Override protected void reduce(CompressedSequenceWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException { int frequency = 0; for (IntWritable value : values) { frequency += value.get();//from ww w . jav a 2s. c o m } // compute base if (frequency > 0) { this.logTFSquareCounter.increment((long) (Math.pow(1 + Math.log10(frequency), 2) * 1000)); } context.write(key, new IntWritable(frequency)); }
From source file:org.openmrs.module.reportingdemo.definition.data.evaluator.BmiPatientDataDefinitionEvaluator.java
@Override public EvaluatedPatientData evaluate(PatientDataDefinition definition, EvaluationContext context) throws EvaluationException { EvaluatedPatientData pd = new EvaluatedPatientData(definition, context); Map<Integer, Object> wts = evaluateObs(demoPatientData.getLatestWeight(), context); Map<Integer, Object> hts = evaluateObs(demoPatientData.getLatestHeight(), context); for (Integer pId : wts.keySet()) { Double wt = (Double) wts.get(pId); Double ht = (Double) hts.get(pId); if (wt != null && ht != null) { double bmi = wt / Math.pow(ht / 100, 2); pd.addData(pId, bmi);/* w w w . j a va 2s . c o m*/ } } return pd; }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.indicator.Spacing.java
/** * Computes the spread metric for the specified problem given an * approximation set./*from www . j a v a 2 s . c o m*/ * * @param problem the problem * @param approximationSet an approximation set for the problem * @return the spread metric for the specified problem given an * approximation set */ static double evaluate(Problem problem, NondominatedPopulation approximationSet) { if (approximationSet.size() < 2) { return 0.0; } double[] d = new double[approximationSet.size()]; for (int i = 0; i < approximationSet.size(); i++) { double min = Double.POSITIVE_INFINITY; Solution solutionI = approximationSet.get(i); if (solutionI.violatesConstraints()) { continue; } for (int j = 0; j < approximationSet.size(); j++) { if (i != j) { Solution solutionJ = approximationSet.get(j); if (solutionJ.violatesConstraints()) { continue; } min = Math.min(min, IndicatorUtils.manhattanDistance(problem, solutionI, solutionJ)); } } d[i] = min; } double dbar = StatUtils.sum(d) / approximationSet.size(); double sum = 0.0; for (int i = 0; i < approximationSet.size(); i++) { if (approximationSet.get(i).violatesConstraints()) { continue; } sum += Math.pow(d[i] - dbar, 2.0); } return Math.sqrt(sum / (approximationSet.size() - 1)); }
From source file:Circle.java
public static int flatDistance(Position a, Position b) { return (int) Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2)); }
From source file:Methods.CalculusNewtonRaphson.java
public static void newtonRaphson2(double xold, double decPoint) {//method used calculate root point acording the paramethers that enter the method and store the data in a global paramether linked list double xnew, fxold, fxnew, fdashxold, diff; int iteration; iteration = 0;/*www. j a va 2 s .co m*/ xNewLinkedList.head = null;//Clearing the linked list before using it xLinkedList.head = null; do { iteration += 1; fxold = (Math.log(Math.abs(xold + 1.0))) + 1.0; fdashxold = (1.0 / (xold + 1.0)); xnew = xold - (fxold / fdashxold); fxnew = xnew - Math.pow(xnew, 2.0); System.out.println("Approx for iteration{}" + iteration + " is " + xnew); if (iteration == 1) {//Block used to insert data in the linked list xNewLinkedList.addFirst(xold, fxold, iteration); xLinkedList.addFirst(xnew, fxnew, iteration); } else { xNewLinkedList.addMid(xold, fxold, iteration, iteration - 1); xLinkedList.addMid(xnew, fxnew, iteration, iteration - 1); } diff = Math.abs(xnew - xold); xold = xnew; } while (diff > decPoint); xNewLinkedList.addMid(xnew, 0.0, iteration + 1, iteration);//Block used to insert data in the linked list xLinkedList.addMid(xnew, 0.0, iteration + 1, iteration); System.out.println("root to six decimal places is " + xnew); }
From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.SABRATMVolatilityCalculator.java
/** * Finds the alpha that gives the required ATM volatility * @param data SABR parameters - the alpha value is ignored * @param option The option/*from w w w .j a v a 2 s. c o m*/ * @param forward the forward * @param atmVol The ATM volatility * @return the value of alpha */ public double calculate(final SABRFormulaData data, final EuropeanVanillaOption option, final double forward, final double atmVol) { Validate.notNull(data, "data"); Validate.notNull(option, "option"); Validate.isTrue(atmVol > 0, "ATM vol must be > 0"); final Function1D<Double, Double> f = new Function1D<Double, Double>() { @SuppressWarnings("synthetic-access") @Override public Double evaluate(final Double alpha) { final SABRFormulaData newData = new SABRFormulaData(alpha, data.getBeta(), data.getRho(), data.getNu()); return _sabrFormula.getVolatilityFunction(option, forward).evaluate(newData) - atmVol; } }; final double alphaTry = atmVol * Math.pow(forward, 1 - data.getBeta()); final double[] range = _bracketer.getBracketedPoints(f, alphaTry / 2.0, 2 * alphaTry); return _rootFinder.getRoot(f, range[0], range[1]); }
From source file:org.amplafi.flow.strategies.CombinationsStrategy.java
/** * Generates a test for an activity.//from ww w.ja va 2 s. c o m * * @param flow * - flow name * @param activityDefinition * - JSON object * @param requestUriString * - base request url * @throws GenerationException * if problem occurs */ @Override public void generateTestForActivity(String flow, String key, JSONObject activityDefinition, FarReachesServiceInfo requestUriString) throws GenerationException { assertNotNull(activityDefinition, "flowDefinition was null, The test should depend on" + " testJsonStringIsReturnedWhenRequestingTheFlowDefinition() does it?"); Collection<String> parameterNames = getAllParameterNames(activityDefinition); // How many combinations of being present or not are there? // should be 2^parameterNames.size() int totalCombinations = (int) Math.pow(2, parameterNames.size()); totalCombinations = (totalCombinations > MAX_GENERATED_COMBINATIONS ? MAX_GENERATED_COMBINATIONS : totalCombinations); // Enumerate those combinations. for (int combination = 0; combination < totalCombinations; combination++) { Collection<String> thisTestParams = new ArrayList<String>(); // loop over the available param names and decide whether to include // them. // for example combination 5 is 101 in binary so include the 1st and // the 3rd parameter // but not the second. int order = 1; for (String pname : parameterNames) { if ((combination & order) == order) { thisTestParams.add(pname); } order *= 2; } // Generate request for this combination. Collection<NameValuePair> parametersPopulatedWithBogusData = generateParameters(flow, thisTestParams); // add the json response parameter parametersPopulatedWithBogusData.add(RENDER_AS_JSON); addRequest(flow, parametersPopulatedWithBogusData); // callFlowForTypicalData(requestUriString, flow, // parametersPopulatedWithBogusData ) addVerification(""); } }
From source file:GeMSE.GS.Analysis.Clustering.DistanceMatrix.java
public double[][] GetDistanceMatrix(double[][] space, Metrics metric, ClusteringDomains clusteringDomain) { euclideanDistance = new EuclideanDistance(); manhattanDistance = new ManhattanDistance(); earthMoversDistance = new EarthMoversDistance(); chebyshevDistance = new ChebyshevDistance(); canberraDistance = new CanberraDistance(); double[][] rtv = null; int rowCount = space.length; int colCount = space[0].length; int rtvIndex = 0; switch (clusteringDomain) { case Rows:// ww w . j a v a 2 s . c o m rtv = new double[1][(int) Math.floor((Math.pow(rowCount, 2) - rowCount) / 2f)]; for (int i = 0; i < rowCount - 1; i++) for (int j = i + 1; j < rowCount; j++) // TODO: replace the following mess with the factory method. switch (metric) { case EuclideanDistance: rtv[0][rtvIndex++] = euclideanDistance.compute(space[i], space[j]); break; case ManhattanDistance: rtv[0][rtvIndex++] = manhattanDistance.compute(space[i], space[j]); break; case EarthMoversDistance: rtv[0][rtvIndex++] = earthMoversDistance.compute(space[i], space[j]); break; case ChebyshevDistance: rtv[0][rtvIndex++] = chebyshevDistance.compute(space[i], space[j]); break; case CanberraDistance: rtv[0][rtvIndex++] = canberraDistance.compute(space[i], space[j]); break; case PearsonCorrelationCoefficient: rtv[0][rtvIndex++] = ComputePCC(space[i], space[j]); break; } break; case Columns: rtv = new double[1][(int) Math.floor((Math.pow(colCount, 2) - colCount) / 2f)]; double[] col_i = new double[rowCount]; double[] col_j = new double[rowCount]; for (int i = 0; i < colCount - 1; i++) { for (int j = i + 1; j < colCount; j++) { for (int row = 0; row < rowCount; row++) { col_i[row] = space[row][i]; col_j[row] = space[row][j]; } // TODO: Replace the following mess with the factory pattern. switch (metric) { case EuclideanDistance: rtv[0][rtvIndex++] = euclideanDistance.compute(col_i, col_j); break; case ManhattanDistance: rtv[0][rtvIndex++] = manhattanDistance.compute(col_i, col_j); break; case EarthMoversDistance: rtv[0][rtvIndex++] = earthMoversDistance.compute(col_i, col_j); break; case ChebyshevDistance: rtv[0][rtvIndex++] = chebyshevDistance.compute(col_i, col_j); break; case CanberraDistance: rtv[0][rtvIndex++] = canberraDistance.compute(col_i, col_j); break; case PearsonCorrelationCoefficient: rtv[0][rtvIndex++] = ComputePCC(col_i, col_j); break; } } } break; } return rtv; }