当前位置: 首页>>代码示例>>Java>>正文


Java FastMath.exp方法代码示例

本文整理汇总了Java中org.apache.commons.math.util.FastMath.exp方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.exp方法的具体用法?Java FastMath.exp怎么用?Java FastMath.exp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math.util.FastMath的用法示例。


在下文中一共展示了FastMath.exp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gradient

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Computes the value of the gradient at {@code x}.
 * The components of the gradient vector are the partial
 * derivatives of the function with respect to each of the
 * <em>parameters</em>.
 *
 * @param x Value at which the gradient must be computed.
 * @param param Values for {@code k}, {@code m}, {@code b}, {@code q},
 * {@code a} and  {@code n}.
 * @return the gradient vector at {@code x}.
 * @throws NullArgumentException if {@code param} is {@code null}.
 * @throws DimensionMismatchException if the size of {@code param} is
 * not 6.
 */
public double[] gradient(double x, double ... param) {
    validateParameters(param);

    final double b = param[2];
    final double q = param[3];

    final double mMinusX = param[1] - x;
    final double oneOverN = 1 / param[5];
    final double exp = FastMath.exp(b * mMinusX);
    final double qExp = q * exp;
    final double qExp1 = qExp + 1;
    final double factor1 = (param[0] - param[4]) * oneOverN / FastMath.pow(qExp1, oneOverN);
    final double factor2 = -factor1 / qExp1;

    // Components of the gradient.
    final double gk = Logistic.value(mMinusX, 1, b, q, 0, oneOverN);
    final double gm = factor2 * b * qExp;
    final double gb = factor2 * mMinusX * qExp;
    final double gq = factor2 * exp;
    final double ga = Logistic.value(mMinusX, 0, b, q, 1, oneOverN);
    final double gn = factor1 * Math.log(qExp1) * oneOverN;

    return new double[] { gk, gm, gb, gq, ga, gn };
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:Logistic.java

示例2: value

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] value(double[] variables) {
  double x01 = variables[0];
  double x02 = variables[1];
  double x03 = variables[2];
  double x04 = variables[3];
  double x05 = variables[4];
  double x06 = variables[5];
  double x07 = variables[6];
  double x08 = variables[7];
  double x09 = variables[8];
  double x10 = variables[9];
  double x11 = variables[10];
  double[] f = new double[m];
  for (int i = 0; i < m; ++i) {
    double temp = i / 10.0;
    double tmp1 = FastMath.exp(-x05 * temp);
    double tmp2 = FastMath.exp(-x06 * (temp - x09) * (temp - x09));
    double tmp3 = FastMath.exp(-x07 * (temp - x10) * (temp - x10));
    double tmp4 = FastMath.exp(-x08 * (temp - x11) * (temp - x11));
    f[i] = y[i] - (x01 * tmp1 + x02 * tmp2 + x03 * tmp3 + x04 * tmp4);
  }
  return f;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:MinpackTest.java

示例3: testParametricGradient

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testParametricGradient() {
    final double norm = 2;
    final double mean = 3;
    final double sigma = 4;
    final Gaussian.Parametric f = new Gaussian.Parametric();

    final double x = 1;
    final double[] grad = f.gradient(1, new double[] {norm, mean, sigma});
    final double diff = x - mean;
    final double n = FastMath.exp(-diff * diff / (2 * sigma * sigma));
    Assert.assertEquals(n, grad[0], EPS);
    final double m = norm * n * diff / (sigma * sigma);
    Assert.assertEquals(m, grad[1], EPS);
    final double s = m * diff / sigma;
    Assert.assertEquals(s, grad[2], EPS);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:GaussianTest.java

示例4: value

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] value(double[] variables) {
  double x1 = variables[0];
  double x2 = variables[1];
  double x3 = variables[2];
  double x4 = variables[3];
  double x5 = variables[4];
  double[] f = new double[m];
  for (int i = 0; i < m; ++i) {
    double temp = 10.0 * i;
    double tmp1 = FastMath.exp(-temp * x4);
    double tmp2 = FastMath.exp(-temp * x5);
    f[i] = y[i] - (x1 + x2 * tmp1 + x3 * tmp2);
  }
  return f;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:MinpackTest.java

示例5: getMass

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the mass associated with the given bin, the middle of the bin.
 *
 * @param bin the bin number
 *
 * @return the mass associated with the given bin
 */
public Double getMass(int bin) {
    if (ppm) {
        return FastMath.exp((scalingFactor * bin) + mzAnchorLog);
    } else {
        return precursorTolerance * (0.5 + bin);
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:15,代码来源:PrecursorMap.java

示例6: cumulativeProbability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For this distribution, {@code X}, this method returns {@code P(X < x)}.
 *
 * @param x Value at which the CDF is evaluated.
 * @return the CDF evaluated at {@code x}.
 */
public double cumulativeProbability(double x) {
    double ret;
    if (x <= 0.0) {
        ret = 0.0;
    } else {
        ret = 1.0 - FastMath.exp(-FastMath.pow(x / scale, shape));
    }
    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:WeibullDistributionImpl.java

示例7: computeTheoreticalState

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Override
public double[] computeTheoreticalState(double t) {
  double t2 = t * t;
  double c = t2 + 2 * (FastMath.exp (-0.5 * t2) - 1);
  for (int i = 0; i < n; ++i) {
    y[i] = c;
  }
  return y;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:TestProblem2.java

示例8: derivative

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public UnivariateRealFunction derivative() {
    return new UnivariateRealFunction() {
        public double value(double x) {
            return FastMath.exp(x);
        }
    };
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:Expm1Function.java

示例9: density

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    final double n = degreesOfFreedom;
    final double nPlus1Over2 = (n + 1) / 2;
    return FastMath.exp(Gamma.logGamma(nPlus1Over2) -
                        0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) -
                        Gamma.logGamma(n/2) - nPlus1Over2 * FastMath.log(1 + x * x /n));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:TDistributionImpl.java

示例10: probability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * For this distribution, {@code X}, this method returns {@code P(X = x)}.
 *
 * @param x Value at which the PMF is evaluated.
 * @return PMF for this distribution.
 */
public double probability(int x) {
    double ret;
    if (x < 0 || x > numberOfTrials) {
        ret = 0.0;
    } else {
        ret = FastMath.exp(SaddlePointExpansion.logBinomialProbability(x,
                numberOfTrials, probabilityOfSuccess,
                1.0 - probabilityOfSuccess));
    }
    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:BinomialDistributionImpl.java

示例11: calculateNumericalVariance

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * The variance is
 * <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code>
 * where <code>Gamma(...)</code> is the Gamma-function
 *
 * @return {@inheritDoc}
 */
@Override
protected double calculateNumericalVariance() {
    final double sh = getShape();
    final double sc = getScale();
    final double mn = getNumericalMean();

    return (sc * sc) *
        FastMath.exp(Gamma.logGamma(1 + (2 / sh))) -
        (mn * mn);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:WeibullDistributionImpl.java

示例12: density

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    final double x0 = x - mean;
    final double x1 = x0 / standardDeviation;
    return FastMath.exp(-0.5 * x1 * x1) / (standardDeviation * SQRT2PI);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:NormalDistributionImpl.java

示例13: derivative

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/** {@inheritDoc} */
public UnivariateRealFunction derivative() {
    return new UnivariateRealFunction() {
        /** {@inheritDoc} */
        public double value(double x) {
            final double exp = FastMath.exp(-x);
            if (Double.isInfinite(exp)) {
                // Avoid returning NaN in case of overflow.
                return 0;
            }
            final double exp1 = 1 + exp;
            return (hi - lo) * exp / (exp1 * exp1);
        }
    };
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:16,代码来源:Sigmoid.java

示例14: convertFromLog

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public void convertFromLog() {
	for (int i = 0; i < vector.length; i++)
		vector[i] = FastMath.exp(vector[i]);
}
 
开发者ID:Scarano,项目名称:Headword,代码行数:5,代码来源:DMVVector.java

示例15: simulateAnnealing

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Simulate Annealing Algorithm.
 *
 * @param solution First Solution of the Algorithm, it's also best solution for beginning.
 * @return bestsolution Found.
 */
public Solution simulateAnnealing(Solution solution) {
    Solution bestSolution = solution;
    Result bestCost = simplex.minimize(solution);
    Solution randomSolution;
    Result randomSolutionCost;
    Solution currentSolution = solution;
    Result currentCost = bestCost.clone();
    int step = (int) nbIterations / 100;
    int progress = 10;
    logger.info("First Cost = " + bestCost);
    double deltaF;
    for (int j = 0; j < 100; j++) {
        for (int i = 0; i < step; i++) {
            randomSolution = generateBetterNeighbour(currentSolution);
            randomSolutionCost = randomSolution.getCost();
            deltaF = currentCost.getCost() - randomSolutionCost.getCost();
            if (deltaF >= 0) {
                currentSolution = randomSolution;
                currentCost = randomSolutionCost;
                if (currentCost.getCost() < bestCost.getCost()) {
                    bestSolution = currentSolution;
                    bestCost = currentCost;
                }
            } else {
                Random random = new Random(System.currentTimeMillis());
                double p = random.nextDouble();
                double exp = FastMath.exp((-deltaF) / temperature);
                if (p <= exp) {
                    currentSolution = randomSolution;
                    currentCost = randomSolutionCost;
                }
            }
        }
        temperature *= mu;
        if (j % progress == 0) {
            int pourcent = j / progress;
            pourcent *= 10;
            StringBuffer stbf = new StringBuffer();
            stbf.append("CSV;").append(temperature).append(";temperature;").append(bestCost.getCost()).append(";bestcost;")
                    .append(pourcent).append("%...");
            logger.info(stbf.toString());
        }
    }
    logger.info("Best Cost :" + bestCost);
    return bestSolution;
}
 
开发者ID:achaussende,项目名称:tp-2D-cutting-stock-problem,代码行数:53,代码来源:SimulatedAnnealing.java


注:本文中的org.apache.commons.math.util.FastMath.exp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。