use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class BeagleTreeLikelihood method main.
public static void main(String[] args) {
try {
MathUtils.setSeed(666);
System.out.println("Test case 1: simulateOnePartition");
int sequenceLength = 1000;
ArrayList<Partition> partitionsList = new ArrayList<Partition>();
// create tree
NewickImporter importer = new NewickImporter("(SimSeq1:73.7468,(SimSeq2:25.256989999999995,SimSeq3:45.256989999999995):18.48981);");
Tree tree = importer.importTree(null);
TreeModel treeModel = new TreeModel(tree);
// create Frequency Model
Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
FrequencyModel freqModel = new FrequencyModel(Nucleotides.INSTANCE, freqs);
// create branch model
Parameter kappa1 = new Parameter.Default(1, 1);
Parameter kappa2 = new Parameter.Default(1, 1);
HKY hky1 = new HKY(kappa1, freqModel);
HKY hky2 = new HKY(kappa2, freqModel);
HomogeneousBranchModel homogenousBranchSubstitutionModel = new HomogeneousBranchModel(hky1);
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
substitutionModels.add(hky1);
substitutionModels.add(hky2);
List<FrequencyModel> freqModels = new ArrayList<FrequencyModel>();
freqModels.add(freqModel);
Parameter epochTimes = new Parameter.Default(1, 20);
// create branch rate model
Parameter rate = new Parameter.Default(1, 0.001);
BranchRateModel branchRateModel = new StrictClockBranchRates(rate);
// create site model
GammaSiteRateModel siteRateModel = new GammaSiteRateModel("siteModel");
BranchModel homogeneousBranchModel = new HomogeneousBranchModel(hky1);
BranchModel epochBranchModel = new EpochBranchModel(treeModel, substitutionModels, epochTimes);
// create partition
Partition partition1 = new //
Partition(//
treeModel, //
homogenousBranchSubstitutionModel, //
siteRateModel, //
branchRateModel, //
freqModel, // from
0, // to
sequenceLength - 1, // every
1);
partitionsList.add(partition1);
// feed to sequence simulator and generate data
BeagleSequenceSimulator simulator = new BeagleSequenceSimulator(partitionsList);
Alignment alignment = simulator.simulate(false, false);
BeagleTreeLikelihood nbtl = new BeagleTreeLikelihood(alignment, treeModel, homogeneousBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
System.out.println("nBTL(homogeneous) = " + nbtl.getLogLikelihood());
nbtl = new BeagleTreeLikelihood(alignment, treeModel, epochBranchModel, siteRateModel, branchRateModel, null, false, PartialsRescalingScheme.DEFAULT, false);
System.out.println("nBTL(epoch) = " + nbtl.getLogLikelihood());
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}
// END: try-catch block
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class ConjugateRootTraitPrior method parseConjugateRootTraitPrior.
public static ConjugateRootTraitPrior parseConjugateRootTraitPrior(XMLObject xo, final int dim) throws XMLParseException {
XMLObject cxo = xo.getChild(CONJUGATE_ROOT_PRIOR);
Parameter meanParameter = (Parameter) cxo.getChild(MultivariateDistributionLikelihood.MVN_MEAN).getChild(Parameter.class);
if (meanParameter.getDimension() != dim) {
throw new XMLParseException("Root prior mean dimension does not match trait diffusion dimension");
}
Parameter sampleSizeParameter = (Parameter) cxo.getChild(PRIOR_SAMPLE_SIZE).getChild(Parameter.class);
return new ConjugateRootTraitPrior(meanParameter.getParameterValues(), sampleSizeParameter.getParameterValue(0));
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class BranchCategoriesParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Parameter allocationParameter = (Parameter) xo.getElementFirstChild(ALLOCATION);
CountableBranchCategoryProvider cladeModel;
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
if (!xo.getAttribute(RANDOMIZE, true)) {
CountableBranchCategoryProvider.CladeBranchCategoryModel cm = new CountableBranchCategoryProvider.CladeBranchCategoryModel(treeModel, allocationParameter);
for (int i = 0; i < xo.getChildCount(); ++i) {
if (xo.getChild(i) instanceof XMLObject) {
XMLObject xoc = (XMLObject) xo.getChild(i);
if (xoc.getName().equals(LocalClockModelParser.CLADE)) {
TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
// XML index-start = 1 not 0
int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
try {
cm.setClade(taxonList, rateCategory, includeStem, excludeClade, false);
} catch (TreeUtils.MissingTaxonException e) {
throw new XMLParseException("Unable to find taxon for clade in countable mixture model: " + e.getMessage());
}
} else if (xoc.getName().equals(LocalClockModelParser.TRUNK)) {
TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
// XML index-start = 1 not 0
int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
try {
cm.setClade(taxonList, rateCategory, includeStem, excludeClade, true);
} catch (TreeUtils.MissingTaxonException e) {
throw new XMLParseException("Unable to find taxon for trunk in countable mixture model: " + e.getMessage());
}
}
}
}
cladeModel = cm;
} else {
CountableBranchCategoryProvider.IndependentBranchCategoryModel cm = new CountableBranchCategoryProvider.IndependentBranchCategoryModel(treeModel, allocationParameter);
cm.randomize();
cladeModel = cm;
}
return cladeModel;
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class HamiltonianMonteCarloOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
int nSteps = xo.getIntegerAttribute(N_STEPS);
double stepSize = xo.getDoubleAttribute(STEP_SIZE);
double drawVariance = xo.getDoubleAttribute(DRAW_VARIANCE);
int mode = xo.getAttribute(MODE, 0);
GradientWrtParameterProvider derivative = (GradientWrtParameterProvider) xo.getChild(GradientWrtParameterProvider.class);
Parameter parameter = (Parameter) xo.getChild(Parameter.class);
Transform transform = null;
if (parameter == null) {
Transform.Collection collection = (Transform.Collection) xo.getChild(Transform.Collection.class);
parameter = collection.getParameter();
transform = collection;
}
if (derivative.getDimension() != parameter.getDimension()) {
throw new XMLParseException("Gradient (" + derivative.getDimension() + ") must be the same dimensions as the parameter (" + parameter.getDimension() + ")");
}
if (mode == 0) {
return new HamiltonianMonteCarloOperator(CoercionMode.DEFAULT, weight, derivative, parameter, transform, stepSize, nSteps, drawVariance);
} else {
return new NoUTurnOperator(CoercionMode.DEFAULT, weight, derivative, parameter, stepSize, nSteps, drawVariance);
}
}
use of dr.inference.model.Parameter in project beast-mcmc by beast-dev.
the class NegationOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Parameter data = (Parameter) xo.getChild(Parameter.class);
double weight = xo.getDoubleAttribute(WEIGHT);
return new NegationOperator(data, weight);
}
Aggregations