Search in sources :

Example 1 with LinearBiasModel

use of dr.oldevomodel.substmodel.LinearBiasModel 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 TreeModel(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) 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) 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 2 with LinearBiasModel

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

the class LinearBiasTest method testLinearBiasModel.

public void testLinearBiasModel() {
    for (Instance test : all) {
        OnePhaseModel subModel = test.getSubModel();
        Microsatellite microsat = (Microsatellite) subModel.getDataType();
        Parameter biasLinear = new Parameter.Default(1, test.getBiasLinearParam());
        Parameter biasConstant = new Parameter.Default(1, test.getBiasConstantParam());
        LinearBiasModel lbm = new LinearBiasModel(microsat, null, subModel, biasConstant, biasLinear, test.isLogistics(), false, false);
        lbm.computeStationaryDistribution();
        double[] statDist = lbm.getStationaryDistribution();
        final double[] expectedStatDist = test.getExpectedPi();
        for (int k = 0; k < statDist.length; ++k) {
            assertEquals(statDist[k], expectedStatDist[k], 1e-10);
        }
        int stateCount = microsat.getStateCount();
        double[] mat = new double[stateCount * stateCount];
        lbm.getTransitionProbabilities(test.getDistance(), mat);
        final double[] result = test.getExpectedResult();
        int k;
        for (k = 0; k < mat.length; ++k) {
            assertEquals(result[k], mat[k], 5e-9);
        //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++], lbm.getOneTransitionProbabilityEntry(test.getDistance(), i, j), 5e-9);
            }
        }
        for (int j = 0; j < microsat.getStateCount(); j++) {
            double[] colTransitionProb = lbm.getColTransitionProbabilities(test.getDistance(), j);
            for (int i = 0; i < microsat.getStateCount(); i++) {
                assertEquals(result[i * microsat.getStateCount() + j], colTransitionProb[i], 5e-9);
            }
        }
        for (int i = 0; i < microsat.getStateCount(); i++) {
            double[] rowTransitionProb = lbm.getRowTransitionProbabilities(test.getDistance(), i);
            for (int j = 0; j < microsat.getStateCount(); j++) {
                assertEquals(result[i * microsat.getStateCount() + j], rowTransitionProb[j], 5e-9);
            }
        }
    }
}
Also used : Microsatellite(dr.evolution.datatype.Microsatellite) Parameter(dr.inference.model.Parameter) OnePhaseModel(dr.oldevomodel.substmodel.OnePhaseModel) LinearBiasModel(dr.oldevomodel.substmodel.LinearBiasModel)

Example 3 with LinearBiasModel

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

the class LinearBiasModelParser method parseXMLObject.

//AbstractXMLObjectParser implementation
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    OnePhaseModel subModel = (OnePhaseModel) xo.getElementFirstChild(SUBMODEL);
    Microsatellite dataType = (Microsatellite) subModel.getDataType();
    Parameter biasConst = null;
    if (xo.hasChildNamed(BIAS_CONSTANT)) {
        biasConst = (Parameter) xo.getElementFirstChild(BIAS_CONSTANT);
    }
    Parameter biasLin = null;
    if (xo.hasChildNamed(BIAS_LINEAR)) {
        biasLin = (Parameter) xo.getElementFirstChild(BIAS_LINEAR);
    }
    //get FrequencyModel
    FrequencyModel freqModel = null;
    if (xo.hasChildNamed(FrequencyModelParser.FREQUENCIES)) {
        freqModel = (FrequencyModel) xo.getElementFirstChild(FrequencyModelParser.FREQUENCIES);
    }
    boolean estimateSubmodelParams = false;
    if (xo.hasAttribute(ESTIMATE_SUBMODEL_PARAMS)) {
        estimateSubmodelParams = xo.getBooleanAttribute(ESTIMATE_SUBMODEL_PARAMS);
    }
    System.out.println("Is estimating submodel parameter(s): " + estimateSubmodelParams);
    boolean logistics = false;
    if (xo.hasAttribute(LOGISTICS)) {
        logistics = xo.getBooleanAttribute(LOGISTICS);
    }
    System.out.println("Using logistic regression: " + logistics);
    boolean isSubmodel = false;
    if (xo.hasAttribute(IS_SUBMODEL)) {
        isSubmodel = xo.getBooleanAttribute(IS_SUBMODEL);
    }
    System.out.println("Is a submodel: " + isSubmodel);
    return new LinearBiasModel(dataType, freqModel, subModel, biasConst, biasLin, logistics, estimateSubmodelParams, isSubmodel);
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) Microsatellite(dr.evolution.datatype.Microsatellite) Parameter(dr.inference.model.Parameter) OnePhaseModel(dr.oldevomodel.substmodel.OnePhaseModel) LinearBiasModel(dr.oldevomodel.substmodel.LinearBiasModel)

Aggregations

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