當前位置: 首頁>>代碼示例>>Java>>正文


Java FastMath.sqrt方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.util.FastMath.sqrt方法的典型用法代碼示例。如果您正苦於以下問題:Java FastMath.sqrt方法的具體用法?Java FastMath.sqrt怎麽用?Java FastMath.sqrt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.util.FastMath的用法示例。


在下文中一共展示了FastMath.sqrt方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertFromGeoToEarthCentred

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * 
 * @param lat
 * @param lon
 * @return
 */
public static double[] convertFromGeoToEarthCentred(final double lat, final double lon){
	double pH=GeoUtils.getGeoidH(lon, lat);
	
	double radLat=FastMath.toRadians(lat);
	double radLon=FastMath.toRadians(lon);
	
	// Convert from geographic coordinates to Earth centred Earth fixed coordinates
	double cosLat=FastMath.cos(radLat);
	double sinLat = FastMath.sin(radLat);
	double cosLon =FastMath.cos(radLon);
	double sinLon = FastMath.sin(radLon);
	
	double denomTmp = FastMath.sqrt((semiMajorAxis2) *(cosLat*cosLat) + (semiMinorAxis2)*(sinLat*sinLat));
	
	double pX = (semiMajorAxis2/denomTmp + pH) * cosLat * cosLon;
	double pY = (semiMajorAxis2/denomTmp + pH) * cosLat * sinLon;
	double pZ = (semiMinorAxis2/denomTmp + pH) * sinLat;
	
	double[] pXYZ = {pX ,pY, pZ};
	//double[] pXYZ = {4740162.032532615 , 787287.082659188, 4180253.542739194};
	return pXYZ;
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:29,代碼來源:GeoUtils.java

示例2: gcpIncidenceAngleForGRD

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 *			 ( Parameters have the names used in radarsat2 metadata )
 *
 * @param complex
 * @param gndRange 
 * @param samplePixelSpacing
 * @param ngrd
 * @param nsam
 * @return
 */
public static double gcpIncidenceAngleForGRD(double slntRangeInNearRange,double sizeXPixel,double samplePixelSpacing,double xPix,double hsat,double earthRad,String timeOrdering){
	double srAndIA=0;
	//convert slant range into grnd range 
	double gndRangeAtNearRange=earthRad*FastMath.acos(1-(slntRangeInNearRange*slntRangeInNearRange-hsat*hsat)/(2*earthRad*(earthRad+hsat))  );
	double gndRangePixel=0;
	
	double gndRangeAtFarRange=gndRangeAtNearRange+sizeXPixel*samplePixelSpacing;
	
	if(timeOrdering.equalsIgnoreCase("Increasing")){		
		//calculate the gnd range for the gpc
		gndRangePixel=gndRangeAtNearRange+xPix*samplePixelSpacing;
	}else{
		gndRangePixel=gndRangeAtFarRange-xPix*samplePixelSpacing;
	}
	//slant range
	double finalSlantRange=FastMath.sqrt(hsat*hsat + (2*earthRad*(earthRad+hsat))*(1-FastMath.cos(gndRangePixel/earthRad)));

	//incidence angle
	srAndIA=FastMath.acos((hsat*(1+hsat/(2*earthRad))/finalSlantRange) - (finalSlantRange/(2*earthRad)));			
	
	//double conv=srAndIA*180/Math.PI;
	//System.out.println(conv);
	return srAndIA;
	
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:36,代碼來源:GeoUtils.java

示例3: getResult

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Returns the value of the statistic based on the values that have been added.
 * <p>
 * See {@link Skewness} for the definition used in the computation.</p>
 *
 * @return the skewness of the available values.
 */
@Override
public double getResult() {

    if (moment.n < 3) {
        return Double.NaN;
    }
    double variance = moment.m2 / (moment.n - 1);
    if (variance < 10E-20) {
        return 0.0d;
    } else {
        double n0 = moment.getN();
        return  (n0 * moment.m3) /
        ((n0 - 1) * (n0 -2) * FastMath.sqrt(variance) * variance);
    }
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:23,代碼來源:Skewness.java

示例4: getSquareRoot

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Computes the square-root of the matrix.
 * This implementation assumes that the matrix is symmetric and positive
 * definite.
 *
 * @return the square-root of the matrix.
 * @throws MathUnsupportedOperationException if the matrix is not
 * symmetric or not positive definite.
 * @since 3.1
 */
public RealMatrix getSquareRoot() {
    if (!isSymmetric) {
        throw new MathUnsupportedOperationException();
    }

    final double[] sqrtEigenValues = new double[realEigenvalues.length];
    for (int i = 0; i < realEigenvalues.length; i++) {
        final double eigen = realEigenvalues[i];
        if (eigen <= 0) {
            throw new MathUnsupportedOperationException();
        }
        sqrtEigenValues[i] = FastMath.sqrt(eigen);
    }
    final RealMatrix sqrtEigen = MatrixUtils.createRealDiagonalMatrix(sqrtEigenValues);
    final RealMatrix v = getV();
    final RealMatrix vT = getVT();

    return v.multiply(sqrtEigen).multiply(vT);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:30,代碼來源:EigenDecomposition.java

示例5: createInterval

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
public ConfidenceInterval createInterval(int numberOfTrials, int numberOfSuccesses, double confidenceLevel) {
    IntervalUtils.checkParameters(numberOfTrials, numberOfSuccesses, confidenceLevel);
    final double alpha = (1.0 - confidenceLevel) / 2;
    final NormalDistribution normalDistribution = new NormalDistribution();
    final double z = normalDistribution.inverseCumulativeProbability(1 - alpha);
    final double zSquared = FastMath.pow(z, 2);
    final double mean = (double) numberOfSuccesses / (double) numberOfTrials;

    final double factor = 1.0 / (1 + (1.0 / numberOfTrials) * zSquared);
    final double modifiedSuccessRatio = mean + (1.0 / (2 * numberOfTrials)) * zSquared;
    final double difference = z *
                              FastMath.sqrt(1.0 / numberOfTrials * mean * (1 - mean) +
                                            (1.0 / (4 * FastMath.pow(numberOfTrials, 2)) * zSquared));

    final double lowerBound = factor * (modifiedSuccessRatio - difference);
    final double upperBound = factor * (modifiedSuccessRatio + difference);
    return new ConfidenceInterval(lowerBound, upperBound, confidenceLevel);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:20,代碼來源:WilsonScoreInterval.java

示例6: nextGaussian

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Returns the next pseudorandom, Gaussian ("normally") distributed
 * {@code double} value with mean {@code 0.0} and standard
 * deviation {@code 1.0} from this random number generator's sequence.
 * <p>
 * The default implementation uses the <em>Polar Method</em>
 * due to G.E.P. Box, M.E. Muller and G. Marsaglia, as described in
 * D. Knuth, <u>The Art of Computer Programming</u>, 3.4.1C.</p>
 * <p>
 * The algorithm generates a pair of independent random values.  One of
 * these is cached for reuse, so the full algorithm is not executed on each
 * activation.  Implementations that do not override this method should
 * make sure to call {@link #clear} to clear the cached value in the
 * implementation of {@link #setSeed(long)}.</p>
 *
 * @return  the next pseudorandom, Gaussian ("normally") distributed
 * {@code double} value with mean {@code 0.0} and
 * standard deviation {@code 1.0} from this random number
 *  generator's sequence
 */
public double nextGaussian() {
    if (!Double.isNaN(cachedNormalDeviate)) {
        double dev = cachedNormalDeviate;
        cachedNormalDeviate = Double.NaN;
        return dev;
    }
    double v1 = 0;
    double v2 = 0;
    double s = 1;
    while (s >=1 ) {
        v1 = 2 * nextDouble() - 1;
        v2 = 2 * nextDouble() - 1;
        s = v1 * v1 + v2 * v2;
    }
    if (s != 0) {
        s = FastMath.sqrt(-2 * FastMath.log(s) / s);
    }
    cachedNormalDeviate = v2 * s;
    return v1 * s;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:41,代碼來源:AbstractRandomGenerator.java

示例7: earthRadiusFromLatitude

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * 
 * @param latitude
 * @param ellipseMin 
 * @param ellipseMaj
 * @return calculate the heart radius for a latitude
 */
public static double earthRadiusFromLatitude(double latitude, double ellipseMin,double ellipseMaj ){
	double tan=FastMath.tan(latitude*FastMath.PI/180);
	double ellipseRapp=(ellipseMin/ellipseMaj)*(ellipseMin/ellipseMaj);
	double d=tan*tan;//FastMath.pow(FastMath.tan(latitude*FastMath.PI/180),2);
	double reEarth=ellipseMin*FastMath.sqrt((1+d)/((ellipseRapp*ellipseRapp)+d));
	
	return reEarth;
	
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:17,代碼來源:GeoUtils.java

示例8: estBetaDist

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
public static double[] estBetaDist(double[] betaValues) {
	Mean mean = new Mean();
	double mu = mean.evaluate(betaValues,0,betaValues.length);
	Variance variance = new Variance();
	double var = variance.evaluate(betaValues, mu);
	double alpha = -mu*(var+mu*mu-mu)/var;
	double beta = (mu-1)*(var+mu*mu-mu)/var;
	return new double[] {alpha, beta, mu, FastMath.sqrt(var)};
}
 
開發者ID:jasminezhoulab,項目名稱:CancerLocator,代碼行數:10,代碼來源:MethyModel.java

示例9: regcf

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * The regcf method conducts the linear regression and extracts the
 * parameter vector. Notice that the algorithm can do subset regression
 * with no alteration.
 *
 * @param nreq how many of the regressors to include (either in canonical
 * order, or in the current reordered state)
 * @return an array with the estimated slope coefficients
 * @throws ModelSpecificationException if {@code nreq} is less than 1
 * or greater than the number of independent variables
 */
private double[] regcf(int nreq) throws ModelSpecificationException {
    int nextr;
    if (nreq < 1) {
        throw new ModelSpecificationException(LocalizedFormats.NO_REGRESSORS);
    }
    if (nreq > this.nvars) {
        throw new ModelSpecificationException(
                LocalizedFormats.TOO_MANY_REGRESSORS, nreq, this.nvars);
    }
    if (!this.tol_set) {
        tolset();
    }
    final double[] ret = new double[nreq];
    boolean rankProblem = false;
    for (int i = nreq - 1; i > -1; i--) {
        if (FastMath.sqrt(d[i]) < tol[i]) {
            ret[i] = 0.0;
            d[i] = 0.0;
            rankProblem = true;
        } else {
            ret[i] = rhs[i];
            nextr = i * (nvars + nvars - i - 1) / 2;
            for (int j = i + 1; j < nreq; j++) {
                ret[i] = smartAdd(ret[i], -r[nextr] * ret[j]);
                ++nextr;
            }
        }
    }
    if (rankProblem) {
        for (int i = 0; i < nreq; i++) {
            if (this.lindep[i]) {
                ret[i] = Double.NaN;
            }
        }
    }
    return ret;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:49,代碼來源:MillerUpdatingRegression.java

示例10: getFrobeniusNorm

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public double getFrobeniusNorm() {
    double sum2 = 0;
    for (int blockIndex = 0; blockIndex < blocks.length; ++blockIndex) {
        for (final double entry : blocks[blockIndex]) {
            sum2 += entry * entry;
        }
    }
    return FastMath.sqrt(sum2);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:12,代碼來源:BlockRealMatrix.java

示例11: errorEstimation

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Estimate error.
 * <p>
 * Error is estimated by interpolating back to previous state using
 * the state Taylor expansion and comparing to real previous state.
 * </p>
 * @param previousState state vector at step start
 * @param predictedState predicted state vector at step end
 * @param predictedScaled predicted value of the scaled derivatives at step end
 * @param predictedNordsieck predicted value of the Nordsieck vector at step end
 * @return estimated normalized local discretization error
 */
private double errorEstimation(final double[] previousState,
                               final double[] predictedState,
                               final double[] predictedScaled,
                               final RealMatrix predictedNordsieck) {

    double error = 0;
    for (int i = 0; i < mainSetDimension; ++i) {
        final double yScale = FastMath.abs(predictedState[i]);
        final double tol = (vecAbsoluteTolerance == null) ?
                           (scalAbsoluteTolerance + scalRelativeTolerance * yScale) :
                           (vecAbsoluteTolerance[i] + vecRelativeTolerance[i] * yScale);

        // apply Taylor formula from high order to low order,
        // for the sake of numerical accuracy
        double variation = 0;
        int sign = predictedNordsieck.getRowDimension() % 2 == 0 ? -1 : 1;
        for (int k = predictedNordsieck.getRowDimension() - 1; k >= 0; --k) {
            variation += sign * predictedNordsieck.getEntry(k, i);
            sign       = -sign;
        }
        variation -= predictedScaled[i];

        final double ratio  = (predictedState[i] - previousState[i] + variation) / tol;
        error              += ratio * ratio;

    }

    return FastMath.sqrt(error / mainSetDimension);

}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:42,代碼來源:AdamsBashforthIntegrator.java

示例12: reset

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Reset the instance as if built from two points.
 * @param p1 first point belonging to the line (this can be any point)
 * @param p2 second point belonging to the line (this can be any point, different from p1)
 * @exception MathIllegalArgumentException if the points are equal
 */
public void reset(final Vector3D p1, final Vector3D p2) throws MathIllegalArgumentException {
    final Vector3D delta = p2.subtract(p1);
    final double norm2 = delta.getNormSq();
    if (norm2 == 0.0) {
        throw new MathIllegalArgumentException(LocalizedFormats.ZERO_NORM);
    }
    this.direction = new Vector3D(1.0 / FastMath.sqrt(norm2), delta);
    zero = new Vector3D(1.0, p1, -p1.dotProduct(delta) / norm2, delta);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:15,代碼來源:Line.java

示例13: pointIsBetween

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Check if a point is geometrically between its neighbor in an array.
 * <p>The neighbors are computed considering the array is a loop
 * (i.e. point at index (n-1) is before point at index 0)</p>
 * @param loop points array
 * @param n number of points to consider in the array
 * @param i index of the point to check (must be between 0 and n-1)
 * @return true if the point is exactly between its neighbors
 */
private boolean pointIsBetween(final Vector2D[] loop, final int n, final int i) {
    final Vector2D previous = loop[(i + n - 1) % n];
    final Vector2D current  = loop[i];
    final Vector2D next     = loop[(i + 1) % n];
    final double dx1       = current.getX() - previous.getX();
    final double dy1       = current.getY() - previous.getY();
    final double dx2       = next.getX()    - current.getX();
    final double dy2       = next.getY()    - current.getY();
    final double cross     = dx1 * dy2 - dx2 * dy1;
    final double dot       = dx1 * dx2 + dy1 * dy2;
    final double d1d2      = FastMath.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2));
    return (FastMath.abs(cross) <= (1.0e-6 * d1d2)) && (dot >= 0.0);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:22,代碼來源:OutlineExtractor.java

示例14: estimateError

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/** Estimate interpolation error.
 * @param scale scaling array
 * @return estimate of the interpolation error
 */
public double estimateError(final double[] scale) {
  double error = 0;
  if (currentDegree >= 5) {
    for (int i = 0; i < scale.length; ++i) {
      final double e = polynomials[currentDegree][i] / scale[i];
      error += e * e;
    }
    error = FastMath.sqrt(error / scale.length) * errfac[currentDegree - 5];
  }
  return error;
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:16,代碼來源:GraggBulirschStoerStepInterpolator.java

示例15: Cholesky

import org.apache.commons.math3.util.FastMath; //導入方法依賴的package包/類
/**
 * Calculates the Cholesky decomposition of the given matrix.
 * @param matrix the matrix to decompose
 * @param relativeSymmetryThreshold threshold above which off-diagonal
 * elements are considered too different and matrix not symmetric
 * @param absolutePositivityThreshold threshold below which diagonal
 * elements are considered null and matrix not positive definite
 * @throws NonSquareMatrixException if the matrix is not square.
 * @throws NonSymmetricMatrixException if the matrix is not symmetric.
 * @throws NonPositiveDefiniteMatrixException if the matrix is not
 * strictly positive definite.
 * @see #Cholesky(RealMatrix)
 * @see #DEFAULT_RELATIVE_SYMMETRY_THRESHOLD
 * @see #DEFAULT_ABSOLUTE_POSITIVITY_THRESHOLD
 */
public Cholesky(final RealMatrix matrix,
                                 final double relativeSymmetryThreshold,
                                 final double absolutePositivityThreshold) {
    if (!matrix.isSquare()) {
        throw new NonSquareMatrixException(matrix.getRowDimension(),
                                           matrix.getColumnDimension());
    }

    final int order = matrix.getRowDimension();
    lTData   = matrix.getData();
    cachedL  = null;
    cachedLT = null;

    // check the matrix before transformation
    for (int i = 0; i < order; ++i) {
        final double[] lI = lTData[i];

        // check off-diagonal elements (and reset them to 0)
        for (int j = i + 1; j < order; ++j) {
            final double[] lJ = lTData[j];
            final double lIJ = lI[j];
            final double lJI = lJ[i];
            final double maxDelta =
                relativeSymmetryThreshold * FastMath.max(FastMath.abs(lIJ), FastMath.abs(lJI));
            if (FastMath.abs(lIJ - lJI) > maxDelta) {
              //double mean = .5*(lIJ+lJI);
              //lTData[j][i] = lTData[i][j] = mean;
              System.out.print("entries: "+lIJ+" "+lJI);
                throw new NonSymmetricMatrixException(i, j, relativeSymmetryThreshold);
            }
            lJ[i] = 0;
       }
    }

    // transform the matrix
    for (int i = 0; i < order; ++i) {

        final double[] ltI = lTData[i];

        // check diagonal element
        if (ltI[i] <= absolutePositivityThreshold) {
            throw new NonPositiveDefiniteMatrixException(ltI[i], i, absolutePositivityThreshold);
        }

        ltI[i] = FastMath.sqrt(ltI[i]);
        final double inverse = 1.0 / ltI[i];

        for (int q = order - 1; q > i; --q) {
            ltI[q] *= inverse;
            final double[] ltQ = lTData[q];
            for (int p = q; p < order; ++p) {
                ltQ[p] -= ltI[q] * ltI[p];
            }
        }
    }
}
 
開發者ID:BigBayes,項目名稱:BNPMix.java,代碼行數:72,代碼來源:Cholesky.java


注:本文中的org.apache.commons.math3.util.FastMath.sqrt方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。