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


Java Randomizer.nextInt方法代码示例

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


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

示例1: getRandomBirthIndex

import beast.util.Randomizer; //导入方法依赖的package包/类
protected int getRandomBirthIndex(String s, int births) {
	if (births == 0) {
		return -1;
	} else if (births  == 1) {
		return s.indexOf('1');
	}
	int tmp;
	int[] indices = new int[s.length()]; 
	for (int i = 0; i < s.length(); ++i) indices[i] = i;

	for (int i = 0; i < s.length(); i++) {
		int j = Randomizer.nextInt(indices.length - i) + i;
		if (j != i) { // swap to shuffle
			tmp = indices[i];
			indices[i] = indices[j];
			indices[j] = tmp;
		}
		if ((s.charAt(indices[i]) == '1')) {
			return indices[i];
		}
	}
	return -1;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:24,代码来源:LanguageSubsitutionModel.java

示例2: pickNarrow

import beast.util.Randomizer; //导入方法依赖的package包/类
private boolean pickNarrow() {
    zNode = speciesTreeNodes[nLeafNodes + Randomizer.nextInt(nInternalNodes)];
    while (zNode.getLeft().isLeaf() && zNode.getRight().isLeaf()) {
        zNode = speciesTreeNodes[nLeafNodes + Randomizer.nextInt(nInternalNodes)];
    }

    yNode = zNode.getLeft();
    cNode = zNode.getRight();
    if (yNode.getHeight() < cNode.getHeight()) {
        yNode = zNode.getRight();
        cNode = zNode.getLeft();
    }

    if (yNode.isLeaf()) {
        return false;
    } else if (Randomizer.nextBoolean()) {
        aNode = yNode.getLeft();
        bNode = yNode.getRight();
    } else {
        aNode = yNode.getRight();
        bNode = yNode.getLeft();
    }

    return true;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:26,代码来源:CoordinatedExchange.java

示例3: chooseK

import beast.util.Randomizer; //导入方法依赖的package包/类
protected int[] chooseK(final int n) {
    final int[] sequential = new int[n];

    for (int i = 0; i < n; i++) sequential[i] = i;

    for (int i = 0; i < discreteK; i++) {
        final int j = Randomizer.nextInt(n - i);
        if (j > 0) { // swap [i] with [i + j]
            final int i_temp = sequential[i];
            final int iplusj = i + j;
            sequential[i] = sequential[iplusj];
            sequential[iplusj] = i_temp;
        }
    }

    return sequential;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:18,代码来源:AdaptiveOperator.java

示例4: proposal

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

    // randomly select leaf node
    int i = Randomizer.nextInt(taxonIndices.length);
    Node node = tree.getNode(taxonIndices[i]);
    double upper = node.getParent().getHeight();
    //double lower = 0.0;
    //final double newValue = (Randomizer.nextDouble() * (upper -lower)) + lower;

    // scale node
    double scale = (scaleFactor + (Randomizer.nextDouble() * ((1.0 / scaleFactor) - scaleFactor)));
    final double newValue = node.getHeight() * scale;

    // check the tree does not get negative branch lengths
    if (newValue > upper) {
        return Double.NEGATIVE_INFINITY;
    }
    node.setHeight(newValue);

    return -Math.log(scale);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:24,代码来源:TipDatesScaler.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() {

    final IntegerParameter param = parameterInput.get(this);

    final int i = Randomizer.nextInt(param.getDimension());
    final int value = param.getValue(i);
    final int newValue = value + Randomizer.nextInt(2 * windowSize + 1) - windowSize;

    if (newValue < param.getLower() || newValue > param.getUpper()) {
        // invalid move, can be rejected immediately
        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,代码行数:27,代码来源:IntRandomWalkOperator.java

示例6: 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);

    // randomly select internal node
    final int nodeCount = tree.getNodeCount();
    
    // Abort if no non-root internal nodes
    if (tree.getInternalNodeCount()==1)
        return Double.NEGATIVE_INFINITY;
    
    Node node;
    do {
        final int nodeNr = nodeCount / 2 + 1 + Randomizer.nextInt(nodeCount / 2);
        node = tree.getNode(nodeNr);
    } while (node.isRoot() || node.isLeaf());
    final double upper = node.getParent().getHeight();
    final double lower = Math.max(node.getLeft().getHeight(), node.getRight().getHeight());
    final double newValue = (Randomizer.nextDouble() * (upper - lower)) + lower;
    node.setHeight(newValue);

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

示例7: testIntegerData

import beast.util.Randomizer; //导入方法依赖的package包/类
@Test
public void testIntegerData() {
	IntegerData datatype = new IntegerData();
	assertEquals("?", datatype.getCode(-1));
	assertEquals("0", datatype.getCode(0));
	assertEquals("1", datatype.getCode(1));
	assertEquals("10", datatype.getCode(10));
	assertEquals("123", datatype.getCode(123));
	Randomizer.setSeed(127);
	for (int i = 0; i < 100; i++) {
		int state = Randomizer.nextInt(100000000);
		int x = state;
    	String str = "";
    	while (state > 0) {
    		str = (char)('0' + state%10) + str;
    		state /= 10;
    	}
		assertEquals(str, datatype.getCode(x));
	}
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:21,代码来源:IntegerDataTest.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);
    int i = Randomizer.nextInt(param.getDimension());
    double value = param.getValue(i);
    double newValue = getProposedVal(
            value, //original value
            i,     //index of the value
            useGaussian, //whether to use gaussian moves
            windowSizes);   //window sizes

    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);
    lastChangedValueIndex = i;


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

示例9: proposal

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

    ParameterList paramList = parameterListInput.get(this);


    // a random parameter to perturb
    int iParam = Randomizer.nextInt(paramList.getDimension());

    //a random dimesion to perturb
    int iValue = Randomizer.nextInt(paramList.getParameterDimension());
    double newValue = calculateNewValue(
            paramList.getValue(iParam,iValue),
            paramList.getUpper(),
            paramList.getLower()
    );
    paramList.setValue(iParam,iValue,newValue);

    return logq;
}
 
开发者ID:jessiewu,项目名称:substBMA,代码行数:22,代码来源:PLIntegerRandomWalkOperator.java

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

示例11: updateParticle

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
	protected void updateParticle(int sampleNr) {
//        nsCountDown = new CountDownLatch(1);
//        countDown.countDown();
//        try {
//			nsCountDown.await();
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
        int n = particlePool.size();
        synchronized (particlePool) {
            Object [] states = particlePool.keySet().toArray();			

            //String [] states = (String []) o;
    		int i = Randomizer.nextInt(n);
    		while (particlePool.get(states[i]) < minLikelihood) {
    			i = Randomizer.nextInt(n);
    		}
    		state.fromXML((String) states[i]);
		}

		// init calculation nodes & oldLogPrior
		robustlyCalcPosterior(posterior);
		
		oldLogPrior = 0;
		for (Distribution d : samplingDistribution) {
			oldLogPrior += d.getArrayValue();
		}
		
		for (int j = 0; j < subChainLength; j++) {
			composeProposal(j + subChainLength * sampleNr);
		}
	}
 
开发者ID:BEAST2-Dev,项目名称:nested-sampling,代码行数:35,代码来源:NSThread.java

示例12: randomYuleTree

import beast.util.Randomizer; //导入方法依赖的package包/类
static Tree randomYuleTree (int nodes, double l) throws Exception {
	Tree tr = new Tree();
	ArrayList<Node> nodeList = new ArrayList<Node>();
	double t = 0.0;
	int label = 1;
	for (int i = 0; i < nodes; i++) {
		Node n = new Node();
		n.setHeight(t);
		n.setNr(label);
		label++;
		nodeList.add(n);
	}

	while (nodeList.size() > 1) {
		t += Randomizer.nextExponential(nodeList.size()*l);

		int p_1_index = Randomizer.nextInt(nodeList.size());
		Node p1 = nodeList.remove(p_1_index);
		int p_2_index = Randomizer.nextInt(nodeList.size());
		Node p2 = nodeList.remove(p_2_index);

		Node parent = new Node();
		parent.setHeight(t);

		parent.setNr(label);
		label++;
		p1.setParent(parent);
		parent.addChild(p1);
		p2.setParent(parent);
		parent.addChild(p2);

		nodeList.add(parent);
	}
	tr.setRoot(nodeList.get(0));
	return new Tree(tr.toString());

}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:38,代码来源:BorrowingComparisonTests.java

示例13: randomYuleTree

import beast.util.Randomizer; //导入方法依赖的package包/类
private static Tree randomYuleTree (int nodes, double l) throws Exception {
	Tree tr = new Tree();
	ArrayList<Node> nodeList = new ArrayList<Node>();
	double t = 0.0;
	int label = 1;
	for (int i = 0; i < nodes; i++) {
		Node n = new Node();
		n.setHeight(t);
		n.setNr(label);
		label++;
		nodeList.add(n);
	}

	while (nodeList.size() > 1) {
		t += Randomizer.nextExponential(nodeList.size()*l);

		int p_1_index = Randomizer.nextInt(nodeList.size());
		Node p1 = nodeList.remove(p_1_index);
		int p_2_index = Randomizer.nextInt(nodeList.size());
		Node p2 = nodeList.remove(p_2_index);

		Node parent = new Node();
		parent.setHeight(t);

		parent.setNr(label);
		label++;
		p1.setParent(parent);
		parent.addChild(p1);
		p2.setParent(parent);
		parent.addChild(p2);

		nodeList.add(parent);
	}
	tr.setRoot(nodeList.get(0));
	return new Tree(tr.toString());

}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:38,代码来源:BeastBorrowingPluginTest.java

示例14: pickWide

import beast.util.Randomizer; //导入方法依赖的package包/类
private boolean pickWide() {
    final int nNodesExceptRoot = nSpeciesNodes - 1;
    final Node rootNode = speciesTreeNodes[nNodesExceptRoot];

    // pick an internal node at random (excluding the root)
    final int yNodeNumber = nLeafNodes + Randomizer.nextInt(nInternalNodes - 1);
    yNode = speciesTreeNodes[yNodeNumber];
    final double yNodeHeight = yNode.getHeight();
    if (Randomizer.nextBoolean()) {
        aNode = yNode.getLeft();
        bNode = yNode.getRight();
    } else {
        aNode = yNode.getRight();
        bNode = yNode.getLeft();
    }

    // for all internal nodes (excluding the root)
    final Node[] zNodes = new Node[nNodesExceptRoot];

    czNodeFinder(yNode, rootNode, yNodeHeight, zNodes);

    // pick a cousin from the available candidates
    int cousinNodeNumber = Randomizer.nextInt(nNodesExceptRoot);
    zNode = zNodes[cousinNodeNumber];
    while (zNode == null) {
        cousinNodeNumber = Randomizer.nextInt(nNodesExceptRoot);
        //System.out.println(String.format("%d/%d", cousinNodeNumber, nNodesExceptRoot));
        zNode = zNodes[cousinNodeNumber];
    }

    cNode = speciesTreeNodes[cousinNodeNumber];

    return true;
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:35,代码来源:CoordinatedExchange.java

示例15: proposal

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

    for (int i = 0; i < discreteK; i++) {
        final int nodeNumber = cycle[i];
        final int newRate = lowerBound + Randomizer.nextInt(integerRange);
        treeRates.setValue(nodeNumber, newRate);
    }

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


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