• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Randomizer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testScaleWithInt

import beast.util.Randomizer; //导入依赖的package包/类
@Test
public void testScaleWithInt() throws Exception {
    Randomizer.setSeed(1);

    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(
            new File("test/epiinf/xmltests/ScaleWithIntTest.xml"));
    Logger.FILE_MODE = Logger.LogFileMode.overwrite;
    runnable.run();


    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("x1", 0.5, 0.01));
    expectations.add(new Expectation("y1", 0.5, 0.01));
    expectations.add(new Expectation("y2", 0.5, 0.01));
    expectations.add(new Expectation("y3", 0.5, 0.01));
    expectations.add(new Expectation("n", 50.0, 1.0));
    LogAnalyser logAnalyser = new LogAnalyser("ScaleWithIntTest.log", expectations);

    try {
        for (Expectation expectation : expectations) {
            assertTrue(expectation.isValid());
            assertTrue(expectation.isPassed());
        }
    } catch (Exception e) {
        throw e;

    } finally {
        Files.deleteIfExists(Paths.get("ScaleWithIntTest.xml.state"));
        Files.deleteIfExists(Paths.get("ScaleWithIntTest.log"));
    }
}
 
开发者ID:tgvaughan,项目名称:EpiInf,代码行数:33,代码来源:OperatorTests.java


示例2: test2Taxon

import beast.util.Randomizer; //导入依赖的package包/类
@Test
public void test2Taxon() throws Exception {
    Randomizer.setSeed(1);

    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(
            new File("examples/ACGsimulations/simulateACGs2taxon.xml"));
    runnable.run();

    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("acg.CFheight", 1.0, 1e-2));
    expectations.add(new Expectation("acg.CFlength", 2.0, 1e-2));
    expectations.add(new Expectation("acg.nConv", 10.0, 5e-2));

    LogAnalyser logAnalyser = new LogAnalyser("simulateACGs2taxon.stats",
            expectations);

    for (int i=0; i<expectations.size(); i++) {
        assertTrue(expectations.get(i).isValid());
        assertTrue(expectations.get(i).isPassed());
    }

    Files.deleteIfExists(Paths.get("simulateACGs2taxon.stats"));
    Files.deleteIfExists(Paths.get("simulateACGs2taxon.converted"));
    Files.deleteIfExists(Paths.get("simulateACGs2taxon.trees"));
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:27,代码来源:SimulatedACGTest.java


示例3: testShortMultiLocus

import beast.util.Randomizer; //导入依赖的package包/类
@Test
public void testShortMultiLocus() throws Exception {
    Randomizer.setSeed(1);

    XMLParser parser = new XMLParser();
    beast.core.Runnable runnable = parser.parseFile(
            new File("examples/allOperatorTests/allOperatorTestShortSSML.xml"));
    disableScreenLog(runnable);
    runnable.run();

    List<Expectation> expectations = new ArrayList<>();
    expectations.add(new Expectation("acg.CFheight", 1.601, 0.2));
    expectations.add(new Expectation("acg.CFlength", 4.17, 0.5));
    expectations.add(new Expectation("acg.nConv", 39.61, 0.5));

    LogAnalyser logAnalyser = new LogAnalyser("allOperatorTestShortSSML.stats",
            expectations);

    for (Expectation expectation : expectations) {
        assertTrue(expectation.isValid());
        assertTrue(expectation.isPassed());
    }

    Files.deleteIfExists(Paths.get("allOperatorTestShortSSML.stats"));
    Files.deleteIfExists(Paths.get("allOperatorTestShortSSML.converted"));
    Files.deleteIfExists(Paths.get("allOperatorTestShortSSML.trees"));
    Files.deleteIfExists(Paths.get("allOperatorTestShortSSML.cf"));
    Files.deleteIfExists(Paths.get("allOperatorTestShortSSML.xml.state"));
}
 
开发者ID:tgvaughan,项目名称:bacter,代码行数:30,代码来源:AllOperatorTest.java


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


示例5: mutateLang

