当前位置: 首页>>代码示例>>Java>>正文


Java Randomizer.nextGaussian方法代码示例

本文整理汇总了Java中beast.util.Randomizer.nextGaussian方法的典型用法代码示例。如果您正苦于以下问题:Java Randomizer.nextGaussian方法的具体用法?Java Randomizer.nextGaussian怎么用?Java Randomizer.nextGaussian使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在beast.util.Randomizer的用法示例。


在下文中一共展示了Randomizer.nextGaussian方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: nextMultivariateNormalCholesky

import beast.util.Randomizer; //导入方法依赖的package包/类
public static void nextMultivariateNormalCholesky(double[] mean, double[][] cholesky, double sqrtScale, double[] result) {

        final int dim = mean.length;

        System.arraycopy(mean, 0, result, 0, dim);

        double[] epsilon = new double[dim];
        for (int i = 0; i < dim; i++)
            epsilon[i] = Randomizer.nextGaussian() * sqrtScale;

        for (int i = 0; i < dim; i++) {
            for (int j = 0; j <= i; j++) {
                result[i] += cholesky[i][j] * epsilon[j];
                // caution: decomposition returns lower triangular
            }
        }
    }
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:18,代码来源:MultivariateNormal.java

示例2: getProposedVal

import beast.util.Randomizer; //导入方法依赖的package包/类
public double getProposedVal(
        double value,
        int iValue,
        boolean useGaussian,
        double[] windowSizes){

    double newValue = value;
    if (useGaussian) {
    	newValue += Randomizer.nextGaussian()* windowSizes[iValue];
    } else {
    	newValue += Randomizer.nextDouble() * 2 * windowSizes[iValue] - windowSizes[iValue];
    }


    return newValue;

}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:18,代码来源:ExtendedRealRandomWalkOperator.java

示例3: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
public double proposal() {

        RealParameter param = parameterInput.get(this);


        double value = param.getValue(index);
        double newValue = value;
        if (useGaussian) {
            newValue += Randomizer.nextGaussian() * windowSize;
        } else {
            newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
        }

        if (newValue < param.getLower() || newValue > param.getUpper()) {
            return Double.NEGATIVE_INFINITY;
        }
        if (newValue == value) {
            // this saves calculating the posterior
            return Double.NEGATIVE_INFINITY;
        }

        param.setValue(index, newValue);

        return 0.0;
    }
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:26,代码来源:SpecificRealRandomWalkOperator.java

示例4: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * override this for proposals,
 * returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
 */
@Override
public double proposal() {

    RealParameter param = parameterInput.get(this);
    for (int i = 0; i < param.getDimension(); i++){
     double value = param.getValue(i);
     double newValue = value;
     double windowSize = 0.0;
     
    	if (indicatorInput.get().getArrayValue(i) > 0.5)
    		windowSize = windowSizeOn;
    	else
    		windowSize = windowSizeOff;
    		

     if (useGaussian) {
         newValue += Randomizer.nextGaussian() * windowSize;
     } else {
         newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
     }
	
     if (newValue < param.getLower() || newValue > param.getUpper()) {
         return Double.NEGATIVE_INFINITY;
     }
     if (newValue == value) {
         // this saves calculating the posterior
         return Double.NEGATIVE_INFINITY;
     }
	
     param.setValue(i, newValue);
    }
    return 0.0;
}
 
开发者ID:nicfel,项目名称:Mascot,代码行数:38,代码来源:RealRandomWalkOperator.java

示例5: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * override this for proposals,
 * returns log of hastingRatio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
 */
@Override
public double proposal() {

    RealParameter param = parameterInput.get(this);

    int i = Randomizer.nextInt(param.getDimension());
    double value = param.getValue(i);
    double newValue = value;
    if (useGaussian) {
        newValue += Randomizer.nextGaussian() * windowSize;
    } else {
        newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
    }

    if (newValue < param.getLower() || newValue > param.getUpper()) {
        return Double.NEGATIVE_INFINITY;
    }
    if (newValue == value) {
        // this saves calculating the posterior
        return Double.NEGATIVE_INFINITY;
    }

    param.setValue(i, newValue);

    return 0.0;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:31,代码来源:RealRandomWalkOperator.java

示例6: getDelta

import beast.util.Randomizer; //导入方法依赖的package包/类
private double getDelta() {
    if (!gaussianInput.get()) {
        return (Randomizer.nextDouble() * size) - (size / 2.0);
    } else {
        return Randomizer.nextGaussian() * size;
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:8,代码来源:SubtreeSlide.java

示例7: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public double proposal() {
    // randomly select leaf node
    int i = Randomizer.nextInt(taxonIndices.length);
    Node node = treeInput.get().getNode(taxonIndices[i]);

    double value = node.getHeight();
    double newValue = value;
    if (useGaussian) {
        newValue += Randomizer.nextGaussian() * windowSize;
    } else {
        newValue += Randomizer.nextDouble() * 2 * windowSize - windowSize;
    }


    if (newValue > node.getParent().getHeight()) { // || newValue < 0.0) {
        if (reflectValue) {
            newValue = reflectValue(newValue, 0.0, node.getParent().getHeight());
        } else {
            return Double.NEGATIVE_INFINITY;
        }
    }
    if (newValue == value) {
        // this saves calculating the posterior
        return Double.NEGATIVE_INFINITY;
    }
    node.setHeight(newValue);

    return 0.0;
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:31,代码来源:TipDatesRandomWalker.java

示例8: nextWishart

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * Generate a random draw from a Wishart distribution
 * Follows Odell and Feiveson (1996) JASA 61, 199-203
 * <p/>
 * Returns a random variable with expectation = df * scaleMatrix
 *
 * @param df          degrees of freedom
 * @param scaleMatrix scaleMatrix
 * @return a random draw
 */
public static double[][] nextWishart(double df, double[][] scaleMatrix) {

    int dim = scaleMatrix.length;
    double[][] draw = new double[dim][dim];

    double[][] z = new double[dim][dim];

    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < i; j++) {
            z[i][j] = Randomizer.nextGaussian();
        }
    }

    for (int i = 0; i < dim; i++)
        z[i][i] = Math.sqrt(Randomizer.nextGamma((df - i) * 0.5, 0.5));   // sqrt of chisq with df-i dfs

    double[][] cholesky = new double[dim][dim];
    for (int i = 0; i < dim; i++) {
        for (int j = i; j < dim; j++)
            cholesky[i][j] = cholesky[j][i] = scaleMatrix[i][j];
    }

    try {
        cholesky = (new CholeskyDecomposition(cholesky)).getL();
        // caution: this returns the lower triangular form
    } catch (IllegalDimension illegalDimension) {
        throw new RuntimeException("Numerical exception in WishartDistribution");
    }

    double[][] result = new double[dim][dim];

    for (int i = 0; i < dim; i++) {
        for (int j = 0; j < dim; j++) {     // lower triangular
            for (int k = 0; k < dim; k++)     // can also be shortened
                result[i][j] += cholesky[i][k] * z[k][j];
        }
    }

    for (int i = 0; i < dim; i++) {           // lower triangular, so more efficiency is possible
        for (int j = 0; j < dim; j++) {
            for (int k = 0; k < dim; k++)
                draw[i][j] += result[i][k] * result[j][k];   // transpose of 2nd element
        }
    }

    return draw;
}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:58,代码来源:Wishart.java


注:本文中的beast.util.Randomizer.nextGaussian方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。