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


Java Randomizer.nextBoolean方法代码示例

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


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

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

示例2: reorder

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * randomly changes left and right children in every internal node *
 */
private void reorder(final Node node) {
    if (!node.isLeaf()) {
        if (Randomizer.nextBoolean()) {
            final Node tmp = node.getLeft();
            node.setLeft(node.getRight());
            node.setRight(tmp);
        }
        reorder(node.getLeft());
        reorder(node.getRight());
    }
}
 
开发者ID:genomescale,项目名称:starbeast2,代码行数:15,代码来源:NodeReheight2.java

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

示例4: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public double proposal() {
    
    if (acg.getTotalConvCount()<1 || acg.wholeLocusModeOn())
        return Double.NEGATIVE_INFINITY;
    
    // Select random conversion and region edge:
    Conversion conv = chooseConversion();
    boolean moveStart = Randomizer.nextBoolean();
    
    int currentLocus, minLocus, maxLocus;
    if (moveStart) {
        currentLocus = conv.getStartSite();
        maxLocus = conv.getEndSite();
        minLocus = 0;
    } else {
        currentLocus = conv.getEndSite();
        minLocus = conv.getStartSite();
        maxLocus = conv.getLocus().getSiteCount()-1;
    }
    
    int radius = (int)Math.round(conv.getLocus().getSiteCount()
            * apertureSizeInput.get())/2;
    
    int newLocus = currentLocus + Randomizer.nextInt(2*radius+1)-radius;
    
    if (newLocus < minLocus || newLocus > maxLocus)
        return Double.NEGATIVE_INFINITY;

    if (moveStart)
        conv.setStartSite(newLocus);
    else
        conv.setEndSite(newLocus);
    
    return 0;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:37,代码来源:ConvertedRegionBoundaryShift.java

示例5: proposal

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

    if (acg.wholeLocusModeOn())
        return Double.NEGATIVE_INFINITY;

    Locus locus = chooseLocus();

    if (Randomizer.nextBoolean())
        return mergeProposal(locus);
    else
        return splitProposal(locus);
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:14,代码来源:MergeSplitConversion.java

示例6: proposal

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

    if (Randomizer.nextBoolean())
        return addDetour();
    else
        return removeDetour();
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:9,代码来源:AddRemoveDetour.java

示例7: proposal

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

    if (acg.getTotalConvCount() == 0)
        return Double.NEGATIVE_INFINITY;

    // Select recombination at random
    Conversion conv = chooseConversion();

    // Choose whether to move departure or arrival point
    boolean moveDeparture = conv.getNode2().isRoot() || Randomizer.nextBoolean();

    double pointHeight = moveDeparture ? conv.getHeight1() : conv.getHeight2();
    Node convNode = moveDeparture ? conv.getNode1() : conv.getNode2();

    // Find list of CF edges alive at pointHeight
    List<Node> intersectingEdges = new ArrayList<>();
    for (Node node : acg.getNodesAsArray()) {
        if (node.isRoot()
                || node == convNode
                || node.getHeight() > pointHeight
                || node.getParent().getHeight() < pointHeight) {
            continue;
        }

        intersectingEdges.add(node);
    }

    if (intersectingEdges.isEmpty())
        return Double.NEGATIVE_INFINITY;

    // Select new attachment point:
    if (moveDeparture)
        conv.setNode1(intersectingEdges.get(Randomizer.nextInt(intersectingEdges.size())));
    else
        conv.setNode2(intersectingEdges.get(Randomizer.nextInt(intersectingEdges.size())));

    return 0.0;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:40,代码来源:ConvertedEdgeHopContemp.java

示例8: splitProposal

import beast.util.Randomizer; //导入方法依赖的package包/类
/**
 * Perform split component of merge/split move.
 *
 * @param locus locus on which to apply move
 * @return log of move HR
 */
private double splitProposal(Locus locus) {

    double logHGF = 0.0;

    if (acg.getConvCount(locus) == 0)
        return Double.NEGATIVE_INFINITY;

    Conversion conv1 = acg.getConversions(locus).get(
        Randomizer.nextInt(acg.getConvCount(locus)));

    logHGF -= Math.log(1.0/acg.getConvCount(locus));

    Conversion conv2 = new Conversion();
    conv2.setLocus(locus);
    conv2.setNode1(conv1.getNode1());
    conv2.setNode2(conv1.getNode2());

    int s1, s2, e1, e2;

    int m1 = conv1.getStartSite() + Randomizer.nextInt(conv1.getSiteCount());
    int m2 = conv1.getStartSite() + Randomizer.nextInt(conv1.getSiteCount());
    
    if (Randomizer.nextBoolean()) {
        s1 = conv1.getStartSite();
        s2 = m1;
    } else {
        s1 = m1;
        s2 = conv1.getStartSite();
    }

    if (Randomizer.nextBoolean()) {
        e1 = conv1.getEndSite();
        e2 = m2;
    } else {
        e1 = m2;
        e2 = conv1.getEndSite();
    }

    if (e1<s1 || e2<s2)
        return Double.NEGATIVE_INFINITY;

    logHGF -= 2.0*Math.log(0.5/(conv1.getSiteCount()));

    conv1.setStartSite(s1);
    conv1.setEndSite(e1);

    conv2.setStartSite(s2);
    conv2.setEndSite(e2);

    conv2.setHeight1(conv1.getNode1().getHeight()
            + Randomizer.nextDouble()*conv1.getNode1().getLength());

    logHGF -= Math.log(1.0/conv1.getNode1().getLength());

    if (conv1.getNode2().isRoot()) {
        double lambda = 1.0/(conv1.getHeight2()-conv1.getNode2().getHeight());
        conv2.setHeight1(conv1.getNode2().getHeight()
                + Randomizer.nextExponential(lambda));
        logHGF -= -lambda*(conv2.getHeight2()-conv2.getNode2().getHeight())
                + Math.log(lambda);
    } else {
        conv2.setHeight2(conv1.getNode2().getHeight()
                + Randomizer.nextDouble()*conv1.getNode2().getLength());
        logHGF -= Math.log(1.0/conv1.getNode2().getLength());
    }

    if (conv2.getHeight2() < conv2.getHeight1())
        return Double.NEGATIVE_INFINITY;

    acg.addConversion(conv2);

    logHGF += Math.log(1.0/(acg.getConvCount(locus)*(acg.getConvCount(locus)-1)));

    return logHGF;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:82,代码来源:MergeSplitConversion.java

示例9: proposal

import beast.util.Randomizer; //导入方法依赖的package包/类
@Override
public double proposal() {
    
    double logHR = 0.0;
    
    if (acg.getTotalConvCount()==0)
        return Double.NEGATIVE_INFINITY;

    // Select edge at random:
    Conversion conv = chooseConversion();
    
    // Decide whether to move departure or arrival point
    boolean moveDeparture = Randomizer.nextBoolean();
    
    // Get current (old) attachment height
    double oldHeight;
    if (moveDeparture) {
        oldHeight = conv.getHeight1();
    } else {
        oldHeight = conv.getHeight2();
    }
    
    // Choose window:
    double w = apertureSizeInput.get()*acg.getRoot().getHeight();

    // Set new height
    double newHeight = oldHeight + (Randomizer.nextDouble() - 0.5)*w;
    
    // Check for boundary violation
    if (moveDeparture) {
        if (newHeight>conv.getHeight2() || newHeight>acg.getRoot().getHeight())
            return Double.NEGATIVE_INFINITY;
    } else {
        if (newHeight<conv.getHeight1())
            return Double.NEGATIVE_INFINITY;
    }
    
    // Get node below current (old) attachment point
    Node nodeBelow;
    if (moveDeparture)
        nodeBelow = conv.getNode1();
    else
        nodeBelow = conv.getNode2();

    // Choose node below new attachment point
    if (newHeight<oldHeight) {
        while (newHeight<nodeBelow.getHeight()) {
            if (nodeBelow.isLeaf())
                return Double.NEGATIVE_INFINITY;
            
            if (Randomizer.nextBoolean())
                nodeBelow = nodeBelow.getLeft();
            else
                nodeBelow = nodeBelow.getRight();
            
            logHR += -Math.log(0.5);
        }
    } else {
        while (!nodeBelow.isRoot() && newHeight>nodeBelow.getParent().getHeight()) {
            nodeBelow = nodeBelow.getParent();
            logHR += Math.log(0.5);
        }
    }
    
    // Write changes back to recombination object
    if (moveDeparture) {
        conv.setHeight1(newHeight);
        conv.setNode1(nodeBelow);
    } else {
        conv.setHeight2(newHeight);
        conv.setNode2(nodeBelow);
    }
    
    return logHR;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:76,代码来源:ConvertedEdgeSlide.java

示例10: proposal

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

    if (acg.getTotalConvCount()==0)
        return Double.NEGATIVE_INFINITY;
    
    // Select recombination at random
    Conversion recomb = chooseConversion();
    
    // Choose whether to move departure or arrival point
    boolean moveDeparture;
    moveDeparture = recomb.getNode2().isRoot() || Randomizer.nextBoolean();
    
    // Select new attachment point:
    double u = Randomizer.nextDouble()*acg.getClonalFrameLength();
    Node nodeBelow = null;
    double newHeight = -1;
    for (Node node : acg.getNodesAsArray()) {
        if (node.isRoot())
            continue;
        
        if (u<node.getLength()) {
            newHeight = node.getHeight() + u;
            nodeBelow = node;
            break;
        }
        
        u -= node.getLength();
    }
    
    if (newHeight < 0.0)
        throw new IllegalStateException("Problem with recombinant edge "
                + "hop operator!  This is a bug.");
    
    // Check that new height does not lie out of bounds
    if (moveDeparture) {
        if (newHeight>recomb.getHeight2())
            return Double.NEGATIVE_INFINITY;
        else {
            recomb.setHeight1(newHeight);
            recomb.setNode1(nodeBelow);
        }
    } else {
        if (newHeight<recomb.getHeight1())
            return Double.NEGATIVE_INFINITY;
        else {
            recomb.setHeight2(newHeight);
            recomb.setNode2(nodeBelow);
        }
    }
    
    return 0.0;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:54,代码来源:ConvertedEdgeHop.java

示例11: proposal

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

    if (Randomizer.nextBoolean()) {
        
        // Add
        
        logHGF += Math.log(1.0/(acg.getTotalConvCount()+1));
        logHGF -= drawNewConversion();
        
    } else {
        
        // Remove
        
        if (acg.getTotalConvCount()==0)
            return Double.NEGATIVE_INFINITY;
        
        // Select conversion to remove:
        Conversion conv = chooseConversion();

        // Calculate HGF
        logHGF += getConversionProb(conv);
        logHGF -= Math.log(1.0/acg.getTotalConvCount());
        
        // Remove conversion
        acg.deleteConversion(conv);

    }

    return logHGF;
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:33,代码来源:AddRemoveConversion.java


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