Search in sources :

Example 1 with AsymmetricQuadraticModel

use of dr.oldevomodel.substmodel.AsymmetricQuadraticModel in project beast-mcmc by beast-dev.

the class AsymQuadModelParser method parseXMLObject.

// AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Microsatellite microsatellite = (Microsatellite) xo.getChild(Microsatellite.class);
    Parameter expanConst = processModelParameter(xo, EXPANSION_CONSTANT);
    Parameter expanLin = processModelParameter(xo, EXPANSION_LIN);
    Parameter expanQuad = processModelParameter(xo, EXPANSION_QUAD);
    Parameter contractConst = processModelParameter(xo, CONTRACTION_CONSTANT);
    Parameter contractLin = processModelParameter(xo, CONTRACTION_LIN);
    Parameter contractQuad = processModelParameter(xo, CONTRACTION_QUAD);
    // get FrequencyModel
    FrequencyModel freqModel = null;
    if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
        freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
    }
    boolean isSubmodel = xo.getAttribute(IS_SUBMODEL, false);
    return new AsymmetricQuadraticModel(microsatellite, freqModel, expanConst, expanLin, expanQuad, contractConst, contractLin, contractQuad, isSubmodel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Microsatellite(dr.evolution.datatype.Microsatellite) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Parameter(dr.inference.model.Parameter)

Example 2 with AsymmetricQuadraticModel

use of dr.oldevomodel.substmodel.AsymmetricQuadraticModel in project beast-mcmc by beast-dev.

the class MsatSamplingTreeLikelihoodTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // taxa
    ArrayList<Taxon> taxonList3 = new ArrayList<Taxon>();
    Collections.addAll(taxonList3, new Taxon("Taxon1"), new Taxon("Taxon2"), new Taxon("Taxon3"), new Taxon("Taxon4"), new Taxon("Taxon5"), new Taxon("Taxon6"), new Taxon("Taxon7"));
    Taxa taxa3 = new Taxa(taxonList3);
    // msat datatype
    Microsatellite msat = new Microsatellite(1, 6);
    Patterns msatPatterns = new Patterns(msat, taxa3);
    // pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 3, 2, 4, 5, 1 });
    // create tree
    NewickImporter importer = new NewickImporter("(((Taxon1:0.3,Taxon2:0.3):0.6,Taxon3:0.9):0.9,((Taxon4:0.5,Taxon5:0.5):0.3,(Taxon6:0.7,Taxon7:0.7):0.1):1.0);");
    Tree tree = importer.importTree(null);
    // treeModel
    TreeModel treeModel = new DefaultTreeModel(tree);
    // msatsubstModel
    AsymmetricQuadraticModel eu1 = new AsymmetricQuadraticModel(msat, null);
    // create msatSamplerTreeModel
    Parameter internalVal = new Parameter.Default(new double[] { 2, 3, 4, 2, 1, 5 });
    int[] externalValues = msatPatterns.getPattern(0);
    HashMap<String, Integer> taxaMap = new HashMap<String, Integer>(externalValues.length);
    boolean internalValuesProvided = true;
    for (int i = 0; i < externalValues.length; i++) {
        taxaMap.put(msatPatterns.getTaxonId(i), i);
    }
    MicrosatelliteSamplerTreeModel msatTreeModel = new MicrosatelliteSamplerTreeModel("JUnitTestEx", treeModel, internalVal, msatPatterns, externalValues, taxaMap, internalValuesProvided);
    // create msatSamplerTreeLikelihood
    BranchRateModel branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
    eu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu1, branchRateModel);
    // eu2
    TwoPhaseModel eu2 = new TwoPhaseModel(msat, null, eu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    eu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu2, branchRateModel);
    // ec1
    LinearBiasModel ec1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
    ec1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec1, branchRateModel);
    // ec2
    TwoPhaseModel ec2 = new TwoPhaseModel(msat, null, ec1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    ec2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec2, branchRateModel);
    // el1
    LinearBiasModel el1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.2), new Parameter.Default(-0.018), true, false, false);
    el1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, el1, branchRateModel);
    AsymmetricQuadraticModel pu1 = new AsymmetricQuadraticModel(msat, null, new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), false);
    pu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu1, branchRateModel);
    // ec2
    TwoPhaseModel pu2 = new TwoPhaseModel(msat, null, pu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
    pu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu2, branchRateModel);
    // ec1
    LinearBiasModel pc1 = new LinearBiasModel(msat, null, pu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
    pc1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pc1, branchRateModel);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StrictClockBranchRates(dr.evomodel.branchratemodel.StrictClockBranchRates) Taxa(dr.evolution.util.Taxa) MicrosatelliteSamplerTreeModel(dr.evomodel.tree.MicrosatelliteSamplerTreeModel) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns) Microsatellite(dr.evolution.datatype.Microsatellite) MicrosatelliteSamplerTreeModel(dr.evomodel.tree.MicrosatelliteSamplerTreeModel) Taxon(dr.evolution.util.Taxon) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) LinearBiasModel(dr.oldevomodel.substmodel.LinearBiasModel) BranchRateModel(dr.evomodel.branchratemodel.BranchRateModel) Parameter(dr.inference.model.Parameter) MicrosatelliteSamplerTreeLikelihood(dr.oldevomodel.treelikelihood.MicrosatelliteSamplerTreeLikelihood) TwoPhaseModel(dr.oldevomodel.substmodel.TwoPhaseModel)

