本文整理汇总了Java中net.jafama.FastMath.log1p方法的典型用法代码示例。如果您正苦于以下问题:Java FastMath.log1p方法的具体用法?Java FastMath.log1p怎么用?Java FastMath.log1p使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.jafama.FastMath
的用法示例。
在下文中一共展示了FastMath.log1p方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: estimate
import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double estimate(RangeQuery<?> rnq, DBIDRef cur, double range) {
int a = 0;
double sum = 0;
final double halfw = 0.5 * range;
for(DoubleDBIDListIter it = rnq.getRangeForDBID(cur, range).iter(); it.valid(); it.advance()) {
if(it.doubleValue() == 0. || DBIDUtil.equal(cur, it)) {
continue;
}
final double v = it.doubleValue();
sum += v < halfw ? FastMath.log(v / range) : FastMath.log1p((v - range) / range);
++a;
final double nw = range - v;
final double halfnw = 0.5 * nw;
for(DoubleDBIDListIter it2 = rnq.getRangeForDBID(it, nw).iter(); it.valid(); it.advance()) {
if(it2.doubleValue() <= 0. || DBIDUtil.equal(it, it2)) {
continue;
}
final double v2 = it2.doubleValue();
sum += v2 < halfnw ? FastMath.log(v2 / nw) : FastMath.log1p((v2 - nw) / nw);
++a;
}
}
return -a / sum;
}
示例3: pdf
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 pdf(double val, double loc, double scale, double shape1, double shape2) {
val = (val - loc) / scale;
final double logc = logcdf(val, shape1, shape2);
if(shape1 == 1.) {
// Then val will usually become 0.
return val >= 1 ? 0 : FastMath.exp(logc * (1. - shape2)) / scale;
}
if(shape1 != 0.) {
val = shape1 * val;
if(val >= 1) {
return 0;
}
val = (1. - 1. / shape1) * FastMath.log1p(-val);
}
if(Double.isInfinite(val)) {
return 0;
}
val = FastMath.exp(-val);
if(Double.isInfinite(val)) {
return 0;
}
return val / scale * FastMath.exp(logc * (1. - shape2));
}
示例4: 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);
}
示例5: 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;
}
示例6: filterSingleObject
import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
protected V filterSingleObject(V featureVector) {
double[] data = new double[featureVector.getDimensionality()];
for(int d = 0; d < data.length; ++d) {
data[d] = featureVector.doubleValue(d);
data[d] = FastMath.log1p((data[d] > 0 ? data[d] : -data[d]) * boost) * scale;
}
return factory.newNumberVector(data);
}
示例7: logcdf
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* log Cumulative density function.
*
* TODO: untested.
*
* @param val Value
* @param loc Location
* @param scale Scale
* @return log PDF
*/
public static double logcdf(double val, double loc, double scale) {
val = (val - loc) / scale;
if (val <= 18.) {
return -FastMath.log1p(FastMath.exp(-val));
} else if (val > 33.3) {
return val;
} else {
return val - FastMath.exp(val);
}
}
示例8: 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);
agg += FastMath.log1p(Math.abs(xd - yd));
}
return agg;
}
示例9: pdf
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* Probability density function of the skewed normal distribution.
*
* @param x The value.
* @param mu The mean.
* @param sigma The standard deviation.
* @return PDF of the given normal distribution at x.
*/
public static double pdf(double x, double mu, double sigma, double skew) {
x = (x - mu) / sigma; // Scale
if(skew == 0.) {
return MathUtil.ONE_BY_SQRTTWOPI / sigma * FastMath.exp(-.5 * x * x);
}
final double y = -FastMath.log1p(-skew * x) / skew;
if(y != y || y == Double.POSITIVE_INFINITY || y == Double.NEGATIVE_INFINITY) { // NaN
return 0.;
}
return MathUtil.ONE_BY_SQRTTWOPI / sigma * FastMath.exp(-.5 * y * y) / (1 - skew * x);
}
示例10: 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));
}
示例11: logpdf
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* LogGamma distribution logPDF
*
* @param x query value
* @param k Alpha
* @param theta Theta = 1 / Beta
* @return log probability density
*/
public static double logpdf(double x, double k, double theta, double shift) {
x = (x - shift);
if(x <= 0.) {
return Double.NEGATIVE_INFINITY;
}
final double log1px = FastMath.log1p(x);
return k * FastMath.log(theta) - GammaDistribution.logGamma(k) - (theta + 1.) * log1px + (k - 1) * FastMath.log(log1px);
}
示例12: logpdf
import net.jafama.FastMath; //导入方法依赖的package包/类
@Override
public double logpdf(double val) {
if(val < 0. || val > 1.) {
return Double.NEGATIVE_INFINITY;
}
if(val == 0.) {
return (alpha > 1.) ? Double.NEGATIVE_INFINITY : (alpha < 1.) ? Double.POSITIVE_INFINITY : FastMath.log(beta);
}
if(val == 1.) {
return (beta > 1.) ? Double.NEGATIVE_INFINITY : (beta < 1.) ? Double.POSITIVE_INFINITY : FastMath.log(alpha);
}
return -logbab + FastMath.log(val) * (alpha - 1) + FastMath.log1p(-val) * (beta - 1);
}
示例13: regularizedIncBetaQuadrature
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* Returns the regularized incomplete beta function I_x(a, b) by quadrature,
* based on the book "Numerical Recipes".
*
* @param alpha Parameter a
* @param beta Parameter b
* @param x Parameter x
* @return result
*/
protected static double regularizedIncBetaQuadrature(double alpha, double beta, double x) {
final double alphapbeta = alpha + beta;
final double a1 = alpha - 1.0;
final double b1 = beta - 1.0;
final double mu = alpha / alphapbeta;
final double lnmu = FastMath.log(mu);
final double lnmuc = FastMath.log1p(-mu);
double t = FastMath.sqrt(alpha * beta / (alphapbeta * alphapbeta * (alphapbeta + 1.0)));
final double xu;
if(x > alpha / alphapbeta) {
if(x >= 1.0) {
return 1.0;
}
xu = Math.min(1.0, Math.max(mu + 10.0 * t, x + 5.0 * t));
}
else {
if(x <= 0.0) {
return 0.0;
}
xu = Math.max(0.0, Math.min(mu - 10.0 * t, x - 5.0 * t));
}
double sum = 0.0;
for(int i = 0; i < GAUSSLEGENDRE_Y.length; i++) {
t = x + (xu - x) * GAUSSLEGENDRE_Y[i];
sum += GAUSSLEGENDRE_W[i] * FastMath.exp(a1 * (FastMath.log(t) - lnmu) + b1 * (FastMath.log1p(-t) - lnmuc));
}
double ans = sum * (xu - x) * FastMath.exp(a1 * lnmu - GammaDistribution.logGamma(alpha) + b1 * lnmuc - GammaDistribution.logGamma(beta) + GammaDistribution.logGamma(alphapbeta));
return ans > 0 ? 1.0 - ans : -ans;
}
示例14: precomputeLogs
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* Grow the log[i] cache.
*
* @param len Required size
*/
private synchronized void precomputeLogs(int len) {
if(len <= ilogs.length) {
return; // Probably done by another thread.
}
double[] logs = Arrays.copyOf(ilogs, len);
for(int i = ilogs.length; i < len; i++) {
logs[i] = FastMath.log1p(i);
}
this.ilogs = logs;
}
示例15: Log1PlusNormalization
import net.jafama.FastMath; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param boost Boosting parameter
*/
public Log1PlusNormalization(double boost) {
super();
this.boost = boost;
this.scale = 1. / FastMath.log1p(boost);
}