Search in sources :

Example 1 with Normal

use of beast.math.distributions.Normal in project beast2 by CompEvol.

the class MeanOfParametricDistributionTest method testMeanOfNormal.

@Test
public void testMeanOfNormal() throws Exception {
    Normal normal = new Normal();
    normal.initByName("mean", "123.0", "sigma", "3.0");
    double mean = normal.getMean();
    assertEquals(mean, 123, 1e-10);
    normal = new Normal();
    normal.initByName("mean", "123.0", "sigma", "30.0");
    mean = normal.getMean();
    assertEquals(mean, 123, 1e-10);
    normal = new Normal();
    normal.initByName("mean", "123.0", "sigma", "3.0", "offset", "3.0");
    mean = normal.getMean();
    assertEquals(mean, 126, 1e-10);
}
Also used : Normal(beast.math.distributions.Normal) Test(org.junit.Test)

Example 2 with Normal

use of beast.math.distributions.Normal in project beast2 by CompEvol.

the class BeautiDoc method addMRCAPrior.

public void addMRCAPrior(MRCAPrior mrcaPrior) {
    Tree tree = (Tree) pluginmap.get("Tree.t:" + alignments.get(0).getID());
    if (tree == null) {
        for (String key : pluginmap.keySet()) {
            if (key.startsWith("Tree.t:")) {
                tree = (Tree) pluginmap.get(key);
                break;
            }
        }
    }
    // make sure we have the appropriate tree:
    if (alignments.size() > 1) {
        String testTaxon = mrcaPrior.taxonsetInput.get().toString().split("\n")[1].trim();
        // = tree.getTaxaNames();
        String[] taxaNames;
        int index = -1;
        int j = 0;
        while (index < 0 && j++ < alignments.size()) {
            tree = (Tree) pluginmap.get("Tree.t:" + alignments.get(j - 1).getID());
            taxaNames = tree.getTaxaNames();
            for (int i = 0; i < taxaNames.length && index < 0; i++) if (testTaxon.equals(taxaNames[i]))
                index = i;
        }
    }
    CompoundDistribution prior = (CompoundDistribution) pluginmap.get("prior");
    mrcaPrior.treeInput.setValue(tree, mrcaPrior);
    ParametricDistribution distr = mrcaPrior.distInput.get();
    TaxonSet t = mrcaPrior.taxonsetInput.get();
    if (taxaset.keySet().contains(t.getID())) {
        Log.warning.println("taxonset " + t.getID() + " already exists: MRCAPrior " + mrcaPrior.getID() + " can not be added");
    } else {
        taxaset.put(t.getID(), t);
        // ensure TaxonSets are not duplicated
        List<Taxon> taxa = t.taxonsetInput.get();
        for (int i = 0; i < taxa.size(); i++) {
            if (taxaset.containsKey(taxa.get(i).getID())) {
                taxa.set(i, taxaset.get(taxa.get(i).getID()));
            } else {
                taxaset.put(taxa.get(i).getID(), taxa.get(i));
            }
        }
        if (distr instanceof Normal && (Double.isInfinite(((Normal) distr).sigmaInput.get().getValue()))) {
        // it is a 'fixed' calibration, no need to add a distribution
        } else {
            prior.pDistributions.setValue(mrcaPrior, prior);
            connect(mrcaPrior, "tracelog", "log");
        }
    }
    if (t.taxonsetInput.get().size() == 1 && distr != null) {
        // only add operators if it is NOT a 'fixed' calibration
        if (!(distr instanceof Normal && (Double.isInfinite(((Normal) distr).sigmaInput.get().getValue())))) {
            TipDatesRandomWalker operator = new TipDatesRandomWalker();
            t.initAndValidate();
            operator.initByName("taxonset", t, "weight", 1.0, "tree", tree, "windowSize", 1.0);
            operator.setID("TipDatesRandomWalker." + t.getID());
            MCMC mcmc = (MCMC) this.mcmc.get();
            mcmc.operatorsInput.setValue(operator, mcmc);
        }
        // set up date trait
        double date = distr.getMean();
        TraitSet dateTrait = null;
        for (TraitSet ts : tree.m_traitList.get()) {
            if (ts.isDateTrait()) {
                dateTrait = ts;
            }
        }
        if (dateTrait == null) {
            dateTrait = new TraitSet();
            dateTrait.setID("traitsetDate");
            registerPlugin(dateTrait);
            dateTrait.initByName("traitname", TraitSet.DATE_BACKWARD_TRAIT, "taxa", tree.getTaxonset(), "value", t.taxonsetInput.get().get(0).getID() + "=" + date);
            tree.m_traitList.setValue(dateTrait, tree);
            tree.initAndValidate();
        } else {
            dateTrait.traitsInput.setValue(dateTrait.traitsInput.get() + ",\n" + t.taxonsetInput.get().get(0).getID() + "=" + date, dateTrait);
        }
        mrcaPrior.onlyUseTipsInput.setValue(true, mrcaPrior);
    }
}
Also used : Taxon(beast.evolution.alignment.Taxon) MCMC(beast.core.MCMC) TaxonSet(beast.evolution.alignment.TaxonSet) Normal(beast.math.distributions.Normal) CompoundDistribution(beast.core.util.CompoundDistribution) ParametricDistribution(beast.math.distributions.ParametricDistribution) TraitSet(beast.evolution.tree.TraitSet) Tree(beast.evolution.tree.Tree) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Example 3 with Normal

use of beast.math.distributions.Normal in project beast2 by CompEvol.

the class NormalDistributionTest method setUp.

public void setUp() {
    norm = new Normal();
    norm.initAndValidate();
    Randomizer.setSeed(123);
}
Also used : Normal(beast.math.distributions.Normal)

Aggregations

Normal (beast.math.distributions.Normal)3 MCMC (beast.core.MCMC)1 CompoundDistribution (beast.core.util.CompoundDistribution)1 Taxon (beast.evolution.alignment.Taxon)1 TaxonSet (beast.evolution.alignment.TaxonSet)1 TipDatesRandomWalker (beast.evolution.operators.TipDatesRandomWalker)1 TraitSet (beast.evolution.tree.TraitSet)1 Tree (beast.evolution.tree.Tree)1 ParametricDistribution (beast.math.distributions.ParametricDistribution)1 Test (org.junit.Test)1