Search in sources :

Example 11 with CompoundParameter

use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.

the class ScaleData method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    MatrixParameterInterface scaling = null;
    CompoundParameter temp = null;
    if (xo.getChild(MatrixParameterInterface.class) != null) {
        scaling = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
    } else {
        temp = (CompoundParameter) xo.getChild(CompoundParameter.class);
        scaling = MatrixParameter.recast(temp.getParameterName(), temp);
    }
    double[][] aData = scaling.getParameterAsMatrix();
    double[] meanList = new double[scaling.getRowDimension()];
    double[] varList = new double[scaling.getRowDimension()];
    double[] count = new double[scaling.getRowDimension()];
    for (int i = 0; i < scaling.getColumnDimension(); i++) {
        for (int j = 0; j < scaling.getRowDimension(); j++) {
            if (scaling.getParameterValue(j, i) != 0) {
                meanList[j] += scaling.getParameterValue(j, i);
                count[j]++;
            }
        }
    }
    for (int i = 0; i < scaling.getRowDimension(); i++) {
        //            if (continuous.getParameterValue(i) == 1)
        meanList[i] = meanList[i] / count[i];
    //            else
    //                meanList[i] = 0;
    }
    double[][] answerTemp = new double[scaling.getRowDimension()][scaling.getColumnDimension()];
    for (int i = 0; i < scaling.getColumnDimension(); i++) {
        for (int j = 0; j < scaling.getRowDimension(); j++) {
            if (aData[j][i] != 0) {
                answerTemp[j][i] = aData[j][i] - meanList[j];
            }
        }
    }
    for (int i = 0; i < scaling.getColumnDimension(); i++) {
        for (int j = 0; j < scaling.getRowDimension(); j++) {
            varList[j] += answerTemp[j][i] * answerTemp[j][i];
        }
    }
    for (int i = 0; i < scaling.getRowDimension(); i++) {
        //            if (continuous.getParameterValue(i) == 1) {
        varList[i] = varList[i] / (count[i] - 1);
        varList[i] = StrictMath.sqrt(varList[i]);
    }
    for (int i = 0; i < scaling.getColumnDimension(); i++) {
        for (int j = 0; j < scaling.getRowDimension(); j++) {
            scaling.setParameterValue(j, i, answerTemp[j][i] / varList[j]);
        }
    }
    return null;
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface)

Example 12 with CompoundParameter

use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.

the class ARGAddRemoveOperatorTest method flatPriorTester.

private void flatPriorTester(ARGModel arg, int chainLength, int sampleTreeEvery, double nodeCountSetting, double rootHeightAlpha, double rootHeightBeta, int maxCount) throws IOException, Importer.ImportException {
    MCMC mcmc = new MCMC("mcmc1");
    MCMCOptions options = new MCMCOptions(chainLength);
    //        double nodeCountSetting = 2.0;
    //        double rootHeightAlpha = 100;
    //        double rootHeightBeta = 0.5;
    OperatorSchedule schedule = getSchedule(arg);
    ARGUniformPrior uniformPrior = new ARGUniformPrior(arg, maxCount, arg.getExternalNodeCount());
    PoissonDistribution poisson = new PoissonDistribution(nodeCountSetting);
    DistributionLikelihood nodeCountPrior = new DistributionLikelihood(poisson, 0.0);
    ARGReassortmentNodeCountStatistic nodeCountStatistic = new ARGReassortmentNodeCountStatistic("nodeCount", arg);
    nodeCountPrior.addData(nodeCountStatistic);
    DistributionLikelihood rootPrior = new DistributionLikelihood(new GammaDistribution(rootHeightAlpha, rootHeightBeta), 0.0);
    CompoundParameter rootHeight = (CompoundParameter) arg.createNodeHeightsParameter(true, false, false);
    rootPrior.addData(rootHeight);
    List<Likelihood> likelihoods = new ArrayList<Likelihood>();
    likelihoods.add(uniformPrior);
    likelihoods.add(rootPrior);
    likelihoods.add(nodeCountPrior);
    CompoundLikelihood compoundLikelihood = new CompoundLikelihood(1, likelihoods);
    compoundLikelihood.setId("likelihood1");
    MCLogger[] loggers = new MCLogger[3];
    loggers[0] = new MCLogger(new TabDelimitedFormatter(System.out), 10000, false);
    loggers[0].add(compoundLikelihood);
    loggers[0].add(arg);
    File file = new File("test.args");
    file.deleteOnExit();
    FileOutputStream out = new FileOutputStream(file);
    loggers[1] = new ARGLogger(arg, new TabDelimitedFormatter(out), sampleTreeEvery, "test");
    ArrayLogFormatter formatter = new ArrayLogFormatter(false);
    loggers[2] = new MCLogger(formatter, sampleTreeEvery, false);
    loggers[2].add(arg);
    arg.getRootHeightParameter().setId("root");
    loggers[2].add(arg.getRootHeightParameter());
    mcmc.setShowOperatorAnalysis(true);
    mcmc.init(options, compoundLikelihood, schedule, loggers);
    mcmc.run();
    out.flush();
    out.close();
    List<Trace> traces = formatter.getTraces();
    //        Set<String> uniqueTrees = new HashSet<String>();
    //
    //        NexusImporter importer = new NexusImporter(new FileReader(file));
    //        while (importer.hasTree()) {
    //            Tree t = importer.importNextTree();
    //            uniqueTrees.add(Tree.Utils.uniqueNewick(t, t.getRoot()));
    //        }
    //
    //        TestCase.assertEquals(numTopologies, uniqueTrees.size());            List<Trace> traces = formatter.getTraces();
    ArrayTraceList traceList = new ArrayTraceList("ARGTest", traces, 0);
    for (int i = 1; i < traces.size(); i++) {
        traceList.analyseTrace(i);
    }
    TraceCorrelation nodeCountStats = traceList.getCorrelationStatistics(1);
    TraceCorrelation rootHeightStats = traceList.getCorrelationStatistics(4);
    assertExpectation("nodeCount", nodeCountStats, poisson.truncatedMean(maxCount));
    assertExpectation(TreeModelParser.ROOT_HEIGHT, rootHeightStats, rootHeightAlpha * rootHeightBeta);
}
Also used : PoissonDistribution(dr.math.distributions.PoissonDistribution) CompoundLikelihood(dr.inference.model.CompoundLikelihood) Likelihood(dr.inference.model.Likelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) MCMC(dr.inference.mcmc.MCMC) ArrayList(java.util.ArrayList) ARGUniformPrior(dr.evomodel.arg.coalescent.ARGUniformPrior) CompoundParameter(dr.inference.model.CompoundParameter) MCMCOptions(dr.inference.mcmc.MCMCOptions) ArrayLogFormatter(dr.inference.loggers.ArrayLogFormatter) ARGReassortmentNodeCountStatistic(dr.evomodel.arg.ARGReassortmentNodeCountStatistic) GammaDistribution(dr.math.distributions.GammaDistribution) TraceCorrelation(dr.inference.trace.TraceCorrelation) OperatorSchedule(dr.inference.operators.OperatorSchedule) SimpleOperatorSchedule(dr.inference.operators.SimpleOperatorSchedule) CompoundLikelihood(dr.inference.model.CompoundLikelihood) TabDelimitedFormatter(dr.inference.loggers.TabDelimitedFormatter) Trace(dr.inference.trace.Trace) ARGLogger(dr.evomodel.arg.ARGLogger) ArrayTraceList(dr.inference.trace.ArrayTraceList) FileOutputStream(java.io.FileOutputStream) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) File(java.io.File) MCLogger(dr.inference.loggers.MCLogger)