import beast.util.Randomizer; //导入依赖的package包/类
public Sequence mutateLang(Sequence l, double T) throws Exception {
	Sequence newLang = new Sequence("", l.getData());
	for (int i = 0; i < newLang.getData().length(); i++) {
		int currentTrait = (int) newLang.getData().charAt(i);
		// Mutations are exponentially distributed.
		double t = Randomizer.nextExponential(rate);
		String newSeq;
		while (t < T) {
			currentTrait = Character.getNumericValue(newLang.getData().charAt(i));
			// In binary model, a mutation switches trait.
			// If death: check NoEmptyTrait.
			if (1 - currentTrait == 0) {
				if (noEmptyTraitCheck(newLang)) {
					newSeq = replaceCharAt(newLang.getData(), i, Integer.toString((1 - currentTrait)));
				} else {
					newSeq = newLang.getData();
				}
			} else {
				newSeq = replaceCharAt(newLang.getData(), i, Integer.toString((1 - currentTrait)));
			}
			newLang.dataInput.setValue(newSeq, newLang);
			t += Randomizer.nextExponential(rate);
		}
	}
	return newLang;
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:27,代码来源:ExplicitBinaryGTR.java


示例6: GTRTreeValidation

import beast.util.Randomizer; //导入依赖的package包/类
private static void GTRTreeValidation() throws Exception {
	ArrayList<Integer> births = new ArrayList<Integer>();
	for (int i = 0; i < 10000; i++) {
		System.out.println(i);
		ExplicitBinaryGTR gtr_mod = new ExplicitBinaryGTR(0.5, 0.0, 0.0, false);
		String seq = "";
		for (int j = 0; j < 20; j++) {
			seq += Integer.toString(Randomizer.nextInt(2));
		}
		Sequence l = new Sequence("", seq);
		Tree tree = randomYuleTree(8, 0.001);
		tree.getRoot().setMetaData("lang", l);
		tree = gtr_mod.mutateOverTree(tree);
		for (Node n : tree.getExternalNodes()) {
			Sequence l2 = (Sequence) n.getMetaData("lang");
			births.add(LanguageSubsitutionModel.getBirths(l2));
		}

	}
	listToCSV(births, "Utilities/Thesis Graph Generation/gtrtree.csv");
}
 
开发者ID:lutrasdebtra,项目名称:Beast-Borrowing-Plugin,代码行数:22,代码来源:BeastBorrowingPluginTest.java


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


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


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


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


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


示例12: simulate

import beast.util.Randomizer; //导入依赖的package包/类
/**
 * perform the actual sequence generation
 *
 * @return alignment containing randomly generated sequences for the nodes in the
 *         leaves of the tree
 */
public void simulate() {
    Node root = m_tree.getRoot();


    double[] categoryProbs = m_siteModel.getCategoryProportions(root);
    int[] category = new int[m_sequenceLength];
    for (int i = 0; i < m_sequenceLength; i++) {
        category[i] = Randomizer.randomChoicePDF(categoryProbs);
    }

    double[] frequencies = m_siteModel.getSubstitutionModel().getFrequencies();
    int[] seq = new int[m_sequenceLength];
    for (int i = 0; i < m_sequenceLength; i++) {
        seq[i] = Randomizer.randomChoicePDF(frequencies);
    }


    //alignment.setDataType(m_siteModel.getFrequencyModel().getDataType());

    traverse(root, seq, category);

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


示例13: traverse

import beast.util.Randomizer; //导入依赖的package包/类
/**
 * recursively walk through the tree top down, and add sequence to alignment whenever
 * a leave node is reached.
 *
 * @param node           reference to the current node, for which we visit all children
 * @param parentSequence randomly generated sequence of the parent node
 * @param category       array of categories for each of the sites
 * @param alignment
 */
void traverse(Node node, int[] parentSequence, int[] category) {
    for (int childIndex = 0; childIndex < 2; childIndex++) {
        Node child = (childIndex == 0 ? node.getLeft() : node.getRight());
        for (int i = 0; i < m_categoryCount; i++) {
            getTransitionProbabilities(m_tree, child, i, m_probabilities[i]);
        }

        int[] seq = new int[m_sequenceLength];
        double[] cProb = new double[m_stateCount];
        for (int i = 0; i < m_sequenceLength; i++) {
            System.arraycopy(m_probabilities[category[i]], parentSequence[i] * m_stateCount, cProb, 0, m_stateCount);
            seq[i] = Randomizer.randomChoicePDF(cProb);
        }

        if (child.isLeaf()) {
            sequenceInput.setValue(intArray2Sequence(seq, child), this);
        } else {
            traverse(child, seq, category);
        }
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:31,代码来源:SimulatedAlignment.java


示例14: traverse

import beast.util.Randomizer; //导入依赖的package包/类
/**
 * recursively walk through the tree top down, and add sequence to alignment whenever
 * a leave node is reached.
 *
 * @param node           reference to the current node, for which we visit all children
 * @param parentSequence randomly generated sequence of the parent node
 * @param category       array of categories for each of the sites
 * @param alignment
 * @
 */
void traverse(Node node, int[] parentSequence, int[] category, Alignment alignment)  {
    for (int childIndex = 0; childIndex < 2; childIndex++) {
        Node child = (childIndex == 0 ? node.getLeft() : node.getRight());
        for (int i = 0; i < m_categoryCount; i++) {
            getTransitionProbabilities(m_tree, child, i, m_probabilities[i]);
        }

        int[] seq = new int[m_sequenceLength];
        double[] cProb = new double[m_stateCount];
        for (int i = 0; i < m_sequenceLength; i++) {
            System.arraycopy(m_probabilities[category[i]], parentSequence[i] * m_stateCount, cProb, 0, m_stateCount);
            seq[i] = Randomizer.randomChoicePDF(cProb);
        }

        if (child.isLeaf()) {
            alignment.sequenceInput.setValue(intArray2Sequence(seq, child), alignment);
        } else {
            traverse(child, seq, category, alignment);
        }
    }
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:32,代码来源:SequenceSimulator.java


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


示例16: testMedian

import beast.util.Randomizer; //导入依赖的package包/类
public void testMedian() throws MathException {

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

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

            norm.meanInput.setValue(M + "", norm);
            norm.sigmaInput.setValue(S + "", norm);
            norm.initAndValidate();

            double median = M;

            assertEquals(median, norm.inverseCumulativeProbability(0.5), 1e-6);
        }
    }
 
开发者ID:CompEvol,项目名称:beast2,代码行数:18,代码来源:NormalDistributionTest.java


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


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


示例19: doWithEqualHFreqs

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

       RealParameter hfrequencies = new RealParameter(new Double[]{0.5, 0.5});
       double d = Randomizer.nextDouble();
       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",
       		"mode", mode);
       
       double [] matrix = new double[16];
       substModel.getTransitionProbabilities(null, 100, 0, 1.0, matrix);
       double EPSILON = 1e-10;
       assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(0), matrix[0], EPSILON);
       assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(0), matrix[1], EPSILON);
       assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(1), matrix[2], EPSILON);
       assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(1), matrix[3], EPSILON);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:26,代码来源:BinaryCovarionModelTest.java