Example 3 with AsymmetricQuadraticModel

use of dr.oldevomodel.substmodel.AsymmetricQuadraticModel in project beast-mcmc by beast-dev.

the class MsatFullLikelihoodTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // taxa
    ArrayList<Taxon> taxonList1 = new ArrayList<Taxon>();
    Collections.addAll(taxonList1, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"));
    Taxa taxa1 = new Taxa(taxonList1);
    // msat datatype
    Microsatellite msat = new Microsatellite(1, 3);
    Patterns msatPatterns = new Patterns(msat, taxa1);
    // pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 2 });
    // create tree
    NewickImporter importer = new NewickImporter("(taxon1:7.5,(taxon2:5.3,taxon3:5.3):2.2);");
    Tree tree = importer.importTree(null);
    // treeModel
    TreeModel treeModel = new DefaultTreeModel(tree);
    // msatsubstModel
    AsymmetricQuadraticModel aqm1 = new AsymmetricQuadraticModel(msat, null);
    // siteModel
    GammaSiteModel siteModel = new GammaSiteModel(aqm1);
    // treeLikelihood
    treeLikelihood1 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
    setUpExample2();
    setUpExample3();
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) Taxa(dr.evolution.util.Taxa) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Example 4 with AsymmetricQuadraticModel

use of dr.oldevomodel.substmodel.AsymmetricQuadraticModel in project beast-mcmc by beast-dev.

the class MsatFullLikelihoodTest method setUpExample2.

private void setUpExample2() throws Exception {
    // taxa
    ArrayList<Taxon> taxonList2 = new ArrayList<Taxon>();
    Collections.addAll(taxonList2, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"), new Taxon("taxon4"), new Taxon("taxon5"));
    Taxa taxa2 = new Taxa(taxonList2);
    // msat datatype
    Microsatellite msat = new Microsatellite(1, 3);
    Patterns msatPatterns = new Patterns(msat, taxa2);
    // pattern in the correct code form.
    msatPatterns.addPattern(new int[] { 0, 1, 2, 1, 2 });
    // create tree
    NewickImporter importer = new NewickImporter("(((taxon1:1.5,taxon2:1.5):1.5,(taxon3:2.1,taxon4:2.1):0.9):0.7,taxon5:3.7);");
    Tree tree = importer.importTree(null);
    // treeModel
    TreeModel treeModel = new DefaultTreeModel(tree);
    // msatsubstModel
    AsymmetricQuadraticModel aqm2 = new AsymmetricQuadraticModel(msat, null);
    // siteModel
    GammaSiteModel siteModel = new GammaSiteModel(aqm2);
    // treeLikelihood
    treeLikelihood2 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) Taxon(dr.evolution.util.Taxon) ArrayList(java.util.ArrayList) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) Taxa(dr.evolution.util.Taxa) TreeModel(dr.evomodel.tree.TreeModel) DefaultTreeModel(dr.evomodel.tree.DefaultTreeModel) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) NewickImporter(dr.evolution.io.NewickImporter) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Tree(dr.evolution.tree.Tree) Patterns(dr.evolution.alignment.Patterns)

