use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class SpeciesTreePrior method initAndValidate.
@Override
public void initAndValidate() {
popFunction = popFunctionInput.get();
popSizesBottom = popSizesBottomInput.get();
popSizesTop = popSizesTopInput.get();
// set up sizes of population functions
final int speciesCount = treeInput.get().getLeafNodeCount();
final int nodeCount = treeInput.get().getNodeCount();
switch(popFunction) {
case constant:
popSizesBottom.setDimension(nodeCount);
break;
case linear:
if (popSizesTop == null) {
throw new IllegalArgumentException("topPopSize must be specified");
}
popSizesBottom.setDimension(speciesCount);
popSizesTop.setDimension(nodeCount);
break;
case linear_with_constant_root:
if (popSizesTop == null) {
throw new IllegalArgumentException("topPopSize must be specified");
}
popSizesBottom.setDimension(speciesCount);
popSizesTop.setDimension(nodeCount - 1);
break;
}
// bottom prior = Gamma(2,Psi)
gamma2Prior = new Gamma();
gamma2Prior.betaInput.setValue(gammaParameterInput.get(), gamma2Prior);
// top prior = Gamma(4,Psi)
gamma4Prior = new Gamma();
final RealParameter parameter = new RealParameter(new Double[] { 4.0 });
gamma4Prior.alphaInput.setValue(parameter, gamma4Prior);
gamma4Prior.betaInput.setValue(gammaParameterInput.get(), gamma4Prior);
if (popFunction != TreePopSizeFunction.constant && gamma4Prior == null) {
throw new IllegalArgumentException("Top prior must be specified when population function is not constant");
}
// make sure the m_taxonSet is a set of taxonsets
// HACK to make Beauti initialise: skip the check here
// for (Taxon taxon : m_taxonSet.get().m_taxonset.get()) {
// if (!(taxon instanceof TaxonSet)) {
// throw new IllegalArgumentException("taxonset should be sets of taxa only, not individual taxons");
// }
// }
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class RandomLocalClockModel method initAndValidate.
@Override
public void initAndValidate() {
m_tree = treeInput.get();
BooleanParameter indicators = indicatorParamInput.get();
if (indicators.getDimension() != m_tree.getNodeCount() - 1) {
Log.warning.println("RandomLocalClockModel::Setting dimension of indicators to " + (m_tree.getNodeCount() - 1));
indicators.setDimension(m_tree.getNodeCount() - 1);
}
unscaledBranchRates = new double[m_tree.getNodeCount()];
RealParameter rates = rateParamInput.get();
if (rates.lowerValueInput.get() == null || rates.lowerValueInput.get() < 0.0) {
rates.setLower(0.0);
}
if (rates.upperValueInput.get() == null || rates.upperValueInput.get() < 0.0) {
rates.setUpper(Double.MAX_VALUE);
}
if (rates.getDimension() != m_tree.getNodeCount() - 1) {
Log.warning.println("RandomLocalClockModel::Setting dimension of rates to " + (m_tree.getNodeCount() - 1));
rates.setDimension(m_tree.getNodeCount() - 1);
}
ratesAreMultipliers = ratesAreMultipliersInput.get();
meanRate = meanRateInput.get();
if (meanRate == null) {
meanRate = new RealParameter("1.0");
}
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class TreeLikelihoodTest method testMarginalisationOfLikelihoodBinary.
@Test
public void testMarginalisationOfLikelihoodBinary() throws Exception {
// test summation over all patterns adds to 1 for binary data
Sequence German_ST = new Sequence("German_ST", " 10110010");
Sequence Dutch_List = new Sequence("Dutch_List", " 11010100");
Sequence English_ST = new Sequence("English_ST", " 11101000");
Alignment data = new Alignment();
data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "dataType", "binary");
Tree tree = BEASTTestCase.getTree(data, "(English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):0.0;");
RealParameter frequencies = new RealParameter("0.683 0.317");
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", frequencies);
GeneralSubstitutionModel covarion = new GeneralSubstitutionModel();
covarion.initByName("frequencies", freqs, "rates", new RealParameter("1.0 1.0"));
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
likelihood.calculateLogP();
double[] logPs = likelihood.getPatternLogLikelihoods();
double P = 0;
for (double d : logPs) {
P += Math.exp(d);
}
assertEquals(P, 1.0, BEASTTestCase.PRECISION);
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class TreeLikelihoodTest method testSDolloLikelihood.
@Test
public void testSDolloLikelihood() throws Exception {
UserDataType dataType = new UserDataType();
dataType.initByName("states", 2, "codeMap", "0=1, 1=0, ?=0 1, -=0 1");
Alignment data = new Alignment();
Sequence German_ST = new Sequence("German_ST", BEASTTestCase.German_ST.dataInput.get());
Sequence Dutch_List = new Sequence("Dutch_List", BEASTTestCase.Dutch_List.dataInput.get());
;
Sequence English_ST = new Sequence("English_ST", BEASTTestCase.English_ST.dataInput.get());
;
Sequence French = new Sequence("French", BEASTTestCase.French.dataInput.get());
;
Sequence Italian = new Sequence("Italian", BEASTTestCase.Italian.dataInput.get());
;
Sequence Spanish = new Sequence("Spanish", BEASTTestCase.Spanish.dataInput.get());
;
data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "sequence", French, "sequence", Italian, "sequence", Spanish, "userDataType", dataType);
Tree tree = BEASTTestCase.getTree(data, "((English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):1.5793160946109988,(Spanish:0.11078392189606047,(Italian:0.10119772534558173,French:0.10119772534558173):0.009586196550478737):1.6959656445951337)");
RealParameter frequencies = new RealParameter("1 0");
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", frequencies);
RealParameter deathprob = new RealParameter("1.7");
MutationDeathModel SDollo = new MutationDeathModel();
SDollo.initByName("deathprob", deathprob, "frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", SDollo);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel, "useAmbiguities", true);
logP = likelihood.calculateLogP();
// beast1 xml gives -3551.6436
assertEquals(logP, -3551.6436270344648, BEASTTestCase.PRECISION);
}
use of beast.core.parameter.RealParameter in project beast2 by CompEvol.
the class TreeLikelihoodTest method testBinaryCovarionLikelihood.
@Test
public void testBinaryCovarionLikelihood() throws Exception {
Alignment data = BEASTTestCase.getCovarionAlignment();
Tree tree = BEASTTestCase.getTree(data, "((English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):1.5793160946109988,(Spanish:0.11078392189606047,(Italian:0.10119772534558173,French:0.10119772534558173):0.009586196550478737):1.6959656445951337)");
RealParameter alpha = new RealParameter("0.284");
RealParameter switchRate = new RealParameter("0.829");
RealParameter frequencies = new RealParameter("0.683 0.317");
RealParameter hfrequencies = new RealParameter("0.5 0.5");
BinaryCovarion covarion = new BinaryCovarion();
covarion.initByName("alpha", alpha, "switchRate", switchRate, "vfrequencies", frequencies, "hfrequencies", hfrequencies);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
// beast1 xml gives -1730.5363
assertEquals(logP, -1730.53631739, BEASTTestCase.PRECISION);
}
Aggregations