use of dr.oldevomodel.substmodel.SubstitutionModel in project beast-mcmc by beast-dev.
the class testGammaSiteBMA method testGammaSiteBMA.
public void testGammaSiteBMA() {
for (Instance test : all) {
SubstitutionModel substModel = test.getSubstModel();
Parameter mu = new Parameter.Default(test.getMu());
Parameter logitInvar = new Parameter.Default(test.getLogitInvar());
Parameter logShape = new Parameter.Default(test.getLogShape());
int catCount = test.getCategoryCount();
Variable<Integer> modelChoose = test.getModelChoose();
GammaSiteBMA gammaSiteBMA = new GammaSiteBMA(substModel, mu, logitInvar, logShape, catCount, modelChoose);
double[] catRates = gammaSiteBMA.getCategoryRates();
double[] expectedCatRates = test.getCategoryRates();
for (int i = 0; i < catRates.length; i++) {
assertEquals(catRates[i], expectedCatRates[i], 8e-10);
}
double[] catProps = gammaSiteBMA.getCategoryProportions();
double[] expectedCatProps = test.getCategoryProportions();
for (int i = 0; i < catProps.length; i++) {
assertEquals(catProps[i], expectedCatProps[i], 1e-10);
}
}
}
use of dr.oldevomodel.substmodel.SubstitutionModel in project beast-mcmc by beast-dev.
the class MultivariateOUModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
Parameter effectParameter = (Parameter) ((XMLObject) xo.getChild(DATA)).getChild(Parameter.class);
Parameter timesParameter = (Parameter) ((XMLObject) xo.getChild(TIME)).getChild(Parameter.class);
Parameter designParameter = (Parameter) ((XMLObject) xo.getChild(DESIGN)).getChild(Parameter.class);
MatrixParameter gammaParameter = (MatrixParameter) xo.getChild(MatrixParameter.class);
if (effectParameter.getDimension() != timesParameter.getDimension() || effectParameter.getDimension() != designParameter.getDimension()) {
// System.err.println("dim(design) "+designParameter.getDimension());
throw new XMLParseException("dim(" + effectParameter.getStatisticName() + ") != dim(" + timesParameter.getStatisticName() + ") != dim(" + designParameter.getStatisticName() + ") in " + xo.getName() + " element");
}
MultivariateOUModel glm = new MultivariateOUModel(substitutionModel, effectParameter, gammaParameter, timesParameter.getParameterValues(), designParameter.getParameterValues());
addIndependentParameters(xo, glm, effectParameter);
return glm;
}
use of dr.oldevomodel.substmodel.SubstitutionModel in project beast-mcmc by beast-dev.
the class SubstitutionEpochModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
DataType dataType = null;
FrequencyModel freqModel = null;
List<SubstitutionModel> modelList = new ArrayList<SubstitutionModel>();
XMLObject cxo = xo.getChild(MODELS);
for (int i = 0; i < cxo.getChildCount(); i++) {
SubstitutionModel model = (SubstitutionModel) cxo.getChild(i);
if (dataType == null) {
dataType = model.getDataType();
} else if (dataType != model.getDataType())
throw new XMLParseException("Substitution models across epoches must use the same data type.");
if (freqModel == null) {
freqModel = model.getFrequencyModel();
} else if (freqModel != model.getFrequencyModel())
throw new XMLParseException("Substitution models across epoches must currently use the same frequency model.\nHarass Marc to fix this.");
modelList.add(model);
}
Parameter transitionTimes = (Parameter) xo.getChild(Parameter.class);
if (transitionTimes.getDimension() != modelList.size() - 1) {
throw new XMLParseException("# of transition times must equal # of substitution models - 1\n" + transitionTimes.getDimension() + "\n" + modelList.size());
}
return new SubstitutionEpochModel(SUBSTITUTION_EPOCH_MODEL, modelList, transitionTimes, dataType, freqModel);
}
use of dr.oldevomodel.substmodel.SubstitutionModel in project beast-mcmc by beast-dev.
the class SampleStateAndCategoryModelParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
XMLObject cxo = xo.getChild(MUTATION_RATE);
Parameter muParam = (Parameter) cxo.getChild(Parameter.class);
cxo = xo.getChild(CATEGORY_PARAMETER);
Parameter catParam = (Parameter) cxo.getChild(Parameter.class);
Vector subModels = new Vector();
for (int i = 0; i < xo.getChildCount(); i++) {
if (xo.getChild(i) instanceof SubstitutionModel) {
subModels.addElement(xo.getChild(i));
}
}
return new SampleStateAndCategoryModel(muParam, catParam, subModels);
}
use of dr.oldevomodel.substmodel.SubstitutionModel in project beast-mcmc by beast-dev.
the class GammaSiteBMAParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getElementFirstChild(SUBSTITUTION_MODEL);
Parameter muParam = (Parameter) xo.getElementFirstChild(MUTATION_RATE);
Parameter logitInvar = (Parameter) xo.getElementFirstChild(LOGIT_PROPORTION_INVARIANT);
final XMLObject cxo = xo.getChild(LOG_GAMMA_SHAPE);
Parameter logShape = (Parameter) cxo.getChild(Parameter.class);
int catCount = cxo.getIntegerAttribute(GAMMA_CATEGORIES);
Variable<Integer> modelChoose = (Variable<Integer>) xo.getElementFirstChild(MODEL_CHOOSE);
return new GammaSiteBMA(substitutionModel, muParam, logitInvar, logShape, catCount, modelChoose);
}
Aggregations