Search in sources :

Example 1 with GaussianProcessSkytrackLikelihood

use of dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood in project beast-mcmc by beast-dev.

the class GaussianProcessSkytrackBlockUpdateOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false);
    Handler gmrfHandler;
    Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator");
    gmrfLogger.setUseParentHandlers(false);
    if (logRecord) {
        gmrfLogger.setLevel(Level.FINE);
        try {
            gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed());
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage());
        }
        gmrfHandler.setLevel(Level.FINE);
        gmrfHandler.setFormatter(new XMLFormatter() {

            public String format(LogRecord record) {
                return "<record>\n \t<message>\n\t" + record.getMessage() + "\n\t</message>\n<record>\n";
            }
        });
        gmrfLogger.addHandler(gmrfHandler);
    }
    CoercionMode mode = CoercionMode.parseMode(xo);
    if (mode == CoercionMode.DEFAULT)
        mode = CoercionMode.COERCION_ON;
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    //                throw new XMLParseException("scaleFactor must be greater than 0.0");
    if (scaleFactor < 1.0) {
        throw new XMLParseException("scaleFactor must be greater than or equal to 1.0");
    }
    int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200);
    double stopValue = xo.getAttribute(STOP_VALUE, 0.01);
    if (xo.getAttribute(OLD_SKYRIDE, true)) {
        GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
        return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
    } else {
        GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
        return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor, maxIterations, stopValue);
    }
}
Also used : IOException(java.io.IOException) GaussianProcessSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood) GaussianProcessSkytrackBlockUpdateOperator(dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator) CoercionMode(dr.inference.operators.CoercionMode)

Example 2 with GaussianProcessSkytrackLikelihood

use of dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood in project beast-mcmc by beast-dev.

the class GaussianProcessSkytrackLikelihoodParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    XMLObject cxo = xo.getChild(POPULATION_PARAMETER);
    Parameter popParameter = (Parameter) cxo.getChild(Parameter.class);
    cxo = xo.getChild(PRECISION_PARAMETER);
    Parameter precParameter = (Parameter) cxo.getChild(Parameter.class);
    //        cxo = xo.getChild(LAMBDA_BOUND_PARAMETER);
    //        Parameter lambda_bound = (Parameter) cxo.getChild(Parameter.class);
    //
    //        cxo = xo.getChild(LAMBDA_PARAMETER);
    //        Parameter lambda_parameter = (Parameter) cxo.getChild(Parameter.class);
    cxo = xo.getChild(POPULATION_TREE);
    List<Tree> treeList = new ArrayList<Tree>();
    for (int i = 0; i < cxo.getChildCount(); i++) {
        Object testObject = cxo.getChild(i);
        if (testObject instanceof Tree) {
            treeList.add((TreeModel) testObject);
        }
    }
    //        TreeModel treeModel = (TreeModel) cxo.getChild(TreeModel.class);
    //        cxo = xo.getChild(GROUP_SIZES);
    //        Parameter groupParameter = null;
    //        if (cxo != null) {
    //            groupParameter = (Parameter) cxo.getChild(Parameter.class);
    //
    //            if (popParameter.getDimension() != groupParameter.getDimension())
    //                throw new XMLParseException("Population and group size parameters must have the same length");
    //        }
    Parameter lambda_parameter;
    if (xo.getChild(LAMBDA_PARAMETER) != null) {
        cxo = xo.getChild(LAMBDA_PARAMETER);
        lambda_parameter = (Parameter) cxo.getChild(Parameter.class);
    } else {
        lambda_parameter = new Parameter.Default(1.0);
    }
    Parameter GPtype;
    if (xo.getChild(GPTYPE) != null) {
        cxo = xo.getChild(GPTYPE);
        GPtype = (Parameter) cxo.getChild(Parameter.class);
    } else {
        GPtype = new Parameter.Default(1.0);
    }
    Parameter Tmrca;
    if (xo.getChild(TMRCA) != null) {
        cxo = xo.getChild(TMRCA);
        Tmrca = (Parameter) cxo.getChild(Parameter.class);
    } else {
        Tmrca = new Parameter.Default(1.0);
    }
    Parameter numPoints;
    if (xo.getChild(NUMBER_POINTS) != null) {
        cxo = xo.getChild(NUMBER_POINTS);
        numPoints = (Parameter) cxo.getChild(Parameter.class);
    } else {
        numPoints = new Parameter.Default(1.0);
    }
    Parameter CoalCounts;
    if (xo.getChild(COALCOUNT) != null) {
        cxo = xo.getChild(COALCOUNT);
        CoalCounts = (Parameter) cxo.getChild(Parameter.class);
    } else {
        CoalCounts = new Parameter.Default(1.0);
    }
    Parameter GPcounts;
    if (xo.getChild(GPCOUNTS) != null) {
        cxo = xo.getChild(GPCOUNTS);
        GPcounts = (Parameter) cxo.getChild(Parameter.class);
    } else {
        GPcounts = new Parameter.Default(1.0);
    }
    Parameter coalfactor;
    if (xo.getChild(COALFACTOR) != null) {
        cxo = xo.getChild(COALFACTOR);
        coalfactor = (Parameter) cxo.getChild(Parameter.class);
    } else {
        coalfactor = new Parameter.Default(1.0);
    }
    Parameter lambda_bound;
    if (xo.getChild(LAMBDA_BOUND_PARAMETER) != null) {
        cxo = xo.getChild(LAMBDA_BOUND_PARAMETER);
        lambda_bound = (Parameter) cxo.getChild(Parameter.class);
    } else {
        lambda_bound = new Parameter.Default(1.0);
    }
    Parameter alpha_parameter;
    if (xo.getChild(ALPHA_PARAMETER) != null) {
        cxo = xo.getChild(ALPHA_PARAMETER);
        alpha_parameter = (Parameter) cxo.getChild(Parameter.class);
    } else {
        alpha_parameter = new Parameter.Default(0.001);
    }
    Parameter beta_parameter;
    if (xo.getChild(BETA_PARAMETER) != null) {
        cxo = xo.getChild(BETA_PARAMETER);
        beta_parameter = (Parameter) cxo.getChild(Parameter.class);
    } else {
        beta_parameter = new Parameter.Default(0.001);
    }
    Parameter change_points;
    if (xo.getChild(CHANGE_POINTS) != null) {
        cxo = xo.getChild(CHANGE_POINTS);
        change_points = (Parameter) cxo.getChild(Parameter.class);
    } else {
        change_points = new Parameter.Default(0, 1);
    }
    if (xo.getAttribute(RANDOMIZE_TREE, false)) {
        for (Tree tree : treeList) {
            if (tree instanceof TreeModel) {
                GaussianProcessSkytrackLikelihood.checkTree((TreeModel) tree);
            } else {
                throw new XMLParseException("Can not randomize a fixed tree");
            }
        }
    }
    //        XMLObject latentChild = xo.getChild(LATENT_PARAMETER);
    //        Parameter latentPoints = (Parameter) latentChild.getChild(Parameter.class);
    boolean rescaleByRootHeight = xo.getAttribute(RESCALE_BY_ROOT_ISSUE, true);
    if (treeList.size() == 1) {
        return new GaussianProcessSkytrackLikelihood(treeList, precParameter, rescaleByRootHeight, lambda_bound, lambda_parameter, popParameter, alpha_parameter, beta_parameter, change_points, GPtype, GPcounts, coalfactor, CoalCounts, numPoints, Tmrca);
    } else {
        return new GaussianProcessMultilocusSkytrackLikelihood(treeList, precParameter, rescaleByRootHeight, lambda_bound, lambda_parameter, popParameter, alpha_parameter, beta_parameter, change_points, GPtype, GPcounts, coalfactor, CoalCounts, numPoints, Tmrca);
    }
}
Also used : ArrayList(java.util.ArrayList) GaussianProcessMultilocusSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessMultilocusSkytrackLikelihood) TreeModel(dr.evomodel.tree.TreeModel) GaussianProcessSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood) Parameter(dr.inference.model.Parameter) Tree(dr.evolution.tree.Tree)

Example 3 with GaussianProcessSkytrackLikelihood

use of dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood in project beast-mcmc by beast-dev.

the class GaussianProcessSkytrackTreeOperatorParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    //        boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false);
    //        Handler gmrfHandler;
    //        Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator");
    //        gmrfLogger.setUseParentHandlers(false);
    //        if (logRecord) {
    //            gmrfLogger.setLevel(Level.FINE);
    //
    //            try {
    //                gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed());
    //            } catch (IOException e) {
    //                throw new RuntimeException(e.getMessage());
    //            }
    //            gmrfHandler.setLevel(Level.FINE);
    //
    //            gmrfHandler.setFormatter(new XMLFormatter() {
    //                public String format(LogRecord record) {
    //                    return "<record>\n \t<message>\n\t" + record.getMessage()
    //                            + "\n\t</message>\n<record>\n";
    //                }
    //            });
    //
    //            gmrfLogger.addHandler(gmrfHandler);
    //        }
    CoercionMode mode = CoercionMode.parseMode(xo);
    if (mode == CoercionMode.DEFAULT)
        mode = CoercionMode.COERCION_ON;
    double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
    double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR);
    //            if (scaleFactor <= 0.0) {
    //                throw new XMLParseException("scaleFactor must be greater than 0.0");
    //        if (scaleFactor < 1.0) {
    //            throw new XMLParseException("scaleFactor must be greater than or equal to 1.0");
    //        }
    //        int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200);
    //        double stopValue = xo.getAttribute(STOP_VALUE, 0.01);
    GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    return new GaussianProcessSkytrackTreeOperator(treeModel, gpLikelihood, weight, scaleFactor, mode);
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) GaussianProcessSkytrackTreeOperator(dr.evomodel.coalescent.operators.GaussianProcessSkytrackTreeOperator) GaussianProcessSkytrackLikelihood(dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood) CoercionMode(dr.inference.operators.CoercionMode)

Aggregations

GaussianProcessSkytrackLikelihood (dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood)3 TreeModel (dr.evomodel.tree.TreeModel)2 CoercionMode (dr.inference.operators.CoercionMode)2 Tree (dr.evolution.tree.Tree)1 GaussianProcessMultilocusSkytrackLikelihood (dr.evomodel.coalescent.GaussianProcessMultilocusSkytrackLikelihood)1 GaussianProcessSkytrackBlockUpdateOperator (dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator)1 GaussianProcessSkytrackTreeOperator (dr.evomodel.coalescent.operators.GaussianProcessSkytrackTreeOperator)1 Parameter (dr.inference.model.Parameter)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1