• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java FastMath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: logicLoop

import net.jafama.FastMath; //导入依赖的package包/类
public void logicLoop(float calcX, float deltaX) {
	this.mouthCurvePos = this.parent.getPos().add(this.pos).addX(0.5f * this.size.x).addX(-calcX);
	this.mouthCurveTimer.logicLoop();
	float maxDelta = this.size.y * 0.5f * this.parent.getState().getMouthAmplitude();
	while (this.mouthCurveTimer.timeUp()) {
		this.mouthCurveTimer.reset();
		Vec newVec = new Vec(calcX, (float) (FastMath.tan(calcX * 10) * FastMath.sinQuick(calcX * 4) * FastMath.cosQuick(calcX * 0.5f) * maxDelta));
		if (newVec.y > maxDelta) {
			newVec = newVec.setY(maxDelta);
		}
		if (newVec.y < -maxDelta) {
			newVec = newVec.setY(-maxDelta);
		}
		this.mouthCurve.add(newVec);
	}
	Iterator<Vec> it = this.mouthCurve.iterator();
	while (it.hasNext()) {
		if (it.next().x <= calcX - this.size.x) {
			it.remove();
		} else {
			break;
		}
	}
}
 
开发者ID:rekit-group,项目名称:rekit-game,代码行数:25,代码来源:Mouth.java


示例2: transformInverse

import net.jafama.FastMath; //导入依赖的package包/类
@Override
   protected void transformInverse(int x, int y, float[] out) {
       float dx = x - icentreX;
       float dy = y - icentreY;
       float distance2 = dx * dx + dy * dy;
       if (distance2 > radius2) {
           out[0] = x;
           out[1] = y;
       } else {
           float distance = (float) Math.sqrt(distance2);
           float amount = amplitude * (float) FastMath.sin(distance / wavelength * ImageMath.TWO_PI - phase);
           amount *= (radius-distance)/radius;
		if ( distance != 0 ) {
               amount *= wavelength / distance;
           }
		out[0] = x + dx*amount;
		out[1] = y + dy*amount;
	}
}
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:20,代码来源:WaterFilter.java


示例3: transformInverse

import net.jafama.FastMath; //导入依赖的package包/类
@Override
  protected void transformInverse(int x, int y, float[] out) {
      double dx = x - icentreX;
      double dy = y - icentreY;
      double r = Math.sqrt(dx * dx + dy * dy);
      double theta = FastMath.atan2(dy, dx) - angle - angle2;
      theta = ImageMath.triangle((float) (theta / Math.PI * sides * .5));
      if (radius != 0) {
          double c = FastMath.cos(theta);
          double radiusc = radius / c;
          r = radiusc * ImageMath.triangle( (float)(r/radiusc) );
}
theta += angle;

      double zoomedR = r / zoom;
      out[0] = (float)(icentreX + zoomedR*FastMath.cos(theta));
      out[1] = (float)(icentreY + zoomedR*FastMath.sin(theta));
  }
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:19,代码来源:KaleidoscopeFilter.java


示例4: transformInverse

import net.jafama.FastMath; //导入依赖的package包/类
@Override
protected void transformInverse(int x, int y, float[] out) {
    float dx = x - cx;
    float dy = cy - y;
    double r = Math.sqrt(dx * dx + dy * dy);

    double radius = srcHeight * zoom / 2;
    double angle = Utils.transformAtan2AngleToIntuitive(FastMath.atan2(dy, dx)) + rotateResult;

    if (angle > (2 * Math.PI)) {
        angle -= 2 * Math.PI;
    }
    float nx = (float) ((angle * srcWidth) / (2 * Math.PI));
    float ratio = (float) (r / radius);
    float correctedRatio = ImageMath.bias(ratio, innerZoom);
    float ny = correctedRatio * srcHeight;
    if(!inverted) {
        ny = srcHeight - ny;
    }

    out[0] = nx;
    out[1] = ny;
}
 
开发者ID:teddyted,项目名称:iSeleda,代码行数:24,代码来源:LittlePlanetFilter.java


