本文整理汇总了Java中org.apache.commons.math.special.Gamma类的典型用法代码示例。如果您正苦于以下问题:Java Gamma类的具体用法?Java Gamma怎么用?Java Gamma使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Gamma类属于org.apache.commons.math.special包,在下文中一共展示了Gamma类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: partitionGet
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
@Override
public PartitionGetResult partitionGet(PartitionGetParam partParam) {
PartitionKey pkey = partParam.getPartKey();
pkey = psContext.getMatrixMetaManager().getMatrixMeta(pkey.getMatrixId())
.getPartitionMeta(pkey.getPartitionId()).getPartitionKey();
int ws = pkey.getStartRow();
int es = pkey.getEndRow();
LikelihoodParam.LikelihoodPartParam param = (LikelihoodParam.LikelihoodPartParam) partParam;
float beta = param.getBeta();
double lgammaBeta = Gamma.logGamma(beta);
double ll = 0;
for (int w = ws; w < es; w ++) {
ServerRow row = psContext.getMatrixStorageManager().getRow(pkey, w);
ll += likelihood(row, beta, lgammaBeta);
}
return new ScalarPartitionAggrResult(ll);
}
开发者ID:Tencent,项目名称:angel,代码行数:24,代码来源:LikelihoodFunc.java
示例2: Sampler
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
public Sampler(CSRTokens data, LDAModel model) {
this.data = data;
this.model = model;
K = model.K();
alpha = model.alpha();
beta = model.beta();
vbeta = data.n_words * beta;
lgammaBeta = Gamma.logGamma(beta);
lgammaAlpha = Gamma.logGamma(alpha);
lgammaAlphaSum = Gamma.logGamma(alpha * K);
nk = new int[K];
wk = new int[K];
tidx = new short[K];
psum = new float[K];
tree = new FTree(K);
}
开发者ID:Tencent,项目名称:angel,代码行数:21,代码来源:Sampler.java
示例3: dpois_raw
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
public static double dpois_raw(double x, double lambda, boolean give_log) {
/* x >= 0 ; integer for dpois(), but not e.g. for pgamma()!
lambda >= 0
*/
if (lambda == 0) {
return ((x == 0) ? SignRank.R_D__1(true, give_log) : SignRank.R_D__0(true, give_log));
}
if (!DoubleVector.isFinite(lambda)) {
return SignRank.R_D__0(true, give_log);
}
if (x < 0) {
return (SignRank.R_D__0(true, give_log));
}
if (x <= lambda * Double.MIN_VALUE) {
return (SignRank.R_D_exp(-lambda, true, give_log));
}
if (lambda < x * Double.MIN_VALUE) {
return (SignRank.R_D_exp(-lambda + x * Math.log(lambda) - Gamma.logGamma(x + 1), true, give_log));
}
return (SignRank.R_D_fexp(2 * Math.PI * x, -Binom.stirlerr(x) - Binom.bd0(x, lambda), true, give_log));
}
开发者ID:CompEvol,项目名称:beastshell,代码行数:22,代码来源:Poisson.java
示例4: testMomonts
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
public void testMomonts() {
final double tol = 1e-9;
WeibullDistribution dist;
dist = new WeibullDistributionImpl(2.5, 3.5);
// In R: 3.5*gamma(1+(1/2.5)) (or emperically: mean(rweibull(10000, 2.5, 3.5)))
assertEquals(dist.getNumericalMean(), 3.5 * FastMath.exp(Gamma.logGamma(1 + (1 / 2.5))), tol);
assertEquals(dist.getNumericalVariance(), (3.5 * 3.5) *
FastMath.exp(Gamma.logGamma(1 + (2 / 2.5))) -
(dist.getNumericalMean() * dist.getNumericalMean()), tol);
dist = new WeibullDistributionImpl(10.4, 2.222);
assertEquals(dist.getNumericalMean(), 2.222 * FastMath.exp(Gamma.logGamma(1 + (1 / 10.4))), tol);
assertEquals(dist.getNumericalVariance(), (2.222 * 2.222) *
FastMath.exp(Gamma.logGamma(1 + (2 / 10.4))) -
(dist.getNumericalMean() * dist.getNumericalMean()), tol);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:WeibullDistributionTest.java
示例5: testMomonts
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
@Test
public void testMomonts() {
final double tol = 1e-9;
WeibullDistribution dist;
dist = new WeibullDistributionImpl(2.5, 3.5);
// In R: 3.5*gamma(1+(1/2.5)) (or emperically: mean(rweibull(10000, 2.5, 3.5)))
Assert.assertEquals(dist.getNumericalMean(), 3.5 * FastMath.exp(Gamma.logGamma(1 + (1 / 2.5))), tol);
Assert.assertEquals(dist.getNumericalVariance(), (3.5 * 3.5) *
FastMath.exp(Gamma.logGamma(1 + (2 / 2.5))) -
(dist.getNumericalMean() * dist.getNumericalMean()), tol);
dist = new WeibullDistributionImpl(10.4, 2.222);
Assert.assertEquals(dist.getNumericalMean(), 2.222 * FastMath.exp(Gamma.logGamma(1 + (1 / 10.4))), tol);
Assert.assertEquals(dist.getNumericalVariance(), (2.222 * 2.222) *
FastMath.exp(Gamma.logGamma(1 + (2 / 10.4))) -
(dist.getNumericalMean() * dist.getNumericalMean()), tol);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:WeibullDistributionTest.java
示例6: functionLogZ
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
protected double functionLogZ(double[] vector){
double valueFunction;
double sum=0;
double logpart1=0;
// log(prod(X))=log(X1)+log(X2)+.........+log(Xn)
for(int i=0;i<vector.length;i++){
logpart1=logpart1+Gamma.logGamma(vector[i]);
sum=sum+vector[i];
}
double logpart2 = Gamma.logGamma(sum);
valueFunction = logpart1-logpart2;
return valueFunction;
}
开发者ID:active-learning,项目名称:active-learning-scala,代码行数:19,代码来源:EncodingCost.java
示例7: likelihood
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
private double likelihood(ServerRow row, float beta, double lgammaBeta) {
int len = (int)(row.getEndCol() - row.getStartCol());
double ll = 0;
if (row instanceof ServerDenseIntRow) {
IntBuffer buf = ((ServerDenseIntRow) row).getData();
for (int i = 0; i < len; i ++) {
if (buf.get(i) > 0)
ll += Gamma.logGamma(buf.get(i) + beta) - lgammaBeta;
}
} else
throw new AngelException("should be ServerDenseIntRow");
return ll;
}
开发者ID:Tencent,项目名称:angel,代码行数:14,代码来源:LikelihoodFunc.java
示例8: evaluate
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
@Override
public Double evaluate(final Double x) {
try {
return Gamma.regularizedGammaP(_a, x, _eps, _maxIter);
} catch (final org.apache.commons.math.MathException e) {
throw new MathException(e);
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:9,代码来源:IncompleteGammaFunction.java
示例9: evaluate
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
@Override
public Double evaluate(final Double x) {
if (x > 0.0) {
return Math.exp(Gamma.logGamma(x));
}
return Math.PI / Math.sin(Math.PI * x) / evaluate(1 - x);
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:8,代码来源:GammaFunction.java
示例10: NonCentralChiSquaredDistribution
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* @param degrees The number of degrees of freedom, not negative or zero
* @param nonCentrality The non-centrality parameter, not negative
*/
public NonCentralChiSquaredDistribution(final double degrees, final double nonCentrality) {
Validate.isTrue(degrees > 0, "degrees of freedom must be > 0, have " + degrees);
Validate.isTrue(nonCentrality >= 0, "non-centrality must be >= 0, have " + nonCentrality);
_dofOverTwo = degrees / 2.0;
_lambdaOverTwo = nonCentrality / 2.0;
_k = (int) Math.round(_lambdaOverTwo);
if (_lambdaOverTwo == 0) {
_pStart = 0.0;
} else {
final double logP = -_lambdaOverTwo + _k * Math.log(_lambdaOverTwo) - Gamma.logGamma(_k + 1);
_pStart = Math.exp(logP);
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:19,代码来源:NonCentralChiSquaredDistribution.java
示例11: cumulativeProbability
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* The probability distribution function P(X <= x) for a Poisson distribution.
*
* @param x the value at which the PDF is evaluated.
* @return Poisson distribution function evaluated at x
* @throws MathException if the cumulative probability can not be
* computed due to convergence or other numerical errors.
*/
public double cumulativeProbability(int x) throws MathException {
if (x < 0) {
return 0;
}
if (x == Integer.MAX_VALUE) {
return 1;
}
return Gamma.regularizedGammaQ((double)x + 1, mean,
1E-12, Integer.MAX_VALUE);
}
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:19,代码来源:PoissonDistributionImpl.java
示例12: density
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* Returns the probability density for a particular point.
*
* @param x The point at which the density should be computed.
* @return The pdf at point x.
* @since 2.1
*/
@Override
public double density(double x) {
final double n = degreesOfFreedom;
final double plus1Over2 = (n + 1) / 2;
return Math.exp(Gamma.logGamma(plus1Over2) - 0.5 * (Math.log(Math.PI) + Math.log(n)) -
Gamma.logGamma(n / 2) - plus1Over2 * Math.log(1 + x * x / n));
}
开发者ID:CompEvol,项目名称:beast2,代码行数:15,代码来源:TDistributionImpl.java
示例13: cumulativeProbability
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* The probability distribution function P(X <= x) for a Poisson
* distribution.
*
* @param x the value at which the PDF is evaluated.
* @return Poisson distribution function evaluated at x
* @throws MathException if the cumulative probability can not be computed
* due to convergence or other numerical errors.
*/
@Override
public double cumulativeProbability(int x) throws MathException {
if (x < 0) {
return 0;
}
if (x == Integer.MAX_VALUE) {
return 1;
}
return Gamma.regularizedGammaQ((double) x + 1, mean, epsilon, maxIterations);
}
开发者ID:CompEvol,项目名称:beast2,代码行数:20,代码来源:PoissonDistributionImpl.java
示例14: gammaLn
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
public static Matrix gammaLn(Matrix m){
int nc = m.data.length;
int nr = m.data[0].length;
double[][] result = new double[nc][];
for (int k = 0; k < nc; ++k) {
result[k] = new double[nr];
for (int w = 0; w < nr; ++w) {
result[k][w] = Gamma.logGamma(m.data[k][w]);
}
}
return new Matrix(result);
}
开发者ID:ahujack,项目名称:online-LDA,代码行数:14,代码来源:MatrixUtil.java
示例15: dirichletExpectation
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* Digamma function (the first derivative of the logarithm of the gamma function).
* @param array - variational parameter
* @return
*/
static double[][] dirichletExpectation(double[][] array) {
int numRows = array.length;
int numCols = array[0].length;
double[] vector = new double[numRows];
Arrays.fill(vector, 0.0);
for (int k = 0; k < numRows; ++k) {
for (int w = 0; w < numCols; ++w) {
try{
vector[k] += array[k][w];
}catch (Exception e){
throw new RuntimeException(e);
}
}
}
for (int k = 0; k < numRows; ++k) {
vector[k] = Gamma.digamma(vector[k]);
}
double [][] approx = new double[numRows][];
for (int k = 0; k < numRows; ++k) {
approx[k] = new double[numCols];
for (int w = 0; w < numCols; ++w) {
double z = Gamma.digamma(array[k][w]);
approx[k][w] = z - vector[k];
}
}
return approx;
}
开发者ID:ahujack,项目名称:online-LDA,代码行数:36,代码来源:MatrixUtil.java
示例16: cumulativeProbability
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* The probability distribution function P(X <= x) for a Poisson
* distribution.
*
* @param x the value at which the PDF is evaluated.
* @return Poisson distribution function evaluated at x
* @throws MathException if the cumulative probability can not be computed
* due to convergence or other numerical errors.
*/
@Override
public double cumulativeProbability(int x) throws MathException {
if (x < 0) {
return 0;
}
if (x == Integer.MAX_VALUE) {
return 1;
}
return Gamma.regularizedGammaQ((double) x + 1, mean, 1E-12,
Integer.MAX_VALUE);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:PoissonDistributionImpl.java
示例17: calculateNumericalVariance
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* {@inheritDoc}
*
* The variance is
* <code>scale^2 * Gamma(1 + (2 / shape)) - mean^2</code>
* where <code>Gamma(...)</code> is the Gamma-function
*
* @return {@inheritDoc}
*/
@Override
protected double calculateNumericalVariance() {
final double sh = getShape();
final double sc = getScale();
final double mn = getNumericalMean();
return (sc * sc) *
FastMath.exp(Gamma.logGamma(1 + (2 / sh))) -
(mn * mn);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:WeibullDistributionImpl.java
示例18: density
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public double density(double x) {
final double n = degreesOfFreedom;
final double nPlus1Over2 = (n + 1) / 2;
return FastMath.exp(Gamma.logGamma(nPlus1Over2) -
0.5 * (FastMath.log(FastMath.PI) + FastMath.log(n)) -
Gamma.logGamma(n/2) - nPlus1Over2 * FastMath.log(1 + x * x /n));
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:TDistributionImpl.java
示例19: density
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public double density(double x) {
if (x < 0) return 0;
return FastMath.pow(x / beta, alpha - 1) / beta *
FastMath.exp(-x / beta) / FastMath.exp(Gamma.logGamma(alpha));
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:GammaDistributionImpl.java
示例20: cumulativeProbability
import org.apache.commons.math.special.Gamma; //导入依赖的package包/类
/**
* The probability distribution function {@code P(X <= x)} for a Poisson
* distribution.
*
* @param x Value at which the PDF is evaluated.
* @return the Poisson distribution function evaluated at {@code x}.
* @throws MathException if the cumulative probability cannot be computed
* due to convergence or other numerical errors.
*/
@Override
public double cumulativeProbability(int x) throws MathException {
if (x < 0) {
return 0;
}
if (x == Integer.MAX_VALUE) {
return 1;
}
return Gamma.regularizedGammaQ((double) x + 1, mean, epsilon, maxIterations);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:PoissonDistributionImpl.java
注:本文中的org.apache.commons.math.special.Gamma类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论