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


Java FastMath.log方法代码示例

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


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

示例1: testLn

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Tests the ln function
 */
public void testLn() {

    for (int i = -100; i <= 100; i++) {
        double x = FastMath.pow(10, i);
        double fastMathResult = FastMath.log(x);
        BigDecimal fastMathResultBD = new BigDecimal(fastMathResult);

        BigDecimal xBD = new BigDecimal(x);
        BigDecimal utilitiesResult = BigFunctions.ln(xBD, mathContext);

        BigDecimal error = utilitiesResult.subtract(fastMathResultBD);

        Assert.assertEquals(-1, error.abs().compareTo(tolerance));
    }

}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:20,代码来源:TestBigFunctions.java

示例2: testLnBD

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Tests the lnBD function
 */
public void testLnBD() {

    for (int i = -100; i <= 100; i++) {
        double x = FastMath.pow(10, i);
        double fastMathResult = FastMath.log(x);
        BigDecimal fastMathResultBD = new BigDecimal(fastMathResult);

        BigDecimal xDB = new BigDecimal(x);
        BigDecimal utilitiesResult = BigFunctions.lnBD(xDB, mathContext);

        BigDecimal error = utilitiesResult.subtract(fastMathResultBD);

        Assert.assertEquals(-1, error.abs().compareTo(tolerance));
    }

}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:20,代码来源:TestBigFunctions.java

