src/dr/evomodelxml/coalescent/operators/GaussianProcessSkytrackTreeOperatorParser.java
raw symbols SCIP| 1 | /* |
| 2 | * GaussianProcessSkytrackTreeOperatorParser.java |
| 3 | * |
| 4 | * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard |
| 5 | * |
| 6 | * This file is part of BEAST. |
| 7 | * See the NOTICE file distributed with this work for additional |
| 8 | * information regarding copyright ownership and licensing. |
| 9 | * |
| 10 | * BEAST is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Lesser General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 |
| 13 | * of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * BEAST is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with BEAST; if not, write to the |
| 22 | * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
| 23 | * Boston, MA 02110-1301 USA |
| 24 | */ |
| 25 | |
| 26 | package dr.evomodelxml.coalescent.operators; |
| 27 | |
| 28 | import dr.evomodel.coalescent.GaussianProcessSkytrackLikelihood; |
| 29 | import dr.evomodel.coalescent.operators.GaussianProcessSkytrackTreeOperator; |
| 30 | import dr.evomodel.tree.TreeModel; |
| 31 | import dr.inference.operators.AdaptableMCMCOperator; |
| 32 | import dr.inference.operators.AdaptationMode; |
| 33 | import dr.inference.operators.MCMCOperator; |
| 34 | import dr.xml.*; |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | */ |
| 39 | public class GaussianProcessSkytrackTreeOperatorParser extends AbstractXMLObjectParser { |
| 40 | |
| 41 | public static final String BLOCK_UPDATE_OPERATOR = "gpTreeOperator"; |
| 42 | public static final String SCALE_FACTOR = "scaleFactor"; |
| 43 | // public static final String MAX_ITERATIONS = "maxIterations"; |
| 44 | // public static final String STOP_VALUE = "stopValue"; |
| 45 | // public static final String KEEP_LOG_RECORD = "keepLogRecord"; |
| 46 | // public static final String OLD_SKYRIDE = "oldSkyride"; |
| 47 | |
| 48 | public String getParserName() { |
| 49 | return BLOCK_UPDATE_OPERATOR; |
| 50 | } |
| 51 | |
| 52 | public Object parseXMLObject(XMLObject xo) throws XMLParseException { |
| 53 | |
| 54 | // boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false); |
| 55 | |
| 56 | // Handler gmrfHandler; |
| 57 | // Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator"); |
| 58 | // gmrfLogger.setUseParentHandlers(false); |
| 59 | |
| 60 | // if (logRecord) { |
| 61 | // gmrfLogger.setLevel(Level.FINE); |
| 62 | // |
| 63 | // try { |
| 64 | // gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed()); |
| 65 | // } catch (IOException e) { |
| 66 | // throw new RuntimeException(e.getMessage()); |
| 67 | // } |
| 68 | // gmrfHandler.setLevel(Level.FINE); |
| 69 | // |
| 70 | // gmrfHandler.setFormatter(new XMLFormatter() { |
| 71 | // public String format(LogRecord record) { |
| 72 | // return "<record>\n \t<message>\n\t" + record.getMessage() |
| 73 | // + "\n\t</message>\n<record>\n"; |
| 74 | // } |
| 75 | // }); |
| 76 | // |
| 77 | // gmrfLogger.addHandler(gmrfHandler); |
| 78 | // } |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | AdaptationMode mode = AdaptationMode.parseMode(xo); |
| 84 | if (mode == AdaptationMode.DEFAULT) mode = AdaptationMode.ADAPTATION_ON; |
| 85 | |
| 86 | double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT); |
| 87 | double scaleFactor = xo.getDoubleAttribute(SCALE_FACTOR); |
| 88 | |
| 89 | |
| 90 | // if (scaleFactor <= 0.0) { |
| 91 | // throw new XMLParseException("scaleFactor must be greater than 0.0"); |
| 92 | // if (scaleFactor < 1.0) { |
| 93 | // throw new XMLParseException("scaleFactor must be greater than or equal to 1.0"); |
| 94 | // } |
| 95 | |
| 96 | // int maxIterations = xo.getAttribute(MAX_ITERATIONS, 200); |
| 97 | |
| 98 | // double stopValue = xo.getAttribute(STOP_VALUE, 0.01); |
| 99 | |
| 100 | GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class); |
| 101 | TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class); |
| 102 | return new GaussianProcessSkytrackTreeOperator(treeModel, gpLikelihood, weight, scaleFactor, mode); |
| 103 | |
| 104 | |
| 105 | |
| 106 | } |
| 107 | |
| 108 | //************************************************************************ |
| 109 | // AbstractXMLObjectParser implementation |
| 110 | //************************************************************************ |
| 111 | |
| 112 | |
| 113 | public String getParserDescription() { |
| 114 | return "This element returns a GP block-update operator for the joint distribution of the population sizes and precision parameter."; |
| 115 | } |
| 116 | |
| 117 | public Class getReturnType() { |
| 118 | return GaussianProcessSkytrackTreeOperator.class; |
| 119 | // return MCMCOperator.class; |
| 120 | } |
| 121 | |
| 122 | public XMLSyntaxRule[] getSyntaxRules() { |
| 123 | return rules; |
| 124 | } |
| 125 | |
| 126 | private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{ |
| 127 | AttributeRule.newDoubleRule(SCALE_FACTOR), |
| 128 | AttributeRule.newDoubleRule(MCMCOperator.WEIGHT), |
| 129 | AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true), |
| 130 | // AttributeRule.newDoubleRule(STOP_VALUE, true), |
| 131 | // AttributeRule.newIntegerRule(MAX_ITERATIONS, true), |
| 132 | // AttributeRule.newBooleanRule(OLD_SKYRIDE, true), |
| 133 | new ElementRule(GaussianProcessSkytrackLikelihood.class), |
| 134 | new ElementRule(TreeModel.class) |
| 135 | |
| 136 | }; |
| 137 | |
| 138 | } |