Example 13 with CompoundParameter

use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.

the class CountableRealizationsParameterParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter categoriesParameter = (Parameter) xo.getElementFirstChild(DirichletProcessPriorParser.CATEGORIES);
    CompoundParameter realizedParameters = (CompoundParameter) xo.getChild(CompoundParameter.class);
    return new CountableRealizationsParameter(categoriesParameter, realizedParameters);
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter)

Example 14 with CompoundParameter

use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.

the class DirichletProcessPriorLoggerParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    //		ParametricMultivariateDistributionModel baseModel = (ParametricMultivariateDistributionModel) xo.getChild(ParametricMultivariateDistributionModel.class);
    Parameter precisionParameter = (Parameter) xo.getElementFirstChild(PRECISION);
    CompoundParameter uniquelyRealizedParameters = (CompoundParameter) xo.getChild(CompoundParameter.class);
    Parameter categoriesParameter = (Parameter) xo.getElementFirstChild(DirichletProcessPriorParser.CATEGORIES);
    return new DirichletProcessPriorLogger(precisionParameter, categoriesParameter, uniquelyRealizedParameters);
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter)

Example 15 with CompoundParameter

use of dr.inference.model.CompoundParameter in project beast-mcmc by beast-dev.

the class DirichletProcessPriorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter categoriesParameter = (Parameter) xo.getElementFirstChild(CATEGORIES);
    CompoundParameter uniquelyRealizedParameters = (CompoundParameter) xo.getChild(CompoundParameter.class);
    ParametricMultivariateDistributionModel baseModel = (ParametricMultivariateDistributionModel) xo.getElementFirstChild(BASE_MODEL);
    Parameter gamma = (Parameter) xo.getElementFirstChild(CONCENTRATION);
    return new //
    DirichletProcessPrior(//
    categoriesParameter, //
    uniquelyRealizedParameters, //
    baseModel, gamma);
}
Also used : CompoundParameter(dr.inference.model.CompoundParameter) ParametricMultivariateDistributionModel(dr.inference.distribution.ParametricMultivariateDistributionModel) CompoundParameter(dr.inference.model.CompoundParameter) Parameter(dr.inference.model.Parameter)

Aggregations

CompoundParameter (dr.inference.model.CompoundParameter)17 Parameter (dr.inference.model.Parameter)14 TreeModel (dr.evomodel.tree.TreeModel)4 NodeRef (dr.evolution.tree.NodeRef)2 Tree (dr.evolution.tree.Tree)2 Taxon (dr.evolution.util.Taxon)2 TaxonList (dr.evolution.util.TaxonList)2 ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)2 Likelihood (dr.inference.model.Likelihood)2 OperatorSchedule (dr.inference.operators.OperatorSchedule)2 SimpleOperatorSchedule (dr.inference.operators.SimpleOperatorSchedule)2 ArrayList (java.util.ArrayList)2 TreeTraitProvider (dr.evolution.tree.TreeTraitProvider)1 ARGLogger (dr.evomodel.arg.ARGLogger)1 ARGReassortmentNodeCountStatistic (dr.evomodel.arg.ARGReassortmentNodeCountStatistic)1 ARGUniformPrior (dr.evomodel.arg.coalescent.ARGUniformPrior)1 EpochBranchModel (dr.evomodel.branchmodel.EpochBranchModel)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)1 MultivariateDiffusionModel (dr.evomodel.continuous.MultivariateDiffusionModel)1