示例3: density

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public double density(double x) {
    recomputeZ();
    if (x < 0 || x > 1) {
        return 0;
    } else if (x == 0) {
        if (alpha < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_0_FOR_SOME_ALPHA, alpha, 1, false);
        }
        return 0;
    } else if (x == 1) {
        if (beta < 1) {
            throw new NumberIsTooSmallException(LocalizedFormats.CANNOT_COMPUTE_BETA_DENSITY_AT_1_FOR_SOME_BETA, beta, 1, false);
        }
        return 0;
    } else {
        double logX = FastMath.log(x);
        double log1mX = FastMath.log1p(-x);
        return FastMath.exp((alpha - 1) * logX + (beta - 1) * log1mX - z);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:BetaDistributionImpl.java

示例4: testGradientComponent5

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
@Test
public void testGradientComponent5() {
    final double m = 1.2;
    final double k = 3.4;
    final double a = 2.3;
    final double q = 0.567;
    final double b = -FastMath.log(q);
    final double n = 3.4;

    final Logistic.Parametric f = new Logistic.Parametric();
    
    final double x = m - 1;
    final double qExp1 = 2;

    final double[] gf = f.gradient(x, new double[] {k, m, b, q, a, n});

    Assert.assertEquals((k - a) * FastMath.log(qExp1) / (n * n * FastMath.pow(qExp1, 1 / n)),
                        gf[5], EPS);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:LogisticTest.java

示例5: logBinomialProbability

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Compute the PMF for a binomial distribution using the saddle point
 * expansion.
 *
 * @param x the value at which the probability is evaluated.
 * @param n the number of trials.
 * @param p the probability of success.
 * @param q the probability of failure (1 - p).
 * @return log(p(x)).
 */
static double logBinomialProbability(int x, int n, double p, double q) {
    double ret;
    if (x == 0) {
        if (p < 0.1) {
            ret = -getDeviancePart(n, n * q) - n * p;
        } else {
            ret = n * FastMath.log(q);
        }
    } else if (x == n) {
        if (q < 0.1) {
            ret = -getDeviancePart(n, n * p) - n * q;
        } else {
            ret = n * FastMath.log(p);
        }
    } else {
        ret = getStirlingError(n) - getStirlingError(x) -
              getStirlingError(n - x) - getDeviancePart(x, n * p) -
              getDeviancePart(n - x, n * q);
        double f = (MathUtils.TWO_PI * x * (n - x)) / n;
        ret = -0.5 * FastMath.log(f) + ret;
    }
    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:34,代码来源:SaddlePointExpansion.java

示例6: logGamma

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the natural logarithm of the gamma function &#915;(x).
 *
 * The implementation of this method is based on:
 * <ul>
 * <li><a href="http://mathworld.wolfram.com/GammaFunction.html">
 * Gamma Function</a>, equation (28).</li>
 * <li><a href="http://mathworld.wolfram.com/LanczosApproximation.html">
 * Lanczos Approximation</a>, equations (1) through (5).</li>
 * <li><a href="http://my.fit.edu/~gabdo/gamma.txt">Paul Godfrey, A note on
 * the computation of the convergent Lanczos complex Gamma approximation
 * </a></li>
 * </ul>
 *
 * @param x Value.
 * @return log(&#915;(x))
 */
public static double logGamma(double x) {
    double ret;

    if (Double.isNaN(x) || (x <= 0.0)) {
        ret = Double.NaN;
    } else {
        double g = 607.0 / 128.0;

        double sum = 0.0;
        for (int i = LANCZOS.length - 1; i > 0; --i) {
            sum = sum + (LANCZOS[i] / (x + i));
        }
        sum = sum + LANCZOS[0];

        double tmp = x + g + .5;
        ret = ((x + .5) * FastMath.log(tmp)) - tmp +
            HALF_LOG_2_PI + FastMath.log(sum / x);
    }

    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:Gamma.java

示例7: logGamma

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the natural logarithm of the gamma function &#915;(x).
 *
 * The implementation of this method is based on:
 * <ul>
 * <li><a href="http://mathworld.wolfram.com/GammaFunction.html">
 * Gamma Function</a>, equation (28).</li>
 * <li><a href="http://mathworld.wolfram.com/LanczosApproximation.html">
 * Lanczos Approximation</a>, equations (1) through (5).</li>
 * <li><a href="http://my.fit.edu/~gabdo/gamma.txt">Paul Godfrey, A note on
 * the computation of the convergent Lanczos complex Gamma approximation
 * </a></li>
 * </ul>
 *
 * @param x the value.
 * @return log(&#915;(x))
 */
public static double logGamma(double x) {
    double ret;

    if (Double.isNaN(x) || (x <= 0.0)) {
        ret = Double.NaN;
    } else {
        double g = 607.0 / 128.0;

        double sum = 0.0;
        for (int i = LANCZOS.length - 1; i > 0; --i) {
            sum = sum + (LANCZOS[i] / (x + i));
        }
        sum = sum + LANCZOS[0];

        double tmp = x + g + .5;
        ret = ((x + .5) * FastMath.log(tmp)) - tmp +
            HALF_LOG_2_PI + FastMath.log(sum / x);
    }

    return ret;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:39,代码来源:Gamma.java

示例8: ln

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the natural logarithm of a big decimal. FastMath method is used
 * when possible. Results are not rounded.
 *
 * @param bigDecimal the big decimal to estimate the log on
 * @param mathContext the math context to use for the calculation
 *
 * @return the log of a big decimal
 */
public static BigDecimal ln(BigDecimal bigDecimal, MathContext mathContext) {
    if (bigDecimal.compareTo(BigDecimal.ZERO) != 1) {
        throw new IllegalArgumentException("Attempting to estimate the log of 0.");
    } else if (bigDecimal.compareTo(BigDecimal.ONE) == 0) {
        // log(1)=0
        return BigDecimal.ZERO;
    } else if (bigDecimal.compareTo(BigMathUtils.E) == 0) {
        // log(1)=0
        return BigDecimal.ZERO;
    }

    int precision = mathContext.getPrecision();
    boolean inRange = false;
    double deltaInf = FastMath.pow(10, -precision - 1); // one order of magnitude as margin
    if (precision < 300) {
        double deltaSup = FastMath.pow(10, -precision + 1);
        // try to find the range where FastMath methods can be used
        if (bigDecimal.compareTo(BigDecimal.ONE) == 1) {
            BigDecimal maxValue = new BigDecimal(Double.MAX_VALUE * (1 - deltaSup));
            if (bigDecimal.compareTo(maxValue) == -1) {
                inRange = true;
            }
        } else {
            BigDecimal minValue = new BigDecimal(Double.MIN_NORMAL * (1 + deltaSup));
            if (bigDecimal.compareTo(minValue) == 1) {
                inRange = true;
            }
        }
    }
    if (inRange) {
        double doubleValue = bigDecimal.doubleValue();
        double log = FastMath.log(doubleValue);
        double resolution = Math.abs(FastMath.pow(2, -60) / log);
        if (resolution < deltaInf) {
            return new BigDecimal(log);
        }
    }
    return lnBD(bigDecimal, mathContext);
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:49,代码来源:BigFunctions.java

示例9: log

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the log of the input in the desired base.
 *
 * @param input the input
 * @param base the log base
 *
 * @return the log value of the input in the desired base.
 */
public static double log(double input, double base) {
    if (base <= 0) {
        throw new IllegalArgumentException("Attempting to comupute logarithm of base " + base + ".");
    } else if (base != logBase) {
        logBase = base;
        logBaseValue = FastMath.log(base);
    }
    return FastMath.log(input) / logBaseValue;
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:18,代码来源:BasicMathFunctions.java

示例10: PrecursorMap

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Builds a precursor map.
 *
 * @param precursors map of the precursors indexed by spectrum title
 * @param precursorTolerance the precursor mass tolerance to use
 * @param ppm boolean indicating whether the tolerance is in ppm
 */
public PrecursorMap(HashMap<String, Precursor> precursors, double precursorTolerance, boolean ppm) {
    this.precursorTolerance = precursorTolerance;
    this.ppm = ppm;
    if (ppm) {
        scalingFactor = FastMath.log((1000000 - precursorTolerance) / (1000000 + precursorTolerance));
    }
    for (String spectrumTitle : precursors.keySet()) {
        Precursor precursor = precursors.get(spectrumTitle);
        PrecursorWithTitle precursorWithTitle = new PrecursorWithTitle(precursor, spectrumTitle);
        double mz = precursor.getMz();
        if (minMz == null || mz < minMz) {
            minMz = mz;
        }
        if (maxMz == null || mz > maxMz) {
            maxMz = mz;
        }
        Integer bin = getBin(mz);
        HashMap<Double, ArrayList<PrecursorWithTitle>> precursorsInBin = precursorsMap.get(bin);
        if (precursorsInBin == null) {
            precursorsInBin = new HashMap<Double, ArrayList<PrecursorWithTitle>>(2);
            precursorsMap.put(bin, precursorsInBin);
        }
        ArrayList<PrecursorWithTitle> precursorsAtMz = precursorsInBin.get(mz);
        if (precursorsAtMz == null) {
            precursorsAtMz = new ArrayList<PrecursorWithTitle>(1);
            precursorsInBin.put(mz, precursorsAtMz);
        }
        precursorsAtMz.add(precursorWithTitle);
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:38,代码来源:PrecursorMap.java

示例11: SpectrumIndex

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Builds a new index.
 *
 * @param peaks map of the peaks indexed by m/z
 * @param intenstiyLimit a lower limit for the intensity of the peaks to
 * index
 * @param tolerance the tolerance to use
 * @param ppm boolean indicating whether the tolerance is in ppm
 */
public SpectrumIndex(HashMap<Double, Peak> peaks, double intenstiyLimit, double tolerance, boolean ppm) {
    this.intensityLimit = intenstiyLimit;
    this.peaksMap = new HashMap<Integer, HashMap<Double, Peak>>();
    this.precursorTolerance = tolerance;
    this.ppm = ppm;
    if (ppm) {
        scalingFactor = FastMath.log((1000000 - tolerance) / (1000000 + tolerance));
    }
    totalIntensity = 0.0;
    for (Peak peak : peaks.values()) {
        if (peak.intensity >= intenstiyLimit) {
            totalIntensity += peak.intensity;
            Integer bin = getBin(peak.mz);
            if (binMax == null || bin > binMax) {
                binMax = bin;
            }
            if (binMin == null || bin < binMin) {
                binMin = bin;
            }
            HashMap<Double, Peak> peaksInBin = peaksMap.get(bin);
            if (peaksInBin == null) {
                peaksInBin = new HashMap<Double, Peak>(4);
                peaksMap.put(bin, peaksInBin);
            }
            peaksInBin.put(peak.mz, peak);
        }
    }
}
 
开发者ID:compomics,项目名称:compomics-utilities,代码行数:38,代码来源:SpectrumIndex.java

示例12: call

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
public static TypeFloat call(TypeFloat x) {
	Double val = x.getValue();

	if (val <= 0)
		throw new ExpressionFault.ValueError("argument must be positive");

	Double ret = FastMath.log(val);
	return new TypeFloat(ret);
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:10,代码来源:Builtins.java

示例13: value

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * @param x Value at which to compute the logit.
 * @param lo Lower bound.
 * @param hi Higher bound.
 * @return the value of the logit function at {@code x}.
 */
private static double value(double x,
                            double lo,
                            double hi) {
    if (x < lo || x > hi) {
        throw new OutOfRangeException(x, lo, hi);
    }
    return FastMath.log((x - lo) / (hi - x));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:Logit.java

示例14: density

import org.apache.commons.math.util.FastMath; //导入方法依赖的package包/类
/**
 * Returns the probability density for a particular point.
 *
 * @param x The point at which the density should be computed.
 * @return The pdf at point x.
 * @since 2.1
 */
@Override
public double density(double x) {
    final double nhalf = numeratorDegreesOfFreedom / 2;
    final double mhalf = denominatorDegreesOfFreedom / 2;
    final double logx = FastMath.log(x);
    final double logn = FastMath.log(numeratorDegreesOfFreedom);
    final double logm = FastMath.log(denominatorDegreesOfFreedom);
    final double lognxm = FastMath.log(numeratorDegreesOfFreedom * x +
                                       denominatorDegreesOfFreedom);
    return FastMath.exp(nhalf * logn + nhalf * logx - logx +
                        mhalf * logm - nhalf * lognxm - mhalf * lognxm -
                        Beta.logBeta(nhalf, mhalf));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:FDistributionImpl.java

示例15: convertToLog

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


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