本文整理汇总了Java中org.apache.commons.math3.special.Gamma.digamma方法的典型用法代码示例。如果您正苦于以下问题:Java Gamma.digamma方法的具体用法?Java Gamma.digamma怎么用?Java Gamma.digamma使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.special.Gamma
的用法示例。
在下文中一共展示了Gamma.digamma方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: precomputeDenominatorForVariationalBayes
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public void precomputeDenominatorForVariationalBayes( final double sumHyperParameterLambda ) {
// Variational Bayes calculations from Bishop
precomputeInverse();
cachedSigmaInverse.timesEquals( hyperParameter_a );
double sum = 0.0;
for(int jjj = 1; jjj <= mu.length; jjj++) {
sum += Gamma.digamma( (hyperParameter_a + 1.0 - jjj) / 2.0 );
}
sum -= Math.log( sigma.det() );
sum += Math.log(2.0) * mu.length;
final double lambda = 0.5 * sum;
final double pi = Gamma.digamma( hyperParameter_lambda ) - Gamma.digamma( sumHyperParameterLambda );
final double beta = (-1.0 * mu.length) / (2.0 * hyperParameter_b);
cachedDenomLog10 = (pi / Math.log(10.0)) + (lambda / Math.log(10.0)) + (beta / Math.log(10.0));
}
示例2: calcEffectivePhis
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
protected double[] calcEffectivePhis(final double E_alpha, final double[] responsibilitiesByRho) {
final double sumResponsibilities = MathUtils.sum(responsibilitiesByRho);
final double[] result = new double[responsibilitiesByRho.length];
final int k = responsibilitiesByRho.length;
// Initialize all pseudocounts to 1, except for index 0, which is 20;
// This artificially increases the odds for a rho = 0.
final RealVector pseudocounts = new ArrayRealVector(responsibilitiesByRho.length);
pseudocounts.set(1.0);
pseudocounts.setEntry(0, 20.0);
final double sumPseudocounts = MathUtils.sum(pseudocounts.toArray());
final double term2 = Gamma.digamma(E_alpha + sumPseudocounts + sumResponsibilities);
for (int i=0; i < result.length; i++) {
final double term1 = Gamma.digamma(E_alpha/k + pseudocounts.getEntry(i) + responsibilitiesByRho[i]);
result[i] = Math.exp(term1 - term2);
}
return result;
}
示例3: MStep
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public Map<String, Double> MStep(List<Double> expectation){
Map<String, Double> parameters=new HashMap<String, Double>();
double pi=EMUtils.getPi(expectation);
parameters.put("pi", pi);
double mu=EMUtils.getMu(sample, expectation);
double logmu=EMUtils.getLogMu(sample, expectation);
// double sd=EMUtils.getSD(sample, expectation,mu);
// double n=EMUtils.getN(expectation);
double s=Math.log(mu)-logmu;
// double scale=Math.pow(sd,2)/mu;
// double shape=mu/scale;
// double shape=1/Math.pow(sd/mu,2)-1d/n;
// double scale=mu/shape;
double shape=Double.POSITIVE_INFINITY;
double shape2=(3-s+Math.pow(Math.pow(s-3,2)+24*s,0.5))/(12*s);
int it=0;
while(it<500&&Math.abs(shape-shape2)>1E-13){
shape=shape2;
shape2=shape-(Math.log(shape)-Gamma.digamma(shape)-s)/(1/shape-Gamma.trigamma(shape));
it++;
}
shape=shape2;
double scale=mu/shape;//wikipedia
if(Double.isInfinite(shape)){
System.out.println();
}
parameters.put("scale", scale);
parameters.put("shape",shape);
return parameters;
}
示例4: digamma
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public ReflexValue digamma(List<ReflexValue> params) {
if (params.size() != 1) {
throw new ReflexException(-1, "digamma needs one number parameter");
}
if (!params.get(0).isNumber()) {
throw new ReflexException(-1, "digamma needs one number parameter");
}
double value = params.get(0).asDouble();
return new ReflexValue(Gamma.digamma(value));
}
示例5: digamma
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
@Nonnull
public static float[] digamma(@Nonnull final float[] arr) {
final int k = arr.length;
final float[] ret = new float[k];
for (int i = 0; i < k; i++) {
ret[i] = (float) Gamma.digamma(arr[i]);
}
return ret;
}
示例6: updatePhiPerDoc
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
private void updatePhiPerDoc(@Nonnegative final int d,
@Nonnull final Map<String, float[]> eLogBeta_d) {
// Dirichlet expectation (2d) for gamma
final float[] gamma_d = _gamma[d];
final double digamma_gammaSum_d = Gamma.digamma(MathUtils.sum(gamma_d));
final double[] eLogTheta_d = new double[_K];
for (int k = 0; k < _K; k++) {
eLogTheta_d[k] = Gamma.digamma(gamma_d[k]) - digamma_gammaSum_d;
}
// updating phi w/ normalization
final Map<String, float[]> phi_d = _phi.get(d);
final Map<String, Float> doc = _miniBatchDocs.get(d);
for (String label : doc.keySet()) {
final float[] phi_label = phi_d.get(label);
final float[] eLogBeta_label = eLogBeta_d.get(label);
double normalizer = 0.d;
for (int k = 0; k < _K; k++) {
float phiVal = (float) Math.exp(eLogBeta_label[k] + eLogTheta_d[k]) + 1E-20f;
phi_label[k] = phiVal;
normalizer += phiVal;
}
for (int k = 0; k < _K; k++) {
phi_label[k] /= normalizer;
}
}
}
示例7: expectationLnLambda
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
private double expectationLnLambda() {
double ex_ln_lambda = D * Math.log(2) + logDetOmega;
for (int i = 1; i <= D; i++) {
ex_ln_lambda += Gamma.digamma(0.5 * (nu + 1 - i));
}
return ex_ln_lambda;
}
示例8: getExpectationLogDeterminantLambda
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public double getExpectationLogDeterminantLambda() {
double ex_log_lambda = D * Math.log(2) + logDetOmega;
for (int i=0; i<D; i++) {
ex_log_lambda += Gamma.digamma(0.5 * (nu - i));
}
return ex_log_lambda;
}
示例9: calcExpectationLog
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
@Override
public double[] calcExpectationLog() {
double[] exLogMixing = new double[K];
for (int i = 0; i < K; i++) {
exLogMixing[i] = Gamma.digamma(coeffs[i]) - Gamma.digamma(sumCoeffs);
}
return exLogMixing;
}
示例10: calcExpectationLog
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
@Override
public double[] calcExpectationLog() {
double[] lnMixingContribution = new double[T];
double cumulativeAlreadyAssigned = 0;
for (int t = 0; t < T; t++) {
// Calculate Mixing coefficient contributions to r
lnMixingContribution[t] = cumulativeAlreadyAssigned + (Gamma.digamma(shapeParams[t][0]) - Gamma.digamma(shapeParams[t][0] + shapeParams[t][1]));
cumulativeAlreadyAssigned += Gamma.digamma(shapeParams[t][1]) - Gamma.digamma(shapeParams[t][0] + shapeParams[t][1]);
}
return lnMixingContribution;
}
示例11: muDerivative
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
private double muDerivative(double mu, int[] cytosines, int[] depth, double thetaEst, double muEst) {
double derivative = 0.0d;
// System.err.print("computing derivative for mu "+mu+", muest "+muEst+". ");
for (int j = 0; j < cytosines.length; j++) {
derivative += Gamma.digamma(muEst * thetaEst + cytosines[j]) - Gamma.digamma((1 - mu) * thetaEst +
depth[j] - cytosines[j])
- Gamma.digamma(mu * thetaEst) + Gamma.digamma((1 - mu) * thetaEst);
}
// System.err.println("computing mu derivative "+mu+ " "+derivative);
return derivative;
}
示例12: digamma
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
/**
* Overloaded digamma function: returns 0 if argument is zero
*
* @param x
* @return digamma(x) if x nonzero, otherwise zero
*/
private double digamma(final double x) {
if (Math.abs(x) < 1e-15)
return 0.0;
else
return Gamma.digamma(x);
}
示例13: effectiveMultinomialWeights
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public double[] effectiveMultinomialWeights() {
final double digammaOfSum = Gamma.digamma(GvcfMathUtils.sum(alpha));
return GvcfMathUtils.applyToArray(alpha, a -> Math.exp(Gamma.digamma(a) - digammaOfSum));
}
示例14: effectiveLog10MultinomialWeights
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
public double[] effectiveLog10MultinomialWeights() {
final double digammaOfSum = Gamma.digamma(GvcfMathUtils.sum(alpha));
return GvcfMathUtils.applyToArray(alpha, a -> (Gamma.digamma(a) - digammaOfSum) * GvcfMathUtils.LOG10_OF_E);
}
示例15: op
import org.apache.commons.math3.special.Gamma; //导入方法依赖的package包/类
@Override
public double op(double d) {
return Double.isNaN(d) ? Double.NaN : Gamma.digamma(d);
}