use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class RelaxedDriftModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
Parameter ratesParameter = (Parameter) xo.getElementFirstChild(RATES);
Parameter rateIndicatorParameter = (Parameter) xo.getElementFirstChild(RATE_IND);
Parameter driftRates = null;
if (xo.hasChildNamed(DRIFT_RATES)) {
driftRates = (Parameter) xo.getElementFirstChild(DRIFT_RATES);
}
Logger.getLogger("dr.evomodel").info("Using relaxed drift model.");
return new RelaxedDriftModel(tree, rateIndicatorParameter, ratesParameter, driftRates);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class ScaledTreeLengthRateModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
Parameter totalLength = (Parameter) xo.getElementFirstChild(SCALING_FACTOR);
if (totalLength == null) {
totalLength = new Parameter.Default(1, 1.0);
}
Logger.getLogger("dr.evomodel.branchratemodel").info("\n ---------------------------------\nCreating ScaledTreeLengthRateModel model.");
Logger.getLogger("dr.evomodel.branchratemodel").info("\tTotal tree length will be scaled to " + totalLength.getParameterValue(0) + ".");
Logger.getLogger("dr.evomodel.branchratemodel").info("\tIf you publish results using this rate model, please cite Alekseyenko, Lee and Suchard (2008) Syst. Biol 57: 772-784." + "\n---------------------------------\n");
return new ScaledTreeLengthRateModel(tree, totalLength);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class GMRFSkyrideLikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
XMLObject cxo = xo.getChild(POPULATION_PARAMETER);
Parameter popParameter = (Parameter) cxo.getChild(Parameter.class);
cxo = xo.getChild(PRECISION_PARAMETER);
Parameter precParameter = (Parameter) cxo.getChild(Parameter.class);
cxo = xo.getChild(POPULATION_TREE);
List<Tree> treeList = new ArrayList<Tree>();
for (int i = 0; i < cxo.getChildCount(); i++) {
Object testObject = cxo.getChild(i);
if (testObject instanceof Tree) {
treeList.add((TreeModel) testObject);
}
}
// TreeModel treeModel = (TreeModel) cxo.getChild(TreeModel.class);
cxo = xo.getChild(GROUP_SIZES);
Parameter groupParameter = null;
if (cxo != null) {
groupParameter = (Parameter) cxo.getChild(Parameter.class);
if (popParameter.getDimension() != groupParameter.getDimension())
throw new XMLParseException("Population and group size parameters must have the same length");
}
Parameter lambda;
if (xo.getChild(LAMBDA_PARAMETER) != null) {
cxo = xo.getChild(LAMBDA_PARAMETER);
lambda = (Parameter) cxo.getChild(Parameter.class);
} else {
lambda = new Parameter.Default(LAMBDA_PARAMETER, 1.0);
}
Parameter gridPoints = null;
if (xo.getChild(GRID_POINTS) != null) {
cxo = xo.getChild(GRID_POINTS);
gridPoints = (Parameter) cxo.getChild(Parameter.class);
}
Parameter numGridPoints = null;
if (xo.getChild(NUM_GRID_POINTS) != null) {
cxo = xo.getChild(NUM_GRID_POINTS);
numGridPoints = (Parameter) cxo.getChild(Parameter.class);
}
Parameter cutOff = null;
if (xo.getChild(CUT_OFF) != null) {
cxo = xo.getChild(CUT_OFF);
cutOff = (Parameter) cxo.getChild(Parameter.class);
}
Parameter phi = null;
if (xo.getChild(PHI_PARAMETER) != null) {
cxo = xo.getChild(PHI_PARAMETER);
phi = (Parameter) cxo.getChild(Parameter.class);
}
List<Parameter> lastObservedIndex = null;
if (xo.hasChildNamed(LAST_OBSERVED_INDEX)) {
lastObservedIndex = new ArrayList<Parameter>();
cxo = xo.getChild(LAST_OBSERVED_INDEX);
final int numObsInd = cxo.getChildCount();
for (int i = 0; i < numObsInd; ++i) {
lastObservedIndex.add((Parameter) cxo.getChild(i));
}
}
Parameter ploidyFactors = null;
if (xo.getChild(PLOIDY) != null) {
cxo = xo.getChild(PLOIDY);
ploidyFactors = (Parameter) cxo.getChild(Parameter.class);
} else {
ploidyFactors = new Parameter.Default(PLOIDY, treeList.size());
for (int i = 0; i < treeList.size(); i++) {
ploidyFactors.setParameterValue(i, 1.0);
}
}
Parameter betaParameter = null;
if (xo.hasChildNamed(SINGLE_BETA)) {
betaParameter = (Parameter) xo.getElementFirstChild(SINGLE_BETA);
}
List<Parameter> betaList = null;
if (xo.getChild(BETA_PARAMETER) != null) {
betaList = new ArrayList<Parameter>();
cxo = xo.getChild(BETA_PARAMETER);
final int numBeta = cxo.getChildCount();
for (int i = 0; i < numBeta; ++i) {
betaList.add((Parameter) cxo.getChild(i));
}
}
MatrixParameter dMatrix = null;
if (xo.getChild(COVARIATE_MATRIX) != null) {
cxo = xo.getChild(COVARIATE_MATRIX);
dMatrix = (MatrixParameter) cxo.getChild(MatrixParameter.class);
}
boolean timeAwareSmoothing = GMRFSkyrideLikelihood.TIME_AWARE_IS_ON_BY_DEFAULT;
if (xo.hasAttribute(TIME_AWARE_SMOOTHING)) {
timeAwareSmoothing = xo.getBooleanAttribute(TIME_AWARE_SMOOTHING);
}
if (dMatrix != null) {
if (dMatrix.getRowDimension() != popParameter.getDimension())
throw new XMLParseException("Design matrix row dimension must equal the population parameter length.");
if (dMatrix.getColumnDimension() != betaParameter.getDimension())
throw new XMLParseException("Design matrix column dimension must equal the regression coefficient length.");
}
List<Parameter> covPrecParam = null;
if (xo.hasChildNamed(COV_PREC_PARAM)) {
covPrecParam = new ArrayList<Parameter>();
cxo = xo.getChild(COV_PREC_PARAM);
final int numCovPrec = cxo.getChildCount();
for (int i = 0; i < numCovPrec; ++i) {
covPrecParam.add((Parameter) cxo.getChild(i));
}
}
List<MatrixParameter> covariates = null;
if (xo.hasChildNamed(COVARIATES)) {
covariates = new ArrayList<MatrixParameter>();
cxo = xo.getChild(COVARIATES);
final int numCov = cxo.getChildCount();
for (int i = 0; i < numCov; ++i) {
covariates.add((MatrixParameter) cxo.getChild(i));
}
}
if ((covariates != null && betaList == null) || (covariates == null && betaList != null))
throw new XMLParseException("Must specify both a set of regression coefficients and a design matrix.");
if (xo.getAttribute(RANDOMIZE_TREE, false)) {
for (Tree tree : treeList) {
if (tree instanceof TreeModel) {
GMRFSkyrideLikelihood.checkTree((TreeModel) tree);
} else {
throw new XMLParseException("Can not randomize a fixed tree");
}
}
}
boolean rescaleByRootHeight = xo.getAttribute(RESCALE_BY_ROOT_ISSUE, true);
Logger.getLogger("dr.evomodel").info("The " + SKYLINE_LIKELIHOOD + " has " + (timeAwareSmoothing ? "time aware smoothing" : "uniform smoothing"));
if (xo.getAttribute(OLD_SKYRIDE, true) && xo.getName().compareTo(SKYGRID_LIKELIHOOD) != 0) {
return new GMRFSkyrideLikelihood(treeList, popParameter, groupParameter, precParameter, lambda, betaParameter, dMatrix, timeAwareSmoothing, rescaleByRootHeight);
} else {
if (xo.getChild(GRID_POINTS) != null) {
return new GMRFMultilocusSkyrideLikelihood(treeList, popParameter, groupParameter, precParameter, lambda, betaParameter, dMatrix, timeAwareSmoothing, gridPoints, covariates, ploidyFactors, lastObservedIndex, covPrecParam, betaList);
} else {
return new GMRFMultilocusSkyrideLikelihood(treeList, popParameter, groupParameter, precParameter, lambda, betaParameter, dMatrix, timeAwareSmoothing, cutOff.getParameterValue(0), (int) numGridPoints.getParameterValue(0), phi, ploidyFactors);
}
}
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class WilsonBaldingParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
return new WilsonBalding(treeModel, weight);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class GaussianProcessSkytrackTreeOperatorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
// boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false);
// Handler gmrfHandler;
// Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator");
// gmrfLogger.setUseParentHandlers(false);
// if (logRecord) {
// gmrfLogger.setLevel(Level.FINE);
//
// try {
// gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed());
// } catch (IOException e) {
// throw new RuntimeException(e.getMessage());
// }
// gmrfHandler.setLevel(Level.FINE);
//
// gmrfHandler.setFormatter(new XMLFormatter() {
// public String format(LogRecord record) {
// return "<record>\n \t<message>\n\t" + record.getMessage()
// + "\n\t</message>\n<record>\n";
// }
// });
//
// gmrfLogger.addHandler(gmrfHandler);
// }
CoercionMode mode = CoercionMode.parseMode(xo);
if (mode == CoercionMode.DEFAULT)
mode = CoercionMode.COERCION_ON;
double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
// if (scaleFactor <= 0.0) {
// throw new XMLParseException("scaleFactor must be greater than 0.0");
// if (scaleFactor < 1.0) {
// throw new XMLParseException("scaleFactor must be greater than or equal to 1.0");
// }
// int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200);
// double stopValue = xo.getAttribute(STOP_VALUE, 0.01);
GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
return new GaussianProcessSkytrackTreeOperator(treeModel, gpLikelihood, weight, scaleFactor, mode);
}
Aggregations