List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:com.datumbox.framework.core.statistics.distributions.ContinuousDistributions.java
/** * Calculates the probability from -INF to X under Student's Distribution * Ported to PHP from Javascript implementation found at http://www.math.ucla.edu/~tom/distributions/tDist.html * // w w w .j av a 2 s. c o m * @param x * @param df * @return */ public static double studentsCdf(double x, int df) { if (df <= 0) { throw new IllegalArgumentException("The degrees of freedom need to be positive."); } double A = df / 2.0; double S = A + 0.5; double Z = df / (df + x * x); double BT = Math.exp(logGamma(S) - logGamma(0.5) - logGamma(A) + A * Math.log(Z) + 0.5 * Math.log(1.0 - Z)); double betacdf; if (Z < (A + 1.0) / (S + 2.0)) { betacdf = BT * betinc(Z, A, 0.5); } else { betacdf = 1 - BT * betinc(1.0 - Z, 0.5, A); } double tcdf; if (x < 0) { tcdf = betacdf / 2.0; } else { tcdf = 1.0 - betacdf / 2.0; } return tcdf; }
From source file:com.datumbox.framework.statistics.distributions.ContinuousDistributions.java
/** * Calculates the probability from -INF to X under Student's Distribution * Ported to PHP from Javascript implementation found at http://www.math.ucla.edu/~tom/distributions/tDist.html * /*from ww w. ja v a2s .c om*/ * @param x * @param df * @return * @throws IllegalArgumentException */ public static double StudentsCdf(double x, int df) throws IllegalArgumentException { if (df <= 0) { throw new IllegalArgumentException(); } double tcdf = 0.0; double A = df / 2.0; double S = A + 0.5; double Z = df / (df + x * x); double BT = Math.exp(LogGamma(S) - LogGamma(0.5) - LogGamma(A) + A * Math.log(Z) + 0.5 * Math.log(1.0 - Z)); double betacdf = 0.0; if (Z < (A + 1.0) / (S + 2.0)) { betacdf = BT * Betinc(Z, A, 0.5); } else { betacdf = 1 - BT * Betinc(1.0 - Z, 0.5, A); } if (x < 0) { tcdf = betacdf / 2.0; } else { tcdf = 1.0 - betacdf / 2.0; } return tcdf; }
From source file:com.itemanalysis.psychometrics.irt.model.IrmGPCM2.java
private double numer(double theta, double[] iparam, int category, double D) { double Zk = 0; double a = iparam[0]; double b = iparam[1]; double[] t = Arrays.copyOfRange(iparam, 2, iparam.length); //first category Zk = D * a * (theta - b);//from www. ja v a2 s . c o m for (int k = 0; k < category; k++) { Zk += D * a * (theta - b + t[k]); } return Math.exp(Zk); }
From source file:lanchester.MultiArena.java
public void step() { int numFoes = forces.size(); if (isMyTurn == null) { isMyTurn = new boolean[numFoes][numFoes]; stanceArray = new int[numFoes][numFoes]; currentFloor = new double[numFoes][numFoes]; for (int i1 = 0; i1 < numFoes; i1++) { int ind1 = forceMap.get(forces.get(i1)); for (int i2 = 0; i2 < numFoes; i2++) { int ind2 = forceMap.get(forces.get(i2)); isMyTurn[i1][i2] = true; if (i1 == i2) { stanceArray[i1][i2] = AthenaConstants.ALLIED_POSTURE; currentFloor[i1][i2] = 0.; } else { stanceArray[i1][i2] = initializeStance(forces.get(i1), forces.get(i2)); setFloor(i1, i2);//w w w . java 2 s.c o m } } } } Array2DRowRealMatrix mat = getMat(); EigenDecomposition eigen = new EigenDecomposition(mat); double det = eigen.getDeterminant(); double[] eVals = eigen.getRealEigenvalues(); // for(int i1=0;i1<eVals.length;i1++){ // System.out.println("eVals["+i1+"] = "+eVals[i1]); // } if (eigen.hasComplexEigenvalues()) { System.out.println("Complex eigenvalues"); for (int i1 = 0; i1 < forces.size(); i1++) { AthenaForce f = forces.get(i1); System.out.println(f.getName() + " has " + f.getForceSize() + " forces remaining"); } } double[] initialNums = getInitialNumbers(forces); Array2DRowRealMatrix eVectors = (Array2DRowRealMatrix) eigen.getV(); LUDecomposition lu = new LUDecomposition(eVectors); double det2 = lu.getDeterminant(); double[] coeffs = new double[numFoes]; for (int i1 = 0; i1 < numFoes; i1++) { Array2DRowRealMatrix tmpMat = (Array2DRowRealMatrix) eVectors.copy(); tmpMat.setColumn(i1, initialNums); LUDecomposition tmpLU = new LUDecomposition(tmpMat); double tmpDet = tmpLU.getDeterminant(); coeffs[i1] = tmpDet / det2; } MultiTimeStep currentStep = new MultiTimeStep(numFoes); currentTime += timeStep; currentStep.setTime(currentTime); for (int i1 = 0; i1 < numFoes; i1++) { double updatedForce = 0.; for (int i2 = 0; i2 < numFoes; i2++) { updatedForce += coeffs[i2] * eVectors.getEntry(i1, i2) * Math.exp(eVals[i2] * timeStep); // updatedForce+=coeffs[i2]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i2]*timeStep); // updatedForce+=coeffs[i1]*eVectors.getEntry(i2, i1)*Math.exp(eVals[i1]*timeStep); } forces.get(i1).updateForce(updatedForce); currentStep.setForceNumber(updatedForce, i1); } history.add(currentStep); // eVectors. // this.currentTime++; // Truncator truncator = new Truncator(); if (true) { // System.out.println("time = " + time); } }
From source file:com.opengamma.analytics.financial.model.finitedifference.ExponentialMeshing.java
@Override public Double evaluate(final Integer i) { Validate.isTrue(i >= 0 && i < getNumberOfPoints(), "i out of range"); if (i == 0) { return _l; }// www.j a v a 2 s . c om if (i == getNumberOfPoints() - 1) { return _r; } //short cut if required point is one of the specified fixed points if (_fpValues != null) { int index = _um.getFixedPointIndex(i); if (index >= 0) { return _fpValues[index]; } } final double z = _um.evaluate(i); if (_linear) { return _theta + _eta * z; } return _theta + _eta * Math.exp(z * _lambda); }
From source file:com.alvermont.terraj.planet.project.MercatorProjection.java
/** * Carry out the projection/*from w ww. j a v a 2s. c o m*/ */ public void project() { setcolours(); final int width = getParameters().getProjectionParameters().getWidth(); final int height = getParameters().getProjectionParameters().getHeight(); final double lat = getParameters().getProjectionParameters().getLatitudeRadians(); final double lon = getParameters().getProjectionParameters().getLongitudeRadians(); final double scale = getParameters().getProjectionParameters().getScale(); final double hgrid = getParameters().getProjectionParameters().getHgrid(); final double vgrid = getParameters().getProjectionParameters().getVgrid(); final boolean doShade = getParameters().getProjectionParameters().isDoShade(); cacheParameters(); colours = new short[width][height]; shades = new short[width][height]; double y; double scale1; double cos2; double theta1; int i; int j; int k; y = Math.sin(lat); y = (1.0 + y) / (1.0 - y); y = 0.5 * Math.log(y); k = (int) ((0.5 * y * width * scale) / Math.PI); progress.progressStart(height, "Generating Terrain"); for (j = 0; j < height; ++j) { // if (debug && ((j % (Height/25)) == 0)) // {fprintf(stderr, "%c", view); fflush(stderr);} progress.progressStep(j); y = (Math.PI * ((2.0 * (j - k)) - height)) / width / scale; y = Math.exp(2. * y); y = (y - 1.) / (y + 1.); scale1 = (scale * width) / height / Math.sqrt(1.0 - (y * y)) / Math.PI; cos2 = Math.sqrt(1.0 - (y * y)); depth = (3 * ((int) (log2(scale1 * height)))) + 3; for (i = 0; i < width; ++i) { theta1 = lon - (0.5 * Math.PI) + ((Math.PI * ((2.0 * i) - width)) / width / scale); colours[i][j] = (short) planet0(Math.cos(theta1) * cos2, y, -Math.sin(theta1) * cos2); if (doShade) { shades[i][j] = shade; } } } progress.progressComplete("Terrain Generated"); if (hgrid != 0.0) { /* draw horizontal gridlines */ for (theta1 = 0.0; theta1 > -90.0; theta1 -= hgrid) ; for (theta1 = theta1; theta1 < 90.0; theta1 += hgrid) { y = Math.sin(Math.toRadians(theta1)); y = (1.0 + y) / (1.0 - y); y = 0.5 * Math.log(y); j = (height / 2) + (int) ((0.5 * y * width * scale) / Math.PI) + k; if ((j >= 0) && (j < height)) { for (i = 0; i < width; ++i) colours[i][j] = BLACK; } } } if (vgrid != 0.0) { /* draw vertical gridlines */ for (theta1 = 0.0; theta1 > -360.0; theta1 -= vgrid) ; for (theta1 = theta1; theta1 < 360.0; theta1 += vgrid) { i = (int) (0.5 * width * (1.0 + ((scale * (Math.toRadians(theta1) - lon)) / Math.PI))); if ((i >= 0) && (i < width)) { for (j = 0; j < height; ++j) colours[i][j] = BLACK; } } } if (doShade) { smoothshades(); } }
From source file:edu.cmu.tetrad.data.MultiGeneralAndersonDarlingTest.java
private void runTest() { int n = data.get(0).size(); double h = 0.0; int numSummed = 0; for (int g = 0; g < data.size(); g++) { List<Double> _data = data.get(g); for (int i = 1; i <= n; i++) { double x1 = _data.get(i - 1); double a1 = Math.log(distributions.get(g).cumulativeProbability(x1)); double x2 = _data.get(n + 1 - i - 1); double a2 = Math.log(1.0 - distributions.get(g).cumulativeProbability(x2)); double k = (2 * i - 1) * (a1 + a2); if (!(Double.isNaN(a1) || Double.isNaN(a2) || Double.isInfinite(a1) || Double.isInfinite(a2))) { h += k;/*from w w w.java 2 s.com*/ numSummed++; } } } System.out.println("n = " + n + " numSummed = " + numSummed); double a = -n - (1.0 / numSummed) * h; double aa = (1 + 0.75 / numSummed + 2.25 / Math.pow(numSummed, 2)) * a; double p; if (aa < 0.2) { p = 1 - Math.exp(-13.436 + 101.14 * aa - 223.73 * aa * aa); } else if (aa < 0.34) { p = 1 - Math.exp(-8.318 + 42.796 * aa - 59.938 * aa * aa); } else if (aa < 0.6) { p = Math.exp(0.9177 - 4.279 * aa - 1.38 * aa * aa); } else { p = Math.exp(1.2937 - 5.709 * aa + 0.0186 * aa * aa); } this.aSquared = a; this.aSquaredStar = aa; this.p = p; }
From source file:org.jfree.data.statistics.Regression.java
/** * Returns the parameters 'a' and 'b' for an equation y = ax^b, fitted to * the data using a power regression equation. The result is returned as * an array, where double[0] --> a, and double[1] --> b. * * @param data the data./*from w w w.jav a 2 s.c o m*/ * * @return The parameters. */ public static double[] getPowerRegression(double[][] data) { int n = data.length; if (n < 2) { throw new IllegalArgumentException("Not enough data."); } double sumX = 0; double sumY = 0; double sumXX = 0; double sumXY = 0; for (int i = 0; i < n; i++) { double x = Math.log(data[i][0]); double y = Math.log(data[i][1]); sumX += x; sumY += y; double xx = x * x; sumXX += xx; double xy = x * y; sumXY += xy; } double sxx = sumXX - (sumX * sumX) / n; double sxy = sumXY - (sumX * sumY) / n; double xbar = sumX / n; double ybar = sumY / n; double[] result = new double[2]; result[1] = sxy / sxx; result[0] = Math.pow(Math.exp(1.0), ybar - result[1] * xbar); return result; }
From source file:com.opengamma.analytics.financial.model.option.pricing.fourier.FourierPricer.java
public double priceFromVol(final BlackFunctionData data, final EuropeanVanillaOption option, final MartingaleCharacteristicExponent ce, final double alpha, final double limitTolerance, final boolean useVarianceReduction) { final double forward = data.getForward(); final double discountFactor = data.getDiscountFactor(); final double t = option.getTimeToExpiry(); final double strike = option.getStrike(); final EuropeanPriceIntegrand integrand = new EuropeanPriceIntegrand(ce, alpha, useVarianceReduction); final EuropeanCallFourierTransform callFourierTransform = new EuropeanCallFourierTransform(ce); final Function1D<ComplexNumber, ComplexNumber> psi = callFourierTransform.getFunction(t); final double xMax = LIMIT_CALCULATOR.solve(psi, alpha, limitTolerance); final double integral = Math.exp(-alpha * Math.log(strike / forward)) * _integrator.integrate(integrand.getFunction(data, option), 0.0, xMax) / Math.PI; final double black = BLACK_PRICE_FUNCTION.getPriceFunction(option).evaluate(data); final double diff = discountFactor * forward * integral; return diff + black; }
From source file:com.itemanalysis.psychometrics.irt.model.IrmPCM.java
/** * Computes the expression for responding in a category. * It is the numerator for the probability of observing a response. * * @param theta person proficiency value * @param category category for which probability is sought * @return expression for responding in category *///w w w. ja v a2 s . com private double numer(double theta, int category) { double Zk = 0; double expZk = 0; double s = 0; //first category Zk = D * (theta - difficulty); for (int k = 0; k < category; k++) { Zk += D * (theta - difficulty - threshold[k]); } return Math.exp(Zk); }