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


Java FastMath.pow方法代码示例

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


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

示例1: LinearScale

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Constructor. Computes a scale covering the range of min-max with between 3
 * and 30 intervals, rounded to the appropriate number of digits.
 * 
 * @param min actual minimum in the data
 * @param max actual maximum in the data
 */
public LinearScale(double min, double max) {
  if(max < min) {
    double tmp = max;
    max = min;
    min = tmp;
  }
  this.delta = max - min;
  if(this.delta <= Double.MIN_NORMAL) {
    this.delta = 1.0;
  }
  log10res = (int) Math.ceil(Math.log10(this.delta) - ZOOMFACTOR);
  res = FastMath.pow(10, log10res);

  // round min and max according to the resolution counters
  this.min = Math.floor(min / res + .001) * res;
  this.max = Math.ceil(max / res - .001) * res;
  if(this.min == this.max) {
    this.max = this.min + res;
  }
  // Update delta (note: updated min, max!)
  this.delta = this.max - this.min;
  if(this.delta <= Double.MIN_NORMAL) {
    this.delta = 1.0;
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:33,代码来源:LinearScale.java

示例2: minDist

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double minDist(SpatialComparable mbr1, SpatialComparable mbr2) {
  if(mbr1.getDimensionality() != mbr2.getDimensionality()) {
    throw new IllegalArgumentException("Different dimensionality of objects\n  " + "first argument: " + mbr1.toString() + "\n  " + "second argument: " + mbr2.toString());
  }
  double sqrDist = 0;
  for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
    final double delta;
    final double max1 = mbr1.getMax(d);
    final double min2 = mbr2.getMin(d);
    if(max1 < min2) {
      delta = min2 - max1;
    }
    else {
      final double min1 = mbr1.getMin(d);
      final double max2 = mbr2.getMax(d);
      if(min1 > max2) {
        delta = min1 - max2;
      }
      else { // The mbrs intersect!
        continue;
      }
    }
    sqrDist += FastMath.pow(delta, p);
  }
  return FastMath.pow(sqrDist, 1. / p);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:SubspaceLPNormDistanceFunction.java

示例3: preDistanceVM

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Compute unscaled distance in a range of dimensions.
 * 
 * @param v First vector
 * @param mbr Second MBR
 * @param start First dimension
 * @param end Exclusive last dimension
 * @return Aggregated values.
 */
private final double preDistanceVM(NumberVector v, SpatialComparable mbr, final int start, final int end) {
  double agg = 0.;
  for(int d = start; d < end; d++) {
    final double value = v.doubleValue(d), min = mbr.getMin(d);
    double delta = min - value;
    delta = (delta >= 0) ? delta : value - mbr.getMax(d);
    if(delta > 0.) {
      agg += FastMath.pow(delta, p);
    }
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:22,代码来源:LPNormDistanceFunction.java

示例4: quantile

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Quantile function.
 * 
 * @param val Value
 * @param loc Location
 * @param scale Scale
 * @param shape1 Shape parameter
 * @param shape2 Shape parameter
 * @return Quantile
 */
public static double quantile(double val, double loc, double scale, double shape1, double shape2) {
  if(!(val >= 0.) || !(val <= 1.)) {
    return Double.NaN;
  }
  if(val == 0.) {
    if(shape2 <= 0.) {
      if(shape1 < 0.) {
        return loc + scale / shape1;
      }
      else {
        return Double.NEGATIVE_INFINITY;
      }
    }
    else {
      if(shape1 != 0.) {
        return loc + scale / shape1 * (1. - FastMath.pow(shape2, -shape1));
      }
      else {
        return loc + scale * FastMath.log(shape2);
      }
    }
  }
  if(val == 1.) {
    if(shape1 <= 0.) {
      return Double.NEGATIVE_INFINITY;
    }
    return loc + scale / shape1;
  }
  val = -FastMath.log(val);
  if(shape2 != 0.) {
    val = (1 - FastMath.exp(-shape2 * val)) / shape2;
  }
  val = -FastMath.log(val);
  if(shape1 != 0.) {
    val = (1 - FastMath.exp(-shape1 * val)) / shape1;
  }
  return loc + scale * val;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:49,代码来源:KappaDistribution.java

示例5: initializeLookupTable

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Initialize the lookup table.
 * 
 * @param splitPositions Split positions
 * @param query Query vector
 * @param p p
 */
private void initializeLookupTable(double[][] splitPositions, NumberVector query, double p) {
  final int dimensions = splitPositions.length;
  final int bordercount = splitPositions[0].length;
  lookup = new double[dimensions][bordercount];
  for(int d = 0; d < dimensions; d++) {
    final double val = query.doubleValue(d);
    for(int i = 0; i < bordercount; i++) {
      lookup[d][i] = FastMath.pow(splitPositions[d][i] - val, p);
    }
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:19,代码来源:VALPNormDistance.java

示例6: preDistance

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Compute unscaled distance in a range of dimensions.
 * 
 * @param v1 First object
 * @param v2 Second object
 * @param start First dimension
 * @param end Exclusive last dimension
 * @return Aggregated values.
 */
private final double preDistance(NumberVector v1, NumberVector v2, final int start, final int end) {
  double agg = 0.;
  for(int d = start; d < end; d++) {
    final double xd = v1.doubleValue(d), yd = v2.doubleValue(d);
    final double delta = (xd >= yd) ? xd - yd : yd - xd;
    agg += FastMath.pow(delta, p);
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:19,代码来源:LPNormDistanceFunction.java

示例7: preDistanceMBR

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Compute unscaled distance in a range of dimensions.
 * 
 * @param mbr1 First MBR
 * @param mbr2 Second MBR
 * @param start First dimension
 * @param end Exclusive last dimension
 * @return Aggregated values.
 */
private final double preDistanceMBR(SpatialComparable mbr1, SpatialComparable mbr2, final int start, final int end) {
  double agg = 0.;
  for(int d = start; d < end; d++) {
    double delta = mbr2.getMin(d) - mbr1.getMax(d);
    delta = (delta >= 0) ? delta : mbr1.getMin(d) - mbr2.getMax(d);
    if(delta > 0.) {
      agg += FastMath.pow(delta, p);
    }
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:21,代码来源:LPNormDistanceFunction.java

示例8: quantile

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Quantile function of GPD distribution
 * 
 * @param val Value
 * @param mu Location parameter mu
 * @param sigma Scale parameter sigma
 * @param xi Shape parameter xi (= -kappa)
 * @return Quantile function at position x.
 */
public static double quantile(double val, double mu, double sigma, double xi) {
  if(val < 0.0 || val > 1.0) {
    return Double.NaN;
  }
  if(xi == 0.) {
    return mu - sigma * FastMath.log(1 - val);
  }
  return mu - sigma / xi * (1 - FastMath.pow(1 - val, -xi));
}
 
开发者ID:elki-project,项目名称:elki,代码行数:19,代码来源:GeneralizedParetoDistribution.java

示例9: pdf

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Probability density function.
 * 
 * @param val Value
 * @param shape Shape
 * @param location TODO
 * @param scale Scale
 * @return PDF
 */
public static double pdf(double val, double shape, double location, double scale) {
  if(val < location) {
    return 0;
  }
  val = (val - location) / scale;
  double f = shape / scale * FastMath.pow(val, shape - 1.);
  if(f == Double.POSITIVE_INFINITY) {
    return 0;
  }
  double d = 1. + FastMath.pow(val, shape);
  return f / (d * d);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:22,代码来源:LogLogisticDistribution.java

示例10: distance

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double distance(NumberVector v1, NumberVector v2) {
  double sqrDist = 0;
  for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
    double delta = Math.abs(v1.doubleValue(d) - v2.doubleValue(d));
    sqrDist += FastMath.pow(delta, p);
  }
  return FastMath.pow(sqrDist, 1. / p);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:10,代码来源:SubspaceLPNormDistanceFunction.java

示例11: preDistance

import net.jafama.FastMath; //导入方法依赖的package包/类
private final double preDistance(NumberVector v1, NumberVector v2, final int start, final int end) {
  double agg = 0.;
  for(int d = start; d < end; d++) {
    final double xd = v1.doubleValue(d), yd = v2.doubleValue(d);
    final double delta = (xd >= yd) ? xd - yd : yd - xd;
    agg += FastMath.pow(delta, p) * weights[d];
  }
  return agg;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:10,代码来源:WeightedLPNormDistanceFunction.java

示例12: getSampleSkewness

import net.jafama.FastMath; //导入方法依赖的package包/类
/**
 * Get the skewness using sample variance.
 * 
 * @return Skewness
 */
public double getSampleSkewness() {
  if(!(m2 > 0) || !(n > 2)) {
    throw new ArithmeticException("Skewness not defined when variance is 0 or weight <= 2.0!");
  }
  return (m3 * n / (n - 1) / (n - 2)) / FastMath.pow(getSampleVariance(), 1.5);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:12,代码来源:StatisticalMoments.java

示例13: getRangeForObject

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public void getRangeForObject(V query, double range, ModifiableDoubleDBIDList result) {
  stats.incrementIssuedQueries();
  long t = System.nanoTime();

  final double epsilonP = FastMath.pow(range, p);

  // generate query approximation and lookup table
  final VectorApproximation queryApprox = calculateFullApproximation(null, query);
  final VALPNormDistance dist = new VALPNormDistance(p, splitPartitions, query, queryApprox);

  // perform multi-step range query

  // filter step

  // calculate selectivity coefficients
  List<DoubleObjPair<DAFile>> subspaceDAFiles = new ArrayList<>(BitsUtil.cardinality(subspace));
  for(int d = BitsUtil.nextSetBit(subspace, 0); d >= 0; d = BitsUtil.nextSetBit(subspace, d + 1)) {
    DAFile daFile = daFiles.get(d);
    subspaceDAFiles.add(new DoubleObjPair<>(-1, daFile));
  }
  calculateSelectivityCoeffs(subspaceDAFiles, query, range);
  // sort DA files by selectivity
  // TODO: validate that this is the correct order
  Collections.sort(subspaceDAFiles, Collections.reverseOrder());

  // create candidate list (all objects) and prune candidates w.r.t.
  // mindist (i.e. remove them from the list)
  // important: this structure contains the maxDist values for refinement!
  int candidates = 0;
  for(VectorApproximation va : vectorApprox) {
    DBID id = va.getId();
    PartialVACandidate pva = new PartialVACandidate(va);

    boolean pruned = false;
    for(DoubleObjPair<DAFile> da : subspaceDAFiles) {
      int dimension = da.second.getDimension();
      int objectCell = va.getApproximation(dimension);
      pva.minDistP += dist.getPartialMinDist(dimension, objectCell);
      pva.maxDistP += dist.getPartialMaxDist(dimension, objectCell);
      if(pva.minDistP > epsilonP) {
        pruned = true;
        break;
      }
    }
    if(!pruned) {
      candidates++;
      if(pva.maxDistP <= epsilonP) {
        // candidate cannot be dropped
        // TODO: actually: no refinement needed - need API that allows
        // reporting maxdists only.
        result.add(refine(id, query), id);
      }
      else { // refine candidate - true refinement
        double dis = refine(id, query);
        stats.incrementRefinements();
        if(dis <= range) {
          result.add(dis, id);
        }
      }
    }
  }
  result.sort();

  stats.incrementScannedBytes(relation.size() * VectorApproximation.byteOnDisk(BitsUtil.cardinality(subspace), partitions));

  stats.incrementQueryTime(System.nanoTime() - t);

  if(LOG.isDebuggingFine()) {
    LOG.fine("query = " + query);
    LOG.fine("database: " + relation.size() + ", candidates: " + candidates + ", results: " + result.size());
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:74,代码来源:PartialVAFile.java

示例14: filter

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public MultipleObjectsBundle filter(MultipleObjectsBundle objects) {
  if(objects.dataLength() == 0) {
    return objects;
  }
  for(int r = 0; r < objects.metaLength(); r++) {
    SimpleTypeInformation<?> type = (SimpleTypeInformation<?>) objects.meta(r);
    final List<?> column = (List<?>) objects.getColumn(r);
    if(!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(type)) {
      continue;
    }
    @SuppressWarnings("unchecked")
    final List<V> castColumn = (List<V>) column;
    // Get the replacement type information
    @SuppressWarnings("unchecked")
    final VectorFieldTypeInformation<V> castType = (VectorFieldTypeInformation<V>) type;
    factory = FilterUtil.guessFactory(castType);

    // Scan to find the best
    final int dim = castType.getDimensionality();
    dists = new ArrayList<>(dim);
    // Scratch space for testing:
    double[] test = new double[castColumn.size()];

    // We iterate over dimensions, this kind of filter needs fast random
    // access.
    Adapter adapter = new Adapter();
    for(int d = 0; d < dim; d++) {
      adapter.dim = d;
      Distribution dist = findBestFit(castColumn, adapter, d, test);
      if(LOG.isVerbose()) {
        LOG.verbose("Best fit for dimension " + d + ": " + dist.toString());
      }
      dists.add(dist);
    }

    // Beta distribution for projection
    double p = FastMath.pow(alpha, -1 / FastMath.sqrt(dim));
    BetaDistribution beta = new BetaDistribution(p, p);
    // Normalization scan
    double[] buf = new double[dim];
    for(int i = 0; i < objects.dataLength(); i++) {
      final V obj = castColumn.get(i);
      for(int d = 0; d < dim; d++) {
        // TODO: when available, use logspace for better numerical precision!
        buf[d] = beta.quantile(dists.get(d).cdf(obj.doubleValue(d)));
      }
      castColumn.set(i, factory.newNumberVector(buf));
    }
  }
  return objects;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:53,代码来源:AttributeWiseBetaNormalization.java

示例15: estimateFromLMoments

import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public GeneralizedExtremeValueDistribution estimateFromLMoments(double[] xmom) {
  double t3 = xmom[2];
  if(Math.abs(t3) < 1e-50 || (t3 >= 1.)) {
    throw new ArithmeticException("Invalid moment estimation.");
  }
  // Approximation for t3 between 0 and 1:
  double g;
  if(t3 > 0.) {
    double z = 1. - t3;
    g = (-1. + z * (C1 + z * (C2 + z * C3))) / (1. + z * (D1 + z * D2));
    // g: Almost zero?
    if(Math.abs(g) < 1e-50) {
      double k = 0;
      double sigma = xmom[1] * MathUtil.ONE_BY_LOG2;
      double mu = xmom[0] - EU * sigma;
      return new GeneralizedExtremeValueDistribution(mu, sigma, k);
    }
  }
  else {
    // Approximation for t3 between -.8 and 0L:
    g = (A0 + t3 * (A1 + t3 * (A2 + t3 * (A3 + t3 * A4)))) / (1. + t3 * (B1 + t3 * (B2 + t3 * B3)));
    if(t3 < -.8) {
      // Newton-Raphson iteration for t3 < -.8
      if(t3 <= -.97) {
        g = 1. - FastMath.log1p(t3) * MathUtil.ONE_BY_LOG2;
      }
      double t0 = .5 * (t3 + 3.);
      for(int it = 1;; it++) {
        // These sometimes do not converge with FastMath.
        double x2 = FastMath.pow(2., -g), xx2 = 1. - x2;
        double x3 = FastMath.pow(3., -g), xx3 = 1. - x3;
        double t = xx3 / xx2;
        double deriv = (xx2 * x3 * MathUtil.LOG3 - xx3 * x2 * MathUtil.LOG2) / (xx2 * xx2);
        double oldg = g;
        g -= (t - t0) / deriv;
        if(Math.abs(g - oldg) < 1e-14 * g) {
          break;
        }
        if(it >= MAXIT) {
          throw new ArithmeticException("Newton-Raphson did not converge.");
        }
      }
    }
  }
  double gam = FastMath.exp(GammaDistribution.logGamma(1. + g));
  final double mu, sigma, k;
  k = g;
  sigma = xmom[1] * g / (gam * (1. - FastMath.pow(2., -g)));
  mu = xmom[0] - sigma * (1. - gam) / g;
  return new GeneralizedExtremeValueDistribution(mu, sigma, k);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:53,代码来源:GeneralizedExtremeValueLMMEstimator.java


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