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


Java Randomizer.nextDouble方法代码示例

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


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

示例1: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * change the parameter and return the hastings ratio.
 *
 * @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
 */
@Override
public double proposal() {
    final Tree tree = treeInput.get(this);
    final int nNodeCount = tree.getNodeCount();
    int leafNodeCount = tree.getLeafNodeCount();

    //make sure that there is at least one non-fake and non-root internal node
    int fakeNodeCount = ((ZeroBranchSATree)tree).getDirectAncestorNodeCount();
    if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !((ZeroBranchSANode)tree.getRoot()).isFake())) {
        return Double.NEGATIVE_INFINITY;
    }

    // randomly select internal node
    Node node;
    do {
        node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
    } while (node.isRoot() || ((ZeroBranchSANode)node).isFake());
    final double fUpper = node.getParent().getHeight();
    final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
    final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
    node.setHeight(newValue);

    return 0.0;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:30,代码来源:UniformForZeroBranchSATrees.java

示例2: simulateTransClock

import beast.util.Randomizer; //导入方法依赖的package包/类
private static double[] simulateTransClock(double diversLower, double diversUpper, boolean simClock, double clock, double r) throws Exception {
    double[] rates = new double[8];
    double d = diversLower + Randomizer.nextDouble()*(diversUpper - diversLower); //diversificationRate
    double r_turnover = Randomizer.nextDouble(); // turnover
    double s = 0.5 + Randomizer.nextDouble()*0.5; // sampling proportion
    if (simClock) {
        LogNormalDistributionModel logNorm = new LogNormalDistributionModel();
        logNorm.initByName("M", "-4.6");
        logNorm.initByName("S", "1.25");
        logNorm.initAndValidate();
        clock = ((LogNormalDistributionModel.LogNormalImpl)logNorm.getDistribution()).inverseCumulativeProbability(Randomizer.nextDouble());
    }

    rates[0] = d/(1-r_turnover); // lambda
    rates[1] = r_turnover*rates[0]; //mu
    rates[2] = rates[1]*s/(1-s);// psi
    rates[3] = Randomizer.nextDouble(); //r
    rates[4] = clock;
    rates[5] = d;
    rates[6] = r_turnover;
    rates[7] = s;
    return rates;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:24,代码来源:SABDTreeSimulator.java

示例3: testPdf

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

        System.out.println("Testing 10000 random pdf calls");

        for (int i = 0; i < 10000; i++) {
            double M = Randomizer.nextDouble() * 10.0 - 5.0;
            double S = Randomizer.nextDouble() * 10;

            double x = Randomizer.nextDouble() * 10;

            norm.meanInput.setValue(M + "", norm);
            norm.sigmaInput.setValue(S + "", norm);
            norm.initAndValidate();
            
            double a = 1.0 / (Math.sqrt(2.0 * Math.PI) * S);
            double b = -(x - M) * (x - M) / (2.0 * S * S);
            double pdf =  a * Math.exp(b);

            assertEquals(pdf, norm.density(x), 1e-10);
        }

        /* Test with an example using R */
        norm.meanInput.setValue(2.835202292812448 + "", norm);
        norm.sigmaInput.setValue(3.539139491639669 + "", norm);
        assertEquals(0.1123318, norm.density(2.540111), 1e-6);
    }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:27,代码来源:NormalDistributionTest.java

示例4: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * change the parameter and return the hastings ratio.
 *
 * @return log of Hastings Ratio, or Double.NEGATIVE_INFINITY if proposal should not be accepted *
 */
@Override
public double proposal() {
    final Tree tree = treeInput.get(this);
    final int nNodeCount = tree.getNodeCount();
    int leafNodeCount = tree.getLeafNodeCount();

    //make sure that there is at least one non-fake and non-root internal node
    int fakeNodeCount = tree.getDirectAncestorNodeCount();
    if (fakeNodeCount == leafNodeCount-1 || (fakeNodeCount == leafNodeCount-2 && !tree.getRoot().isFake())) {
        return Double.NEGATIVE_INFINITY;
    }

    // randomly select internal node
    Node node;
    do {
        node = tree.getNode(leafNodeCount + Randomizer.nextInt(nNodeCount / 2));
    } while (node.isRoot() || node.isFake());
    final double fUpper = node.getParent().getHeight();
    final double fLower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
    final double newValue = (Randomizer.nextDouble() * (fUpper - fLower)) + fLower;
    node.setHeight(newValue);

    return 0.0;
}
 