示例5: 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


示例6: computeSigma

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Compute row pij[i], using binary search on the kernel bandwidth sigma to
 * obtain the desired perplexity.
 *
 * @param i Current point
 * @param pij_row Distance matrix row pij[i]
 * @param perplexity Desired perplexity
 * @param log_perp Log of desired perplexity
 * @param pij_i Output row
 * @return beta
 */
protected static double computeSigma(int i, DoubleArray pij_row, double perplexity, double log_perp, double[] pij_i) {
  double max = pij_row.get((int) FastMath.ceil(perplexity)) / Math.E;
  double beta = 1 / max; // beta = 1. / (2*sigma*sigma)
  double diff = computeH(pij_row, pij_i, -beta) - log_perp;
  double betaMin = 0.;
  double betaMax = Double.POSITIVE_INFINITY;
  for(int tries = 0; tries < PERPLEXITY_MAXITER && Math.abs(diff) > PERPLEXITY_ERROR; ++tries) {
    if(diff > 0) {
      betaMin = beta;
      beta += (betaMax == Double.POSITIVE_INFINITY) ? beta : ((betaMax - beta) * .5);
    }
    else {
      betaMax = beta;
      beta -= (beta - betaMin) * .5;
    }
    diff = computeH(pij_row, pij_i, -beta) - log_perp;
  }
  return beta;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:31,代码来源:NearestNeighborAffinityMatrixBuilder.java


示例7: cdf

import net.jafama.FastMath; //导入依赖的package包/类
@Override
public double cdf(double x) {
  if(alpha <= 0.0 || beta <= 0.0 || Double.isNaN(alpha) || Double.isNaN(beta) || Double.isNaN(x)) {
    return Double.NaN;
  }
  if(x <= 0.0) {
    return 0.0;
  }
  if(x >= 1.0) {
    return 1.0;
  }
  if(alpha > SWITCH && beta > SWITCH) {
    return regularizedIncBetaQuadrature(alpha, beta, x);
  }
  double bt = FastMath.exp(-logbab + alpha * FastMath.log(x) + beta * FastMath.log1p(-x));
  if(x < (alpha + 1.0) / (alpha + beta + 2.0)) {
    return bt * regularizedIncBetaCF(alpha, beta, x) / alpha;
  }
  else {
    return 1.0 - bt * regularizedIncBetaCF(beta, alpha, 1.0 - x) / beta;
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:23,代码来源:BetaDistribution.java


示例8: 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 k = end - begin;
  if(k < 2) {
    throw new ArithmeticException("ID estimates require at least 2 non-zero distances");
  }
  final int n1 = k >> 1; // i in Section 5.1 of the ACM publication
  final int n2 = (3 * k) >> 2; // j in Section 5.1 of the ACM publication
  final int n3 = k; // n in Section 5.1 of the ACM publication
  final double r1 = adapter.getDouble(data, begin + n1 - 1);
  final double r2 = adapter.getDouble(data, begin + n2 - 1);
  final double r3 = adapter.getDouble(data, begin + n3 - 1);
  final double p = (r3 - r2) / (r1 - 2 * r2 + r3);
  // Optimized away: final double a1 = 1;
  final double a2 = (1. - p) / p;
  return (/* a1 * */ FastMath.log(n3 / (double) n2) //
      + a2 * FastMath.log(n1 / (double) n2)) / (/* a1 * */ FastMath.log(r3 / r2) + a2 * FastMath.log(r1 / r2));
}
 
开发者ID:elki-project,项目名称:elki,代码行数:20,代码来源:RVEstimator.java


示例9: cdf

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Cumulative probability density function (CDF) of a normal distribution.
 * 
 * Reference:
 * <p>
 * G. Marsaglia<br />
 * Evaluating the Normal Distribution<br />
 * Journal of Statistical Software 11(4)
 * </p>
 *
 * @param x value to evaluate CDF at
 * @param mu Mean value
 * @param sigma Standard deviation.
 * @return The CDF of the given normal distribution at x.
 */
@Reference(authors = "G. Marsaglia", //
    title = "Evaluating the Normal Distribution", //
    booktitle = "Journal of Statistical Software 11(4)", //
    url = "https://www.jstatsoft.org/article/view/v011i04/v11i04.pdf")
public static double cdf(double x, double mu, double sigma) {
  x = (x - mu) / sigma;
  if(x >= 8.22) {
    return 1.;
  }
  if(x <= -8.22) {
    return 0.;
  }
  if(x != x) {
    return Double.NaN;
  }
  double s = x, t = 0, b = x, q = x * x, i = 1;
  while(s != t && i < 1000) {
    t = s;
    s += (b *= q / (i += 2));
  }
  // Constant is 0.5 * log(2*pi)
  return .5 + s * FastMath.exp(-.5 * q - .91893853320467274178);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:39,代码来源:NormalDistribution.java


示例10: initializeBandwidth

import net.jafama.FastMath; //导入依赖的package包/类
@Reference(authors = "D. W. Scott", title = "Multivariate density estimation: Theory, Practice, and Visualization", //
    booktitle = "Multivariate Density Estimation: Theory, Practice, and Visualization", //
    url = "http://dx.doi.org/10.1002/9780470316849")
private double[] initializeBandwidth(double[][] data) {
  MeanVariance mv0 = new MeanVariance();
  MeanVariance mv1 = new MeanVariance();
  // For Kernel bandwidth.
  for(double[] projected : data) {
    mv0.put(projected[0]);
    mv1.put(projected[1]);
  }
  // Set bandwidths according to Scott's rule:
  // Note: in projected space, d=2.
  double[] bandwidth = new double[2];
  bandwidth[0] = MathUtil.SQRT5 * mv0.getSampleStddev() * FastMath.pow(rel.size(), -1 / 6.);
  bandwidth[1] = MathUtil.SQRT5 * mv1.getSampleStddev() * FastMath.pow(rel.size(), -1 / 6.);
  return bandwidth;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:19,代码来源:DensityEstimationOverlay.java


示例11: CorrelationAnalysisSolution

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Provides a new CorrelationAnalysisSolution holding the specified matrix and
 * number format.
 * 
 * @param solution the linear equation system describing the solution
 *        equations
 * @param db the database containing the objects
 * @param strongEigenvectors the strong eigenvectors of the hyperplane induced
 *        by the correlation
 * @param weakEigenvectors the weak eigenvectors of the hyperplane induced by
 *        the correlation
 * @param similarityMatrix the similarity matrix of the underlying distance
 *        computations
 * @param centroid the centroid if the objects belonging to the hyperplane
 *        induced by the correlation
 * @param nf the number format for output accuracy
 */
public CorrelationAnalysisSolution(LinearEquationSystem solution, Relation<V> db, double[][] strongEigenvectors, double[][] weakEigenvectors, double[][] similarityMatrix, double[] centroid, NumberFormat nf) {
  this.linearEquationSystem = solution;
  this.correlationDimensionality = strongEigenvectors[0].length;
  this.strongEigenvectors = strongEigenvectors;
  this.weakEigenvectors = weakEigenvectors;
  this.similarityMatrix = similarityMatrix;
  this.centroid = centroid;
  this.nf = nf;

  // determine standard deviation
  double variance = 0;
  DBIDs ids = db.getDBIDs();
  for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
    double distance = distance(db.get(iter).toArray());
    variance += distance * distance;
  }
  standardDeviation = FastMath.sqrt(variance / ids.size());
}
 
开发者ID:elki-project,项目名称:elki,代码行数:36,代码来源:CorrelationAnalysisSolution.java


示例12: ecefToLatLngRadHeight

import net.jafama.FastMath; //导入依赖的package包/类
@Override
public double[] ecefToLatLngRadHeight(double x, double y, double z) {
  double lng = FastMath.atan2(y, x);
  final double p = FastMath.sqrt(x * x + y * y);
  double plat = FastMath.atan2(z, p * (1 - esq));
  double h = 0;

  // Iteratively improving the lat value
  // TODO: instead of a fixed number of iterations, check for convergence?
  for (int i = 0;; i++) {
    final double slat = FastMath.sin(plat);
    final double v = a / FastMath.sqrt(1 - esq * slat * slat);
    double lat = FastMath.atan2(z + esq * v * slat, p);
    if (Math.abs(lat - plat) < PRECISION || i > MAX_ITER) {
      h = p / FastMath.cos(lat) - v;
      return new double[] { lat, lng, h };
    }
    plat = lat;
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:21,代码来源:AbstractEarthModel.java


示例13: dependence

import net.jafama.FastMath; //导入依赖的package包/类
@Override
public <A, B> double dependence(NumberArrayAdapter<?, A> adapter1, A data1, NumberArrayAdapter<?, B> adapter2, B data2) {
  final int len = size(adapter1, data1, adapter2, data2);
  // Find a number of bins as recommended by Cheng et al.
  double p = MathUtil.log2(len / (double) TARGET);
  // As we are in 2d, take the root (*.5) But let's use at least 1, too.
  // Check: for 10000 this should give 4, for 150 it gives 1.
  int power = Math.max(1, (int) Math.floor(p * .5));
  int gridsize = 1 << power;
  double loggrid = FastMath.log((double) gridsize);

  ArrayList<int[]> parts1 = buildPartitions(adapter1, data1, len, power);
  ArrayList<int[]> parts2 = buildPartitions(adapter2, data2, len, power);

  int[][] res = new int[gridsize][gridsize];
  intersectionMatrix(res, parts1, parts2, gridsize);
  return 1. - getMCEntropy(res, parts1, parts2, len, gridsize, loggrid);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:19,代码来源:MCEDependenceMeasure.java


示例14: rawProbability

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Poisson distribution probability, but also for non-integer arguments.
 *
 * lb^x exp(-lb) / x!
 *
 * @param x X
 * @param lambda lambda
 * @return Poisson distribution probability
 */
public static double rawProbability(double x, double lambda) {
  // Extreme lambda
  if(lambda == 0) {
    return ((x == 0) ? 1. : 0.);
  }
  // Extreme values
  if(Double.isInfinite(lambda) || x < 0) {
    return 0.;
  }
  if(x <= lambda * Double.MIN_NORMAL) {
    return FastMath.exp(-lambda);
  }
  if(lambda < x * Double.MIN_NORMAL) {
    double r = -lambda + x * FastMath.log(lambda) - GammaDistribution.logGamma(x + 1);
    return FastMath.exp(r);
  }
  final double f = MathUtil.TWOPI * x;
  final double y = -stirlingError(x) - devianceTerm(x, lambda);
  return FastMath.exp(y) / FastMath.sqrt(f);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:30,代码来源:PoissonDistribution.java


示例15: normalizeColumns

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Normalizes the columns of this matrix to length of 1.0.
 *
 * Note: if a column has length 0, it will remain unmodified.
 *
 * @param m1 Input matrix
 */
public static void normalizeColumns(final double[][] m1) {
  final int columndimension = getColumnDimensionality(m1);
  for(int col = 0; col < columndimension; col++) {
    double norm = 0.0;
    for(int row = 0; row < m1.length; row++) {
      final double v = m1[row][col];
      norm += v * v;
    }
    if(norm > 0) {
      norm = FastMath.sqrt(norm);
      for(int row = 0; row < m1.length; row++) {
        m1[row][col] /= norm;
      }
    }
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:24,代码来源:VMath.java


示例16: computeDCG

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Compute the DCG given a set of positive IDs and a sorted list of entries,
 * which may include ties.
 * 
 * @param <I> Iterator type
 * @param predicate Predicate to test for positive objects
 * @param iter Iterator over results, with ties.
 * @return area under curve
 */
public static <I extends ScoreIter> double computeDCG(Predicate<? super I> predicate, I iter) {
  double sum = 0.;
  int i = 0, positive = 0, tied = 0;
  while(iter.valid()) {
    // positive or negative match?
    do {
      if(predicate.test(iter)) {
        ++positive;
      }
      ++tied;
      ++i;
      iter.advance();
    } // Loop while tied:
    while(iter.valid() && iter.tiedToPrevious());
    // We only support binary labeling, and can ignore negative weight.
    if(positive > 0) {
      sum += tied == 1 ? 1. / FastMath.log(i + 1) : //
          DCGEvaluation.sumInvLog1p(i - tied + 1, i) * positive / (double) tied;
    }
    positive = 0;
    tied = 0;
  }
  return sum * MathUtil.LOG2; // Change base to log 2.
}
 
开发者ID:elki-project,项目名称:elki,代码行数:34,代码来源:DCGEvaluation.java


示例17: filterSingleObject

import net.jafama.FastMath; //导入依赖的package包/类
@Override
protected V filterSingleObject(V featureVector) {
  double[] raw = featureVector.toArray();
  // TODO: reduce memory consumption?
  double[] tmp = raw.clone();
  Arrays.sort(tmp);
  double scale = .5 / (raw.length - 1);
  for(int i = 0; i < raw.length; ++i) {
    final double v = raw[i];
    if(v != v) { // NaN guard
      raw[i] = CENTER;
      continue;
    }
    int first = Arrays.binarySearch(tmp, v), last = first + 1;
    assert (first >= 0);
    while(first > 0 && tmp[first - 1] >= v) {
      --first;
    }
    while(last < tmp.length && tmp[last] <= v) {
      ++last;
    }
    raw[i] = FastMath.log1p((first + last - 1) * scale) * MathUtil.ONE_BY_LOG2;
  }
  return factory.newNumberVector(raw);
}
 
开发者ID:elki-project,项目名称:elki,代码行数:26,代码来源:InstanceLogRankNormalization.java


示例18: linearScan

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Main loop for linear scan,
 * 
 * @param relation Data relation
 * @param iter Iterator
 * @param obj Query object
 * @param range Query radius
 * @param result Output data structure
 */
private void linearScan(Relation<? extends O> relation, DBIDIter iter, O obj, double range, ModifiableDoubleDBIDList result) {
  final SquaredEuclideanDistanceFunction squared = SquaredEuclideanDistanceFunction.STATIC;
  // Avoid a loss in numerical precision when using the squared radius:
  final double upper = range * 1.0000001;
  // This should be more precise, but slower:
  // upper = MathUtil.floatToDoubleUpper((float)range);
  final double sqrange = upper * upper;
  while(iter.valid()) {
    final double sqdistance = squared.distance(obj, relation.get(iter));
    if(sqdistance <= sqrange) {
      final double dist = FastMath.sqrt(sqdistance);
      if(dist <= range) { // double check, as we increased the radius above
        result.add(dist, iter);
      }
    }
    iter.advance();
  }
}
 
开发者ID:elki-project,项目名称:elki,代码行数:28,代码来源:LinearScanEuclideanDistanceRangeQuery.java


示例19: DiagonalGaussianModel

import net.jafama.FastMath; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param weight Cluster weight
 * @param mean Initial mean
 * @param variances Initial variances.
 */
public DiagonalGaussianModel(double weight, double[] mean, double[] variances) {
  this.weight = weight;
  final int dim = mean.length;
  this.mean = mean;
  this.logNorm = MathUtil.LOGTWOPI * mean.length;
  this.logNormDet = FastMath.log(weight) - .5 * logNorm;
  this.nmea = new double[dim];
  if(variances == null) {
    this.variances = new double[dim];
    Arrays.fill(variances, 1.);
  }
  else {
    this.variances = variances;
    this.priordiag = copy(variances);
  }
  this.wsum = 0.;
}
 
开发者ID:elki-project,项目名称:elki,代码行数:25,代码来源:DiagonalGaussianModel.java


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Animatable2类代码示例发布时间:2022-05-22
下一篇:
Java FragmentContext类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap