本文整理汇总了Java中net.jafama.FastMath类的典型用法代码示例。如果您正苦于以下问题:Java FastMath类的具体用法?Java FastMath怎么用?Java FastMath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastMath类属于net.jafama包,在下文中一共展示了FastMath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
}
示例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;
}
}
示例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));
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
}
示例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));
}
示例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);
}
示例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;
}
示例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());
}
示例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;
}
}
示例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);
}
示例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);
}
示例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;
}
}
}
}