Debian Codegraph @

src/dr/evomodelxml/coalescent/operators/GaussianProcessSkytrackBlockUpdateOperatorParser.java

raw symbols SCIP
1 /*
2 * GaussianProcessSkytrackBlockUpdateOperatorParser.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.GaussianProcessSkytrackBlockUpdateOperator;
30 import dr.inference.operators.AdaptableMCMCOperator;
31 import dr.inference.operators.AdaptationMode;
32 import dr.inference.operators.MCMCOperator;
33 import dr.math.MathUtils;
34 import dr.xml.*;
35
36 import java.io.IOException;
37 import java.util.logging.*;
38
39 /**
40 *
41 */
42 public class GaussianProcessSkytrackBlockUpdateOperatorParser extends AbstractXMLObjectParser {
43
44 public static final String BLOCK_UPDATE_OPERATOR = "gpBlockUpdateOperator";
45 public static final String SCALE_FACTOR = "scaleFactor";
46 public static final String MAX_ITERATIONS = "maxIterations";
47 public static final String STOP_VALUE = "stopValue";
48 public static final String KEEP_LOG_RECORD = "keepLogRecord";
49 public static final String OLD_SKYRIDE = "oldSkyride";
50
51 public String getParserName() {
52 return BLOCK_UPDATE_OPERATOR;
53 }
54
55 public Object parseXMLObject(XMLObject xo) throws XMLParseException {
56
57 boolean logRecord = xo.getAttribute(KEEP_LOG_RECORD, false);
58
59 Handler gmrfHandler;
60 Logger gmrfLogger = Logger.getLogger("dr.evomodel.coalescent.operators.GaussianProcessSkytrackBlockUpdateOperator");
61 gmrfLogger.setUseParentHandlers(false);
62
63 if (logRecord) {
64 gmrfLogger.setLevel(Level.FINE);
65
66 try {
67 gmrfHandler = new FileHandler("GPBlockUpdate.log." + MathUtils.getSeed());
68 } catch (IOException e) {
69 throw new RuntimeException(e.getMessage());
70 }
71 gmrfHandler.setLevel(Level.FINE);
72
73 gmrfHandler.setFormatter(new XMLFormatter() {
74 public String format(LogRecord record) {
75 return "<record>\n \t<message>\n\t" + record.getMessage()
76 + "\n\t</message>\n<record>\n";
77 }
78 });
79
80 gmrfLogger.addHandler(gmrfHandler);
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
101 if (xo.getAttribute(OLD_SKYRIDE, true)) {
102
103 GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
104
105 return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor,
106 maxIterations, stopValue);
107 }else{
108
109 GaussianProcessSkytrackLikelihood gpLikelihood = (GaussianProcessSkytrackLikelihood) xo.getChild(GaussianProcessSkytrackLikelihood.class);
110 return new GaussianProcessSkytrackBlockUpdateOperator(gpLikelihood, weight, mode, scaleFactor,
111 maxIterations, stopValue);
112 }
113
114 }
115
116 //************************************************************************
117 // AbstractXMLObjectParser implementation
118 //************************************************************************
119
120
121 public String getParserDescription() {
122 return "This element returns a GP block-update operator for the joint distribution of the population sizes and precision parameter.";
123 }
124
125 public Class getReturnType() {
126 return GaussianProcessSkytrackBlockUpdateOperator.class;
127 // return MCMCOperator.class;
128 }
129
130 public XMLSyntaxRule[] getSyntaxRules() {
131 return rules;
132 }
133
134 private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
135 AttributeRule.newDoubleRule(SCALE_FACTOR),
136 AttributeRule.newDoubleRule(MCMCOperator.WEIGHT),
137 AttributeRule.newBooleanRule(AdaptableMCMCOperator.AUTO_OPTIMIZE, true),
138 AttributeRule.newDoubleRule(STOP_VALUE, true),
139 AttributeRule.newIntegerRule(MAX_ITERATIONS, true),
140 AttributeRule.newBooleanRule(OLD_SKYRIDE, true),
141 new ElementRule(GaussianProcessSkytrackLikelihood.class)
142 };
143
144 }