本文整理汇总了Java中cc.mallet.util.Randoms.nextGaussian方法的典型用法代码示例。如果您正苦于以下问题:Java Randoms.nextGaussian方法的具体用法?Java Randoms.nextGaussian怎么用?Java Randoms.nextGaussian使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.util.Randoms
的用法示例。
在下文中一共展示了Randoms.nextGaussian方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sample
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public Assignment sample (Randoms r)
{
// generate from standard normal
double[] vals = new double [mean.size ()];
for (int k = 0; k < vals.length; k++) {
vals[k] = r.nextGaussian ();
}
// and transform
Vector Z = new DenseVector (vals, false);
DenseVector result = new DenseVector (vals.length);
variance.mult (Z, result);
result = (DenseVector) result.add (mean);
return new Assignment (vars.toVariableArray (), result.getData ());
}
示例2: nextWishart
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
/**
* A Wishart random variate, based on R code by Bill Venables.
*
* @param sqrtScaleMatrix The lower-triangular matrix square root of the scale matrix.
* To draw from the posterior of a precision (ie inverse covariance) matrix,
* this should be chol( S^{-1} ), where S is the scatter matrix X'X of
* columns of MV normal observations X.
* @param dimension The size of the matrix
* @param degreesOfFreedom The degree of freedom for the Wishart. Should be greater than dimension. For
* a posterior distribution, this is the number of observations + the df of the prior.
*/
public static double[] nextWishart(double[] sqrtScaleMatrix, int dimension,
int degreesOfFreedom, Randoms random) {
double[] sample = new double[sqrtScaleMatrix.length];
for (int row = 0; row < dimension; row++) {
for (int col = 0; col < row; col++) {
sample[ (row * dimension) + col ] = random.nextGaussian(0, 1);
}
sample[ (row * dimension) + row ] = Math.sqrt(random.nextChiSq(degreesOfFreedom));
}
//System.out.println(doubleArrayToString(sample, dimension));
//System.out.println(doubleArrayToString(sqrtScaleMatrix, dimension));
//System.out.println(doubleArrayToString(lowerTriangularProduct(sample, sqrtScaleMatrix, dimension), dimension));
System.out.println(diagonalToString(sample, dimension));
System.out.println(diagonalToString(sqrtScaleMatrix, dimension));
System.out.println(diagonalToString(lowerTriangularProduct(sample, sqrtScaleMatrix, dimension), dimension));
return lowerTriangularCrossproduct(lowerTriangularProduct(sample, sqrtScaleMatrix, dimension), dimension);
}
示例3: RandomFeatureVectorIterator
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public RandomFeatureVectorIterator (Randoms r,
// the generator of all random-ness used here
Dirichlet classCentroidDistribution,
// includes a Alphabet
double classCentroidAvergeAlphaMean,
// Gaussian mean on the sum of alphas
double classCentroidAvergeAlphaVariance,
// Gaussian variance on the sum of alphas
double featureVectorSizePoissonLambda,
double classInstanceCountPoissonLamba,
String[] classNames)
{
this.r = r;
this.classCentroidDistribution = classCentroidDistribution;
assert (classCentroidDistribution.getAlphabet() instanceof Alphabet);
this.classCentroidAvergeAlphaMean = classCentroidAvergeAlphaMean;
this.classCentroidAvergeAlphaVariance = classCentroidAvergeAlphaVariance;
this.featureVectorSizePoissonLambda = featureVectorSizePoissonLambda;
this.classInstanceCountPoissonLamba = classInstanceCountPoissonLamba;
this.classNames = classNames;
this.numInstancesPerClass = new int[classNames.length];
this.classCentroid = new Dirichlet[classNames.length];
for (int i = 0; i < classNames.length; i++) {
logger.fine ("classCentroidAvergeAlphaMean = "+classCentroidAvergeAlphaMean);
double aveAlpha = r.nextGaussian (classCentroidAvergeAlphaMean,
classCentroidAvergeAlphaVariance);
logger.fine ("aveAlpha = "+aveAlpha);
classCentroid[i] = classCentroidDistribution.randomDirichlet (r, aveAlpha);
//logger.fine ("Dirichlet for class "+classNames[i]); classCentroid[i].print();
}
reset ();
}
示例4: RandomTokenSequenceIterator
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public RandomTokenSequenceIterator (Randoms r,
// the generator of all random-ness used here
Dirichlet classCentroidDistribution,
// includes a Alphabet
double classCentroidAvergeAlphaMean,
// Gaussian mean on the sum of alphas
double classCentroidAvergeAlphaVariance,
// Gaussian variance on the sum of alphas
double featureVectorSizePoissonLambda,
double classInstanceCountPoissonLamba,
String[] classNames)
{
this.r = r;
this.classCentroidDistribution = classCentroidDistribution;
assert (classCentroidDistribution.getAlphabet() instanceof Alphabet);
this.classCentroidAvergeAlphaMean = classCentroidAvergeAlphaMean;
this.classCentroidAvergeAlphaVariance = classCentroidAvergeAlphaVariance;
this.featureVectorSizePoissonLambda = featureVectorSizePoissonLambda;
this.classInstanceCountPoissonLamba = classInstanceCountPoissonLamba;
this.classNames = classNames;
this.numInstancesPerClass = new int[classNames.length];
this.classCentroid = new Dirichlet[classNames.length];
for (int i = 0; i < classNames.length; i++) {
logger.fine ("classCentroidAvergeAlphaMean = "+classCentroidAvergeAlphaMean);
double aveAlpha = r.nextGaussian (classCentroidAvergeAlphaMean,
classCentroidAvergeAlphaVariance);
logger.fine ("aveAlpha = "+aveAlpha);
classCentroid[i] = classCentroidDistribution.randomDirichlet (r, aveAlpha);
//logger.fine ("Dirichlet for class "+classNames[i]); classCentroid[i].print();
}
reset ();
}
示例5: nextMVNormalWithCholesky
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public static double[] nextMVNormalWithCholesky(double[] mean, double[] precisionLowerTriangular,
Randoms random) {
int n = mean.length;
// Initialize vector z to standard normals
// [NB: using the same array for z and x]
double[] result = new double[ n ];
for (int i = 0; i < n; i++) {
result[i] = random.nextGaussian();
}
// Now solve trans(L) x = z using back substitution
double innerProduct;
for (int i = n-1; i >= 0; i--) {
innerProduct = 0.0;
for (int j = i+1; j < n; j++) {
// the cholesky decomp got us the precisionLowerTriangular triangular
// matrix, but we really want the transpose.
innerProduct += result[j] * precisionLowerTriangular[ (n * j) + i ];
}
result[i] = (result[i] - innerProduct) / precisionLowerTriangular[ (n * i) + i ];
}
for (int i = 0; i < n; i++) {
result[i] += mean[i];
}
return result;
}
示例6: sample
import cc.mallet.util.Randoms; //导入方法依赖的package包/类
public Assignment sample (Randoms r)
{
double val = r.nextGaussian (mean, variance);
return new Assignment (var, val);
}