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


Java FastMath.log方法代码示例

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


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

示例1: logpdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Probability density function.
 * 
 * @param val Value
 * @param loc Location
 * @param scale Scale
 * @param shape1 Shape parameter
 * @param shape2 Shape parameter
 * @return PDF
 */
public static double logpdf(double val, double loc, double scale, double shape1, double shape2) {
  val = (val - loc) / scale;
  final double logc = logcdf(val, shape1, shape2);
  if(shape1 != 0.) {
    val = shape1 * val;
    if(val >= 1) {
      return Double.NEGATIVE_INFINITY;
    }
    val = (1. - 1. / shape1) * FastMath.log1p(-val);
  }
  if(Double.isInfinite(val)) {
    return Double.NEGATIVE_INFINITY;
  }
  return -val - FastMath.log(scale) + logc * (1. - shape2);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:26,代码来源:KappaDistribution.java

示例2: computeH

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Compute H (observed perplexity) for row i, and the row pij_i.
 * 
 * @param ignore Object to skip
 * @param it Distances list
 * @param p Output probabilities
 * @param mbeta {@code -1. / (2 * sigma * sigma)}
 * @return Observed perplexity
 */
protected static double computeH(DBIDRef ignore, DoubleDBIDListIter it, double[] p, double mbeta) {
  double sumP = 0.;
  // Skip point "i", break loop in two:
  it.seek(0);
  for(int j = 0; it.valid(); j++, it.advance()) {
    if(DBIDUtil.equal(ignore, it)) {
      p[j] = 0;
      continue;
    }
    sumP += (p[j] = FastMath.exp(it.doubleValue() * mbeta));
  }
  if(!(sumP > 0)) {
    // All pij are zero. Bad news.
    return Double.NEGATIVE_INFINITY;
  }
  final double s = 1. / sumP; // Scaling factor
  double sum = 0.;
  // While we could skip pi[i], it should be 0 anyway.
  it.seek(0);
  for(int j = 0; it.valid(); j++, it.advance()) {
    sum += it.doubleValue() * (p[j] *= s);
  }
  return FastMath.log(sumP) - mbeta * sum;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:34,代码来源:SOS.java

示例3: estimate

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public <A> double estimate(A data, NumberArrayAdapter<?, ? super A> adapter, final int end) {
  final int last = end - 1;
  final double w = adapter.getDouble(data, last);
  if(w <= 0.) {
    throw new ArithmeticException("ID estimates require at least 2 non-zero distances");
  }
  final double halfw = 0.5 * w;
  double sum = 0.;
  int valid = 0;
  for(int i = 0; i < last; ++i) {
    final double v = adapter.getDouble(data, i);
    if(!(v > 0.)) {
      continue;
    }
    sum += v < halfw ? FastMath.log(v / w) : FastMath.log1p((v - w) / w);
    ++valid;
  }
  if(valid < 1) {
    throw new ArithmeticException("ID estimates require at least 2 non-zero distances");
  }
  return -valid / sum;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:24,代码来源:HillEstimator.java

示例4: minDist

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
  final int dim = dimensionality(mbr1, mbr2);
  double agg = 0;
  for(int d = 0; d < dim; d++) {
    final double min1 = mbr1.getMin(d), max1 = mbr1.getMax(d);
    final double min2 = mbr2.getMin(d), max2 = mbr2.getMax(d);
    final double md = .5 * (max1 + max2);
    if(!(md > 0. || md < 0.)) {
      continue;
    }
    if(min1 > 0.) {
      agg += min1 * FastMath.log(min1 / md);
    }
    if(min2 > 0.) {
      agg += min2 * FastMath.log(min2 / md);
    }
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:21,代码来源:JeffreyDivergenceDistanceFunction.java

示例5: finalizeEStep

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public void finalizeEStep(double weight, double prior) {
  final int dim = variances.length;
  this.weight = weight;
  // FIXME: support prior.
  double logDet = 0;
  if(prior > 0 && priordiag != null) {
    // MAP
    double nu = dim + 2; // Popular default.
    double f2 = 1. / (wsum + prior * (nu + dim + 2));
    for(int i = 0; i < dim; i++) {
      logDet += FastMath.log(variances[i] = (variances[i] + prior * priordiag[i]) * f2);
    }
  }
  else if(wsum > 0.) { // MLE
    final double s = 1. / wsum;
    for(int i = 0; i < dim; i++) {
      double v = variances[i];
      logDet += FastMath.log(variances[i] = v > 0 ? v * s : SINGULARITY_CHEAT);
    }
  } // else degenerate
  logNormDet = FastMath.log(weight) - .5 * (logNorm + logDet);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:24,代码来源:DiagonalGaussianModel.java

示例6: estimate

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public <A> double estimate(A data, NumberArrayAdapter<?, ? super A> adapter, final int end) {
  final int begin = countLeadingZeros(data, adapter, end);
  final int len = end - begin;
  if(len < 2) {
    throw new ArithmeticException("ID estimates require at least 2 non-zero distances");
  }
  // TODO: any value from literature that works?
  final double bias = .6; // Literature uses 1.
  final double nplus1 = len + bias;
  double wls = 0., ws = 0., ls = 0., wws = 0.;
  for(int i = begin; i < end; ++i) {
    final double v = adapter.getDouble(data, i);
    assert (v > 0.);
    final double logv = FastMath.log(v);
    final double weight = FastMath.log(nplus1 / (i - begin + bias));
    wls += weight * logv;
    ws += weight;
    ls += logv;
    wws += weight * weight;
  }
  return -1. / ((len * wls - ws * ls) / (len * wws - ws * ws));
}
 
开发者ID:elki-project,项目名称:elki,代码行数:24,代码来源:ZipfEstimator.java

示例7: KernelDensityEstimator

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Process an array of data
 * 
 * @param data data to process
 * @param kernel Kernel function to use.
 * @param epsilon Precision threshold
 */
public KernelDensityEstimator(double[] data, KernelDensityFunction kernel, double epsilon) {
  boolean needsort = false;
  for (int i = 1; i < data.length; i++) {
    if (data[i - 1] > data[i]) {
      needsort = true;
      break;
    }
  }
  // Duplicate and sort when needed:
  if (needsort) {
    data = data.clone();
    Arrays.sort(data);
  }
  final double min = data[0];
  final double max = data[data.length - 1];
  // Heuristic for choosing the window size.
  int windows = 1 + (int) (FastMath.log(data.length));

  process(data, min, max, kernel, windows, epsilon);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:KernelDensityEstimator.java

示例8: logpdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * log PDF of GEV distribution
 * 
 * @param x Value
 * @param mu Location parameter mu
 * @param sigma Scale parameter sigma
 * @param k Shape parameter k
 * @return PDF at position x.
 */
public static double logpdf(double x, double mu, double sigma, double k) {
  if(x == Double.POSITIVE_INFINITY || x == Double.NEGATIVE_INFINITY) {
    return Double.NEGATIVE_INFINITY;
  }
  x = (x - mu) / sigma;
  if(k > 0 || k < 0) {
    if(k * x > 1) {
      return Double.NEGATIVE_INFINITY;
    }
    double t = FastMath.log(1 - k * x);
    return t == Double.NEGATIVE_INFINITY ? -FastMath.log(sigma) //
        : t == Double.POSITIVE_INFINITY ? Double.NEGATIVE_INFINITY //
            : (1 - k) * t / k - FastMath.exp(t / k) - FastMath.log(sigma);
  }
  else { // Gumbel case:
    return -x - FastMath.exp(-x) - FastMath.log(sigma);
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:GeneralizedExtremeValueDistribution.java

示例9: stirlingError

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Calculates the Striling Error
 *
 * stirlerr(n) = ln(n!) - ln(sqrt(2*pi*n)*(n/e)^n)
 *
 * @param n Parameter n
 * @return Stirling error
 */
@Reference(title = "Fast and accurate computation of binomial probabilities", authors = "C. Loader", booktitle = "", url = "http://projects.scipy.org/scipy/raw-attachment/ticket/620/loader2000Fast.pdf")
private static double stirlingError(double n) {
  if(n < 16.0) {
    // Our table has a step size of 0.5
    final double n2 = 2.0 * n;
    if(FastMath.floor(n2) == n2) { // Exact match
      return STIRLING_EXACT_ERROR[(int) n2];
    }
    else {
      return GammaDistribution.logGamma(n + 1.0) - (n + 0.5) * FastMath.log(n) + n - MathUtil.LOGSQRTTWOPI;
    }
  }
  final double nn = n * n;
  if(n > 500.0) {
    return (S0 - S1 / nn) / n;
  }
  if(n > 80.0) {
    return ((S0 - (S1 - S2 / nn)) / nn) / n;
  }
  if(n > 35.0) {
    return ((S0 - (S1 - (S2 - S3 / nn) / nn) / nn) / n);
  }
  return ((S0 - (S1 - (S2 - (S3 - S4 / nn) / nn) / nn) / nn) / n);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:33,代码来源:PoissonDistribution.java

示例10: pdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * PDF of GEV distribution
 * 
 * @param x Value
 * @param mu Location parameter mu
 * @param sigma Scale parameter sigma
 * @param k Shape parameter k
 * @return PDF at position x.
 */
public static double pdf(double x, double mu, double sigma, double k) {
  if(x == Double.POSITIVE_INFINITY || x == Double.NEGATIVE_INFINITY) {
    return 0.;
  }
  x = (x - mu) / sigma;
  if(k > 0 || k < 0) {
    if(k * x > 1) {
      return 0.;
    }
    double t = FastMath.log(1 - k * x);
    return t == Double.NEGATIVE_INFINITY ? 1. / sigma //
        : t == Double.POSITIVE_INFINITY ? 0. //
            : FastMath.exp((1 - k) * t / k - FastMath.exp(t / k)) / sigma;
  }
  else { // Gumbel case:
    return FastMath.exp(-x - FastMath.exp(-x)) / sigma;
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:GeneralizedExtremeValueDistribution.java

示例11: logpdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * PDF of Rayleigh distribution
 * 
 * @param x Value
 * @param sigma Scale
 * @return PDF at position x.
 */
public static double logpdf(double x, double sigma) {
  if(x <= 0. || x == Double.POSITIVE_INFINITY) {
    return Double.NEGATIVE_INFINITY;
  }
  final double xs = x / sigma, xs2 = xs * xs;
  return xs2 < Double.POSITIVE_INFINITY ? FastMath.log(xs / sigma) - .5 * xs2 : Double.NEGATIVE_INFINITY;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:15,代码来源:RayleighDistribution.java

示例12: getValueAt

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Returns the function value of the polynomial approximation
 * at the specified k.
 *
 * @param k the value for which the polynomial approximation should be returned
 * @return the function value of the polynomial approximation
 *         at the specified k
 */
public double getValueAt(int k) {
  double result = 0.;
  double log_k = FastMath.log(k), acc = 1.;
  for (int p = 0; p < b.length; p++) {
    result += b[p] * acc;
    acc *= log_k;
  }
  return result;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:18,代码来源:PolynomialApproximation.java

示例13: logpdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Probability density function.
 * 
 * @param val Value
 * @param shape Shape
 * @param location Location
 * @param scale Scale
 * @return logPDF
 */
public static double logpdf(double val, double shape, double location, double scale) {
  if(val < location) {
    return Double.NEGATIVE_INFINITY;
  }
  val = (val - location) / scale;
  final double lval = FastMath.log(val);
  if(lval == Double.POSITIVE_INFINITY) {
    return Double.NEGATIVE_INFINITY;
  }
  return FastMath.log(shape / scale) + (shape - 1.) * lval //
      - 2. * FastMath.log1p(FastMath.exp(lval * shape));
}
 
开发者ID:elki-project,项目名称:elki,代码行数:22,代码来源:LogLogisticDistribution.java

示例14: logGamma

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Compute logGamma.
 * 
 * Based loosely on "Numerical Recpies" and the work of Paul Godfrey at
 * http://my.fit.edu/~gabdo/gamma.txt
 * 
 * TODO: find out which approximation really is the best...
 * 
 * @param x Parameter x
 * @return log(&#915;(x))
 */
public static double logGamma(final double x) {
  if(Double.isNaN(x) || (x <= 0.0)) {
    return Double.NaN;
  }
  double g = 607.0 / 128.0;
  double tmp = x + g + .5;
  tmp = (x + 0.5) * FastMath.log(tmp) - tmp;
  double ser = LANCZOS[0];
  for(int i = LANCZOS.length - 1; i > 0; --i) {
    ser += LANCZOS[i] / (x + i);
  }
  return tmp + FastMath.log(MathUtil.SQRTTWOPI * ser / x);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:25,代码来源:GammaDistribution.java

示例15: distance

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double distance(NumberVector v1, NumberVector v2) {
  final int dim = dimensionality(v1, v2);
  double agg = 0.;
  for(int d = 0; d < dim; d++) {
    final double xd = v1.doubleValue(d), yd = v2.doubleValue(d);
    if(yd <= 0.) {
      return Double.POSITIVE_INFINITY;
    }
    if(xd > 0.) {
      agg += xd * FastMath.log(xd / yd);
    }
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:16,代码来源:KullbackLeiblerDivergenceAsymmetricDistanceFunction.java


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