开发者ID:CompEvol,项目名称:sampled-ancestors,代码行数:30,代码来源:SAUniform.java

示例5: testMean

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

        for (int i = 0; i < 1000; i++) {
            double M = Randomizer.nextDouble() * 10.0 - 5.0;
            double S = Randomizer.nextDouble() * 10;

            logNormal.MParameterInput.setValue(M + "", logNormal);
            logNormal.SParameterInput.setValue(S + "", logNormal);
            logNormal.initAndValidate();
            
            double mean = Math.exp(M + S * S / 2);

            //System.out.println("Testing logNormal[M=" + M + " S=" + S + "].mean()");

            assertEquals(mean, logNormal.getMean(), 1e-10);
        }
    }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:18,代码来源:LogNormalDistributionModelTest.java

示例6: proposal

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

    RealParameter changeTimes = changeTimesInput.get();

    double minf = Math.min(scaleFactorInput.get(), 1.0/scaleFactorInput.get());
    double f = minf + (1.0/minf - minf)* Randomizer.nextDouble();

    // Select element:

    int i = Randomizer.nextInt(changeTimes.getDimension());
    double newValue = f*changeTimes.getValue(i);

    if (newValue < changeTimes.getLower()
            || newValue > changeTimes.getUpper()
            || i>0 && newValue < changeTimes.getValue(i-1)
            || i<changeTimes.getDimension()-1 && newValue > changeTimes.getValue(i+1))
        return Double.NEGATIVE_INFINITY;

    changeTimes.setValue(i, newValue);

    return -Math.log(f);
}
 
开发者ID:tgvaughan,项目名称:EpiInf,代码行数:24,代码来源:ChangeTimesOperator.java

示例7: attachEdge

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * Attach chosen recombination to the clonal frame.  Note that only the
 * attachment points (nodes and heights) are set, the affected region of
 * the alignment is not modified.
 * 
 * @param conv conversion
 * @return log probability density of chosen attachment.
 */
