Search in sources :

Example 1 with SubstitutionModel

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);
        }
    }
}
Also used : GammaSiteBMA(dr.oldevomodel.sitemodel.GammaSiteBMA) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Example 2 with SubstitutionModel

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;
}
Also used : MatrixParameter(dr.inference.model.MatrixParameter) MultivariateOUModel(dr.inferencexml.distribution.MultivariateOUModel) Parameter(dr.inference.model.Parameter) MatrixParameter(dr.inference.model.MatrixParameter) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Example 3 with SubstitutionModel

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);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) ArrayList(java.util.ArrayList) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) SubstitutionEpochModel(dr.oldevomodel.substmodel.SubstitutionEpochModel) AbstractSubstitutionModel(dr.oldevomodel.substmodel.AbstractSubstitutionModel) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Example 4 with SubstitutionModel

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);
}
Also used : SampleStateAndCategoryModel(dr.oldevomodel.sitemodel.SampleStateAndCategoryModel) Parameter(dr.inference.model.Parameter) Vector(java.util.Vector) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Example 5 with SubstitutionModel

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);
}
Also used : GammaSiteBMA(dr.oldevomodel.sitemodel.GammaSiteBMA) Variable(dr.inference.model.Variable) Parameter(dr.inference.model.Parameter) SubstitutionModel(dr.oldevomodel.substmodel.SubstitutionModel)

Aggregations

SubstitutionModel (dr.oldevomodel.substmodel.SubstitutionModel)12 Parameter (dr.inference.model.Parameter)10 DataType (dr.evolution.datatype.DataType)2 GammaSiteBMA (dr.oldevomodel.sitemodel.GammaSiteBMA)2 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)2 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)2 Vector (java.util.Vector)2 Alignment (dr.evolution.alignment.Alignment)1 ExtractPairs (dr.evolution.alignment.ExtractPairs)1 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)1 SitePatterns (dr.evolution.alignment.SitePatterns)1 NexusImporter (dr.evolution.io.NexusImporter)1 Sequence (dr.evolution.sequence.Sequence)1 NodeRef (dr.evolution.tree.NodeRef)1 Tree (dr.evolution.tree.Tree)1 MatrixParameter (dr.inference.model.MatrixParameter)1 Variable (dr.inference.model.Variable)1 MultivariateOUModel (dr.inferencexml.distribution.MultivariateOUModel)1 CategorySiteModel (dr.oldevomodel.sitemodel.CategorySiteModel)1 SampleStateAndCategoryModel (dr.oldevomodel.sitemodel.SampleStateAndCategoryModel)1