本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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());
}
示例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());
}
示例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;
}
示例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;
}