示例20: testNarrowExchange4Taxa

import beast.util.Randomizer; //导入依赖的package包/类
@Test 
public void testNarrowExchange4Taxa() throws Exception {
	
       int runs = 10000;
       Randomizer.setSeed(666);
       // test that going from source tree to target tree 
       // is as likely as going the other way around
       // taking the HR in account.
       Sequence A = new Sequence("A", "A");
       Sequence B = new Sequence("B", "A");
       Sequence C = new Sequence("C", "A");
       Sequence D = new Sequence("D", "A");

       Alignment data = new Alignment();
       data.initByName("sequence", A, "sequence", B, "sequence", C, "sequence", D,
               "dataType", "nucleotide"
       );
       String sourceTree = "((A:2.0,B:2.0):1.0,(C:1.0,D:1.0):2.0):0.0"; // ((A,B),(C,D))
       String targetTree = "((A:2.0,(C:1.0,D:1.0):1.0):1.0,B:3.0):0.0"; // ((A,(C,D)),B)
       testNarrowExchange(sourceTree, targetTree, runs, data);
}
 
开发者ID:CompEvol,项目名称:beast2,代码行数:22,代码来源:ExchangeOperatorTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NonRepeatableRequestException类代码示例发布时间:2022-05-22
下一篇:
Java ResourcesListImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap