Search in sources :

Example 1 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class EllipticalSliceOperator method main.

public static void main(String[] arg) {
    // Define normal model
    // Starting values
    Parameter thetaParameter = new Parameter.Default(new double[] { 1.0, 0.0 });
    MaskedParameter meanParameter = new MaskedParameter(thetaParameter, new Parameter.Default(new double[] { 1.0, 0.0 }), true);
    TransformedParameter precParameter = new TransformedParameter(new MaskedParameter(thetaParameter, new Parameter.Default(new double[] { 0.0, 1.0 }), true), new Transform.LogTransform(), true);
    //        System.err.println(thetaParameter);
    //        System.err.println(meanParameter);
    //        System.err.println(precParameter);
    ParametricDistributionModel densityModel = new NormalDistributionModel(meanParameter, precParameter, true);
    DistributionLikelihood likelihood = new DistributionLikelihood(densityModel);
    // Define prior
    MultivariateNormalDistribution priorDistribution = new MultivariateNormalDistribution(new double[] { 0.0, 0.0 }, new double[][] { { 0.001, 0.0 }, { 0.0, 0.001 } });
    MultivariateDistributionLikelihood prior = new MultivariateDistributionLikelihood(priorDistribution);
    prior.addData(thetaParameter);
    // Define data
    //        likelihood.addData(new Attribute.Default<double[]>("Data", new double[] {0.0, 2.0, 4.0}));
    likelihood.addData(new Attribute.Default<double[]>("Data", new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
    List<Likelihood> list = new ArrayList<Likelihood>();
    list.add(likelihood);
    list.add(prior);
    CompoundLikelihood posterior = new CompoundLikelihood(0, list);
    EllipticalSliceOperator sliceSampler = new EllipticalSliceOperator(thetaParameter, priorDistribution, false, true);
    final int dim = thetaParameter.getDimension();
    final int length = 100000;
    double[] mean = new double[dim];
    double[] variance = new double[dim];
    Parameter[] log = new Parameter[dim];
    log[0] = meanParameter;
    log[1] = precParameter;
    for (int i = 0; i < length; i++) {
        sliceSampler.doOperation(posterior);
        for (int j = 0; j < dim; ++j) {
            double x = log[j].getValue(0);
            mean[j] += x;
            variance[j] += x * x;
        }
    }
    for (int j = 0; j < dim; ++j) {
        mean[j] /= length;
        variance[j] /= length;
        variance[j] -= mean[j] * mean[j];
    }
    System.out.println("E(x)\tStErr(x)");
    for (int j = 0; j < dim; ++j) {
        System.out.println(mean[j] + " " + Math.sqrt(variance[j]));
    }
}
Also used : MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) Attribute(dr.util.Attribute) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood) ArrayList(java.util.ArrayList) MultivariateNormalDistribution(dr.math.distributions.MultivariateNormalDistribution) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) NormalDistributionModel(dr.inference.distribution.NormalDistributionModel) Transform(dr.util.Transform) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) MultivariateDistributionLikelihood(dr.inference.distribution.MultivariateDistributionLikelihood)

Example 2 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class SliceOperator method main.

public static void main(String[] arg) {
    // Define normal model
    // Starting value
    Parameter meanParameter = new Parameter.Default(1.0);
    // Fixed value
    Variable<Double> stdev = new Variable.D(1.0, 1);
    ParametricDistributionModel densityModel = new NormalDistributionModel(meanParameter, stdev);
    DistributionLikelihood likelihood = new DistributionLikelihood(densityModel);
    // Define prior
    // Hyper-priors
    DistributionLikelihood prior = new DistributionLikelihood(new NormalDistribution(0.0, 1.0));
    prior.addData(meanParameter);
    // Define data
    likelihood.addData(new Attribute.Default<double[]>("Data", new double[] { 0.0, 1.0, 2.0 }));
    List<Likelihood> list = new ArrayList<Likelihood>();
    list.add(likelihood);
    list.add(prior);
    CompoundLikelihood posterior = new CompoundLikelihood(0, list);
    SliceOperator sliceSampler = new SliceOperator(meanParameter);
    final int length = 10000;
    double mean = 0;
    double variance = 0;
    for (int i = 0; i < length; i++) {
        sliceSampler.doOperation(posterior);
        double x = meanParameter.getValue(0);
        mean += x;
        variance += x * x;
    }
    mean /= length;
    variance /= length;
    variance -= mean * mean;
    System.out.println("E(x) = " + mean);
    System.out.println("V(x) = " + variance);
}
Also used : Attribute(dr.util.Attribute) CompoundLikelihood(dr.inference.model.CompoundLikelihood) Likelihood(dr.inference.model.Likelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) CompoundLikelihood(dr.inference.model.CompoundLikelihood) ArrayList(java.util.ArrayList) NormalDistribution(dr.math.distributions.NormalDistribution) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) NormalDistributionModel(dr.inference.distribution.NormalDistributionModel) Parameter(dr.inference.model.Parameter) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood)

Example 3 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class SampleNonActiveGibbsOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    XMLObject cxo = xo.getChild(DISTRIBUTION);
    ParametricDistributionModel distribution = (ParametricDistributionModel) cxo.getChild(ParametricDistributionModel.class);
    cxo = xo.getChild(DATA_PARAMETER);
    Parameter data = (Parameter) cxo.getChild(Parameter.class);
    cxo = xo.getChild(INDICATOR_PARAMETER);
    Parameter indicators = (Parameter) cxo.getChild(Parameter.class);
    return new SampleNonActiveGibbsOperator(distribution, data, indicators, weight);
}
Also used : SampleNonActiveGibbsOperator(dr.evomodel.coalescent.operators.SampleNonActiveGibbsOperator) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) Parameter(dr.inference.model.Parameter)

Example 4 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class RandomWalkModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter data = (Parameter) xo.getChild(Parameter.class);
    ParametricDistributionModel distribution = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class);
    boolean logScale = false;
    if (xo.hasAttribute(LOG_SCALE))
        logScale = xo.getBooleanAttribute(LOG_SCALE);
    return new RandomWalkModel(distribution, data, false, logScale);
}
Also used : RandomWalkModel(dr.inference.distribution.RandomWalkModel) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) Parameter(dr.inference.model.Parameter)

Example 5 with ParametricDistributionModel

use of dr.inference.distribution.ParametricDistributionModel in project beast-mcmc by beast-dev.

the class OrnsteinUhlenbeckPriorLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    Parameter mean = getParam(xo, MEAN);
    Parameter sigma = getParam(xo, SIGMA);
    Parameter lambda = getParam(xo, LAMBDA);
    final boolean logSpace = xo.getAttribute(LOG_SPACE, false);
    final boolean normalize = xo.getAttribute(NORMALIZE, false);
    VariableDemographicModel m = (VariableDemographicModel) xo.getChild(VariableDemographicModel.class);
    if (m != null) {
        ParametricDistributionModel popMeanPrior = (ParametricDistributionModel) xo.getChild(ParametricDistributionModel.class);
        return new OrnsteinUhlenbeckPriorLikelihood(mean, sigma, lambda, m, logSpace, normalize, popMeanPrior);
    }
    final XMLObject cxo1 = xo.getChild(DATA);
    Parameter dataParameter = (Parameter) cxo1.getChild(Parameter.class);
    final XMLObject cxo2 = xo.getChild(TIMES);
    final Parameter timesParameter = (Parameter) cxo2.getChild(Parameter.class);
    return new OrnsteinUhlenbeckPriorLikelihood(mean, sigma, lambda, dataParameter, timesParameter, logSpace, normalize);
}
Also used : OrnsteinUhlenbeckPriorLikelihood(dr.evomodel.coalescent.OrnsteinUhlenbeckPriorLikelihood) VariableDemographicModel(dr.evomodel.coalescent.VariableDemographicModel) ParametricDistributionModel(dr.inference.distribution.ParametricDistributionModel) Parameter(dr.inference.model.Parameter)

Aggregations

ParametricDistributionModel (dr.inference.distribution.ParametricDistributionModel)21 Parameter (dr.inference.model.Parameter)16 ArrayList (java.util.ArrayList)4 TreeModel (dr.evomodel.tree.TreeModel)3 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)3 DiscretizedBranchRates (dr.evomodel.branchratemodel.DiscretizedBranchRates)2 VariableDemographicModel (dr.evomodel.coalescent.VariableDemographicModel)2 SpeciesTreeModel (dr.evomodel.speciation.SpeciesTreeModel)2 NormalDistributionModel (dr.inference.distribution.NormalDistributionModel)2 CompoundParameter (dr.inference.model.CompoundParameter)2 Statistic (dr.inference.model.Statistic)2 Attribute (dr.util.Attribute)2 SimpleTree (dr.evolution.tree.SimpleTree)1 Tree (dr.evolution.tree.Tree)1 Taxa (dr.evolution.util.Taxa)1 Taxon (dr.evolution.util.Taxon)1 TaxonList (dr.evolution.util.TaxonList)1 Units (dr.evolution.util.Units)1 AlloppNetworkPriorModel (dr.evomodel.alloppnet.speciation.AlloppNetworkPriorModel)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1