public double attachEdge(Conversion conv) {
    
    double logP = 0.0;
    
    // Select departure point
    double u = Randomizer.nextDouble()*acg.getClonalFrameLength();
    logP += Math.log(1.0/acg.getClonalFrameLength());
    
    for (Node node : acg.getNodesAsArray()) {
        if (node.isRoot())
            continue;
        
        if (u<node.getLength()) {
            conv.setNode1(node);
            conv.setHeight1(node.getHeight() + u);
            break;
        } else
            u -= node.getLength();
    }
    
    // Select arrival point
    logP += coalesceEdge(conv);
    
    return logP;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:34,代码来源:EdgeCreationOperator.java

示例8: 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

示例9: binomalDraw

import beast.util.Randomizer; //导入方法依赖的package包/类
protected int binomalDraw(int n, double p) {
	int x = 0;
	for(int i = 0; i < n; i++) {
		if(Randomizer.nextDouble() < p) {
			x++;
		}
	}
	return x;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:10,代码来源:MissingDataModel.java

示例10: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public double proposal() {
    final RealParameter treeRates = treeRatesInput.get();
    final double[] treeRatesArray = treeRates.getDoubleValues();
    final int[] network = chooseK(nNodes);

    // exchange a new delta between all pairs of nodes in 'network'
    for (int i = 0; i < (discreteK - 1); i++) {
        for (int j = i + 1; j < discreteK; j++) {
            final double delta = (Randomizer.nextDouble() - 0.5) * deltaScaleFactor;
            treeRatesArray[network[i]] += delta;
            treeRatesArray[network[j]] -= delta;
        }
    }

    for (int i = 0; i < discreteK; i++) {
        final int nodeNumber = network[i];
        final double newRate = treeRatesArray[nodeNumber];
        if (newRate < lowerBound || newRate > upperBound) {
            return Double.NEGATIVE_INFINITY;
        } else {
            treeRates.setValue(nodeNumber, newRate);
        }
    }

    return 0.0;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:28,代码来源:NetworkRateExchange.java

示例11: creatTreeLogFiles

import beast.util.Randomizer; //导入方法依赖的package包/类
static void creatTreeLogFiles(int filesCount, int sampleInterval, int sampleCount) {
	for (int i = 0; i < filesCount; i++) {
		StringBuilder b = new StringBuilder();
		b.append("#NEXUS\n\n");
		b.append("Begin taxa;\n");
		b.append("Dimensions ntax=2;\n");
		b.append("	                Taxlabels\n");
		b.append("	                        bonobo \n");
		b.append("	                        siamang \n");
		b.append(";\n");
		b.append("End;\n");
		b.append("Begin trees;\n");
		b.append("	        Translate\n");
		b.append("	                   1 bonobo,\n");
		b.append("	                   2 siamang\n");
		b.append(";\n");

		for (int j = 0; j < sampleCount; j++) {
			b.append("tree STATE_" + j * sampleInterval + " = ");
			double h = Randomizer.nextDouble();
			b.append("(1:" + h + ",2:" + h +"):0.0;\n");
		}
		b.append("End;\n");
		try {
			FileWriter outfile = new FileWriter(new File("tmp_in" + i + ".trees"));
			outfile.write(b.toString());
			outfile.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:33,代码来源:LogCombinerTest.java

示例12: 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

示例13: 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

示例14: doWithUnEqualHFreqs

import beast.util.Randomizer; //导入方法依赖的package包/类
private void doWithUnEqualHFreqs(String mode) {
       Frequencies dummyFreqs = new Frequencies();
       dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
       BinaryCovarion substModel;

       double d = 0.05+Randomizer.nextDouble()*0.9;
       RealParameter hfrequencies = new RealParameter(new Double[]{d, 1.0 - d});
       d = 0.05+Randomizer.nextDouble()*0.9;
       RealParameter vfrequencies = new RealParameter(new Double[]{d, 1.0 - d});
       
       substModel = new BinaryCovarion();
       substModel.initByName("frequencies", dummyFreqs, 
       		"hfrequencies", hfrequencies, /* [f0, f1] */
       		"vfrequencies", vfrequencies, /* [p0, p1] */
       		"alpha", "0.01",
       		"switchRate", "0.1",
       		//"eigenSystem", "beast.evolution.substitutionmodel.RobustEigenSystem",
       		"mode", mode);
       
       double [] matrix = new double[16];
       substModel.getTransitionProbabilities(null, 1000, 0, 1.0, matrix);
       double [] baseFreqs = new double[] {
        (vfrequencies.getValue(0) * hfrequencies.getValue(0)),
        (vfrequencies.getValue(1) * hfrequencies.getValue(0)),
        (vfrequencies.getValue(0) * hfrequencies.getValue(1)),
        (vfrequencies.getValue(1) * hfrequencies.getValue(1))
       };
       System.err.println("Expected: " + Arrays.toString(baseFreqs));
       System.err.println("Calculat: " + Arrays.toString(matrix));
       for (int j = 0; j < 4; j++) {
       	assertEquals(baseFreqs[j], matrix[j], 1e-3);
       }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:34,代码来源:BinaryCovarionModelTest.java

示例15: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
public double proposal(){
    int categoryCount = dpVal.getCategoryCount();
    if(categoryCount == 1){
        return Double.NEGATIVE_INFINITY;
    }

    int categoryIndex1 = (int)(Randomizer.nextDouble()*categoryCount);
    int categoryIndex2 = categoryIndex1;
    while(categoryIndex1 == categoryIndex2){
        int something = (int)(Randomizer.nextDouble()*categoryCount);
        //System.out.println("Hi! "+categoryCount+" "+something);
        categoryIndex2 = something;
    }

    int[] sitesInCategoryIndex1 = dpVal.getClusterSites(categoryIndex1);
    int[] sitesInCategoryIndex2 = dpVal.getClusterSites(categoryIndex2);
    int site1 = sitesInCategoryIndex1[(int)(sitesInCategoryIndex1.length*Randomizer.nextDouble())];
    int site2 = sitesInCategoryIndex2[(int)(sitesInCategoryIndex2.length*Randomizer.nextDouble())];
    if(checkPattern && alignment.getPatternIndex(site1) == alignment.getPatternIndex(site2)){
        return Double.NEGATIVE_INFINITY;
    }

    DPPointer ratePointers = ratePointerInput.get(this);
    ratePointers.swapPointers(site1, site2);

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


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