Example 5 with AsymmetricQuadraticModel

use of dr.oldevomodel.substmodel.AsymmetricQuadraticModel in project beast-mcmc by beast-dev.

the class AsymQuadTest method testAsymmetricQuadraticModel.

public void testAsymmetricQuadraticModel() {
    for (Instance test : all) {
        Parameter expanConst = new Parameter.Default(1, test.getExpanConst());
        Parameter expanLin = new Parameter.Default(1, test.getExpanLin());
        Parameter expanQuad = new Parameter.Default(1, test.getExpanQuad());
        Parameter contractConst = new Parameter.Default(1, test.getContractConst());
        Parameter contractLin = new Parameter.Default(1, test.getContractLin());
        Parameter contractQuad = new Parameter.Default(1, test.getContractQuad());
        Microsatellite microsat = test.getDataType();
        AsymmetricQuadraticModel aqm = new AsymmetricQuadraticModel(microsat, null, expanConst, expanLin, expanQuad, contractConst, contractLin, contractQuad, false);
        aqm.computeStationaryDistribution();
        double[] statDist = aqm.getStationaryDistribution();
        final double[] expectedStatDist = test.getExpectedPi();
        for (int k = 0; k < statDist.length; ++k) {
            assertEquals(statDist[k], expectedStatDist[k], 1e-10);
        }
        double[] mat = new double[4 * 4];
        aqm.getTransitionProbabilities(test.getDistance(), mat);
        final double[] result = test.getExpectedResult();
        int k;
        for (k = 0; k < mat.length; ++k) {
            assertEquals(result[k], mat[k], 1e-10);
        // System.out.print(" " + (mat[k] - result[k]));
        }
        k = 0;
        for (int i = 0; i < microsat.getStateCount(); i++) {
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[k++], aqm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 1e-10);
            }
        }
        for (int j = 0; j < microsat.getStateCount(); j++) {
            double[] colTransitionProb = aqm.getColTransitionProbabilities(test.getDistance(), j);
            for (int i = 0; i < microsat.getStateCount(); i++) {
                assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 1e-10);
            }
        }
        for (int i = 0; i < microsat.getStateCount(); i++) {
            double[] rowTransitionProb = aqm.getRowTransitionProbabilities(test.getDistance(), i);
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 1e-10);
            }
        }
    }
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) AsymmetricQuadraticModel(dr.oldevomodel.substmodel.AsymmetricQuadraticModel) Parameter(dr.inference.model.Parameter)

Aggregations

Microsatellite (dr.evolution.datatype.Microsatellite)6 AsymmetricQuadraticModel (dr.oldevomodel.substmodel.AsymmetricQuadraticModel)6 Patterns (dr.evolution.alignment.Patterns)4 NewickImporter (dr.evolution.io.NewickImporter)4 Tree (dr.evolution.tree.Tree)4 Taxa (dr.evolution.util.Taxa)4 Taxon (dr.evolution.util.Taxon)4 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)4 TreeModel (dr.evomodel.tree.TreeModel)4 ArrayList (java.util.ArrayList)4 Parameter (dr.inference.model.Parameter)3 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)3 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)3 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 StrictClockBranchRates (dr.evomodel.branchratemodel.StrictClockBranchRates)1 MicrosatelliteSamplerTreeModel (dr.evomodel.tree.MicrosatelliteSamplerTreeModel)1 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)1 LinearBiasModel (dr.oldevomodel.substmodel.LinearBiasModel)1 TwoPhaseModel (dr.oldevomodel.substmodel.TwoPhaseModel)1 MicrosatelliteSamplerTreeLikelihood (dr.oldevomodel.treelikelihood.MicrosatelliteSamplerTreeLikelihood)1