Revision: 6727
Author:
mdha...@gmail.com
Date: Tue Apr 7 10:03:54 2015 UTC
Log: Transmission tree logging fixed
https://code.google.com/p/beast-mcmc/source/detail?r=6727
Added:
/trunk/src/dr/evomodel/coalescent/AsymptoticGrowthModel.java
/trunk/src/dr/evomodelxml/coalescent/AsymptoticGrowthModelParser.java
Modified:
/trunk/src/dr/app/beast/development_parsers.properties
/trunk/src/dr/evolution/coalescent/FlexibleGrowth.java
/trunk/src/dr/evolution/coalescent/PowerLawGrowth.java
/trunk/src/dr/evomodel/coalescent/PeakAndDeclineModel.java
/trunk/src/dr/evomodel/epidemiology/casetocase/CaseToCaseTreeLikelihood.java
=======================================
--- /dev/null
+++ /trunk/src/dr/evomodel/coalescent/AsymptoticGrowthModel.java Tue Apr 7
10:03:54 2015 UTC
@@ -0,0 +1,105 @@
+/*
+ * LogisticGrowthModel.java
+ *
+ * Copyright (C) 2002-2009 Alexei Drummond and Andrew Rambaut
+ *
+ * This file is part of BEAST.
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership and licensing.
+ *
+ * BEAST is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * BEAST is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with BEAST; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301 USA
+ */
+
+package dr.evomodel.coalescent;
+
+import dr.evolution.coalescent.DemographicFunction;
+import dr.evolution.coalescent.FlexibleGrowth;
+import dr.evomodelxml.coalescent.AsymptoticGrowthModelParser;
+import dr.evomodelxml.coalescent.LogisticGrowthModelParser;
+import dr.inference.model.Parameter;
+
+/**
+ * Growth starts at zero at time zero, peaks and declines
+ *
+ */
+public class AsymptoticGrowthModel extends DemographicModel {
+
+ //
+ // Public stuff
+ //
+
+ /**
+ * Construct demographic model with default settings
+ */
+ public AsymptoticGrowthModel(Parameter asymptoteValueParameter,
Parameter shapeParameter, Type units) {
+
+ this(AsymptoticGrowthModelParser.ASYMPTOTIC_GROWTH_MODEL,
asymptoteValueParameter, shapeParameter, units);
+ }
+
+ /**
+ * Construct demographic model with default settings
+ */
+ public AsymptoticGrowthModel(String name, Parameter
asymptoteValueParameter, Parameter shapeParameter,
+ Type units) {
+
+ super(name);
+
+ flexibleGrowth = new FlexibleGrowth(units);
+
+ this.asyptoteValue = asymptoteValueParameter;
+ addVariable(asymptoteValueParameter);
+ asymptoteValueParameter.addBounds(new
Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0.0, 1));
+
+
+ this.shapeParameter = shapeParameter;
+ addVariable(shapeParameter);
+ shapeParameter.addBounds(new
Parameter.DefaultBounds(Double.POSITIVE_INFINITY, 0, 1));
+
+
+ setUnits(units);
+ }
+
+
+ // general functions
+
+ public DemographicFunction getDemographicFunction() {
+
+ double asymptoteValue = asyptoteValue.getParameterValue(0);
+ double shapeValue = shapeParameter.getParameterValue(0);
+
+
+
+ double flexibleN0 = asymptoteValue/shapeValue;
+
+
+ flexibleGrowth.setN0(flexibleN0);
+ flexibleGrowth.setK(shapeValue);
+ flexibleGrowth.setR(0);
+
+
+
+ return flexibleGrowth;
+ }
+
+ //
+ // protected stuff
+ //
+
+ Parameter asyptoteValue = null;
+ Parameter shapeParameter = null;
+ FlexibleGrowth flexibleGrowth = null;
+
+}
=======================================
--- /dev/null
+++ /trunk/src/dr/evomodelxml/coalescent/AsymptoticGrowthModelParser.java
Tue Apr 7 10:03:54 2015 UTC
@@ -0,0 +1,67 @@
+package dr.evomodelxml.coalescent;
+
+import dr.evolution.util.Units;
+import dr.evomodel.coalescent.AsymptoticGrowthModel;
+import dr.evomodel.coalescent.LogisticGrowthModel;
+import dr.evomodel.coalescent.PeakAndDeclineModel;
+import dr.evoxml.util.XMLUnits;
+import dr.inference.model.Parameter;
+import dr.xml.*;
+
+/**
+ * Parses an element from an XMLObject into LogisticGrowthModel.
+ */
+public class AsymptoticGrowthModelParser extends AbstractXMLObjectParser {
+
+ public static String ASYMPTOTE_VALUE = "asymptoteValue";
+ public static String ASYMPTOTIC_GROWTH_MODEL = "asymptoticGrowth";
+
+ public static String SHAPE = "shape";
+
+ public String getParserName() {
+ return ASYMPTOTIC_GROWTH_MODEL;
+ }
+
+ public Object parseXMLObject(XMLObject xo) throws XMLParseException {
+
+ Units.Type units = XMLUnits.Utils.getUnitsAttr(xo);
+
+ XMLObject cxo = xo.getChild(ASYMPTOTE_VALUE);
+ Parameter asymptoticValueParam = (Parameter)
cxo.getChild(Parameter.class);
+
+
+ Parameter rParam;
+
+ cxo = xo.getChild(SHAPE);
+ Parameter shapeParam = (Parameter) cxo.getChild(Parameter.class);
+
+
+ return new AsymptoticGrowthModel(asymptoticValueParam, shapeParam,
units);
+ }
+
+
//************************************************************************
+ // AbstractXMLObjectParser implementation
+
//************************************************************************
+
+ public String getParserDescription() {
+ return "Logistic growth demographic model.";
+ }
+
+ public Class getReturnType() {
+ return LogisticGrowthModel.class;
+ }
+
+ public XMLSyntaxRule[] getSyntaxRules() {
+ return rules;
+ }
+
+ private XMLSyntaxRule[] rules = new XMLSyntaxRule[]{
+ XMLUnits.SYNTAX_RULES[0],
+ new ElementRule(ASYMPTOTE_VALUE,
+ new XMLSyntaxRule[]{new ElementRule(Parameter.class)}),
+
+
+ new ElementRule(SHAPE,
+ new XMLSyntaxRule[]{new
ElementRule(Parameter.class)}),
+ };
+}
=======================================
--- /trunk/src/dr/app/beast/development_parsers.properties Thu Apr 2
15:11:48 2015 UTC
+++ /trunk/src/dr/app/beast/development_parsers.properties Tue Apr 7
10:03:54 2015 UTC
@@ -152,6 +152,8 @@
dr.evomodelxml.coalescent.LinearGrowthModelParser
dr.evomodelxml.coalescent.PowerLawGrowthModelParser
dr.evomodelxml.coalescent.PeakAndDeclineModelParser
+dr.evomodelxml.coalescent.AsymptoticGrowthModelParser
+
# UNIFORM INTERNAL NODE HEIGHT PRIOR
dr.evomodelxml.operators.FunkyPriorMixerOperatorParser
=======================================
--- /trunk/src/dr/evolution/coalescent/FlexibleGrowth.java Thu Apr 2
15:11:48 2015 UTC
+++ /trunk/src/dr/evolution/coalescent/FlexibleGrowth.java Tue Apr 7
10:03:54 2015 UTC
@@ -60,20 +60,20 @@
}
- public void setK(double r) {
- if(r<=1){
- throw new RuntimeException("PowerLawGrowth requires r>1");
- }
+ public void setK(double K) {
- this.K = r;
+ this.K = K;
}
-
- // Implementation of abstract methods
+
+
+
+
+ // Implementation of abstract methods
public double getDemographic(double t) {
if(t>0){
- throw new RuntimeException("Negative times only!");
+ throw new RuntimeException("Negative times only! t="+t);
}
return getN0()*K*Math.pow(-t,getR())/(1+K*Math.pow(-t, getR()-1));
@@ -142,9 +142,9 @@
public double getLowerBound(int n) {
switch (n) {
case 0:
+ return 0;
+ case 1:
return Double.NEGATIVE_INFINITY;
- case 1:
- return 0;
case 2:
return 0;
default:
=======================================
--- /trunk/src/dr/evolution/coalescent/PowerLawGrowth.java Thu Apr 2
15:11:48 2015 UTC
+++ /trunk/src/dr/evolution/coalescent/PowerLawGrowth.java Tue Apr 7
10:03:54 2015 UTC
@@ -57,9 +57,7 @@
public void setR(double r) {
- if(r<=1){
- throw new RuntimeException("PowerLawGrowth requires r>1");
- }
+
this.r = r;
}
=======================================
--- /trunk/src/dr/evomodel/coalescent/PeakAndDeclineModel.java Thu Apr 2
15:11:48 2015 UTC
+++ /trunk/src/dr/evomodel/coalescent/PeakAndDeclineModel.java Tue Apr 7
10:03:54 2015 UTC
@@ -29,14 +29,12 @@
import dr.evolution.coalescent.FlexibleGrowth;
import dr.evolution.coalescent.LogisticGrowth;
import dr.evomodelxml.coalescent.LogisticGrowthModelParser;
+import dr.evomodelxml.coalescent.PeakAndDeclineModelParser;
import dr.inference.model.Parameter;
/**
- * Logistic growth.
+ * Growth starts at zero at time zero, peaks and declines
*
- * @author Alexei Drummond
- * @author Andrew Rambaut
- * @version $Id: LogisticGrowthModel.java,v 1.21 2005/05/24 20:25:57
rambaut Exp $
*/
public class PeakAndDeclineModel extends DemographicModel {
@@ -50,14 +48,15 @@
public PeakAndDeclineModel(Parameter peakValueParameter, Parameter
shapeParameter, Parameter peakTimeParameter,
Type units) {
- this(LogisticGrowthModelParser.LOGISTIC_GROWTH_MODEL,
peakValueParameter, shapeParameter, peakTimeParameter, units);
+ this(PeakAndDeclineModelParser.PEAK_AND_DECLINE_MODEL,
peakValueParameter, shapeParameter, peakTimeParameter,
+ units);
}
/**
* Construct demographic model with default settings
*/
- public PeakAndDeclineModel(String name, Parameter peakValueParameter,
Parameter shapeParameter, Parameter peakTimeParameter,
- Type units) {
+ public PeakAndDeclineModel(String name, Parameter peakValueParameter,
Parameter shapeParameter,
+ Parameter peakTimeParameter, Type units) {
super(name);
=======================================
---
/trunk/src/dr/evomodel/epidemiology/casetocase/CaseToCaseTreeLikelihood.java
Wed Dec 17 11:55:20 2014 UTC
+++
/trunk/src/dr/evomodel/epidemiology/casetocase/CaseToCaseTreeLikelihood.java
Tue Apr 7 10:03:54 2015 UTC
@@ -34,6 +34,9 @@
import dr.util.Author;
import dr.util.Citable;
import dr.util.Citation;
+import org.apache.commons.math.stat.descriptive.moment.Mean;
+import org.apache.commons.math.stat.descriptive.moment.Variance;
+import org.apache.commons.math.stat.descriptive.rank.Median;
/**
* Handles manipulation of the tree partition, and likelihood of the
infection times.
@@ -989,14 +992,14 @@
primitiveVariable[i] = variable[i];
}
- DescriptiveStatistics stats = new
DescriptiveStatistics(primitiveVariable);
Double[] out = new Double[4];
- out[0] = stats.getMean();
- out[1] = stats.getPercentile(50);
- out[2] = stats.getVariance();
- out[3] = stats.getStandardDeviation();
+ out[0] = (new Mean()).evaluate(primitiveVariable);
+ out[1] = (new Median()).evaluate(primitiveVariable);
+ out[2] = (new Variance()).evaluate(primitiveVariable);
+ out[3] = Math.sqrt(out[2]);
return out;
}
+