Skip to content

Commit

Permalink
update model test
Browse files Browse the repository at this point in the history
  • Loading branch information
higgs.ml committed Apr 2, 2015
1 parent 1221bef commit 43cfe75
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 60 deletions.
33 changes: 21 additions & 12 deletions examples/BEASTmodeltest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ name="alignment">
<parameter id="gammaShape.s:dna" name="stateNode">1.0</parameter>
<parameter id="proportionInvariant.s:dna" lower="0.0" name="stateNode" upper="1.0">0.1</parameter>

<stateNode id="hasInvariantSites.s:dna" spec="parameter.BooleanParameter">1</stateNode>
<stateNode id="hasGammaRates.s:dna" spec="parameter.BooleanParameter">1</stateNode>
<stateNode id="hasInvariantSites.s:dna" spec="parameter.IntegerParameter">1</stateNode>
<stateNode id="hasGammaRates.s:dna" spec="parameter.IntegerParameter">1</stateNode>
</state>

<init id="RandomTree.t:dna" spec="beast.evolution.tree.RandomTree" estimate="false" initial="@Tree.t:dna" taxa="@dna">
Expand All @@ -71,14 +71,17 @@ name="alignment">
<prior id="YuleBirthRatePrior.t:dna" name="distribution" x="@birthRate.t:dna">
<Uniform id="Uniform.0" name="distr" upper="Infinity"/>
</prior>
<distribution id="GammaShapePrior.s:dna" spec="beast.math.distributions.RBPrior" x="@gammaShape.s:dna" count='@hasGammaRates.s:dna'>

<distribution id="RBPropInvariantPrior.s:dna" spec="beast.math.distributions.RBPrior" x="@proportionInvariant.s:dna" count='@hasInvariantSites.s:dna'>
<Uniform id="Uniform.01" name="distr" lower="0" upper="1.0"/>
</distribution>

<distribution id="RBGammaShapePrior.s:dna" spec="beast.math.distributions.RBPrior" x="@gammaShape.s:dna" count='@hasGammaRates.s:dna'>
<Exponential id="Exponential.0" name="distr">
<parameter id="RealParameter.02" lower="0.0" name="mean" upper="0.0">1.0</parameter>
</Exponential>
</distribution>
<distribution id="PropInvariantPrior.s:dna" spec="beast.math.distributions.RBPrior" x="@proportionInvariant.s:dna" count='@hasInvariantSites.s:dna'>
<Exponential id="Uniform.01" name="distr" mean="1.0"/>
</distribution>

</distribution>
<distribution id="likelihood" spec="util.CompoundDistribution">
<distribution id="treeLikelihood.dna" spec="TreeLikelihood" data="@dna" tree="@Tree.t:dna">
Expand Down Expand Up @@ -114,16 +117,22 @@ name="alignment">
<operator id="WilsonBalding.t:dna" spec="WilsonBalding" tree="@Tree.t:dna" weight="3.0"/>

<operator id="RBOperator.s:dna" spec="RBOperator" count="@RBcount.s:dna" rates="@RBrates.s:dna" weight="1.0"/>

<operator id="RBratescaler.s:dna" spec="RBScaleOperator" count="@RBcount.s:dna" parameter="@RBrates.s:dna" scaleFactor="0.5" weight="1.0"/>

<operator id="gammaShapeScaler.s:dna" spec="ScaleOperator" parameter="@gammaShape.s:dna" scaleFactor="0.5" weight="0.1"/>
<operator id="proportionInvariantScaler.s:dna" spec="ScaleOperator" parameter="@proportionInvariant.s:dna" scaleFactor="0.5" weight="0.1"/>
<operator id="RBshapeOperator.s:dna" spec="RBOperator" count="@hasGammaRates.s:dna" rates="@gammaShape.s:dna" weight="1.0"/>
<operator id="RBshapecaler.s:dna" spec="RBScaleOperator" count="@hasGammaRates.s:dna" parameter="@gammaShape.s:dna" scaleFactor="0.5" weight="1.0"/>

<operator id="RBpinvOperator.s:dna" spec="RBOperator" count="@hasInvariantSites.s:dna" rates="@proportionInvariant.s:dna" weight="1.0"/>
<operator id="RBpInvscaler.s:dna" spec="RBScaleOperator" count="@hasInvariantSites.s:dna" parameter="@proportionInvariant.s:dna" scaleFactor="0.5" weight="1.0"/>


<!--
<operator id="gammaShapeScaler.s:dna" spec="ScaleOperator" parameter="@gammaShape.s:dna" scaleFactor="0.5" weight="0.1"/>
<operator id="hasGammaRatesFlipper.s:dna" spec="BitFlipOperator" parameter="@hasGammaRates.s:dna" weight="0.1"/>
<operator id="proportionInvariantScaler.s:dna" spec="ScaleOperator" parameter="@proportionInvariant.s:dna" scaleFactor="0.5" weight="0.1"/>
<operator id="hasInvariantSitesFlipper.s:dna" spec="BitFlipOperator" parameter="@hasInvariantSites.s:dna" weight="0.1"/>

-->

<logger id="tracelog" fileName="dna.log" logEvery="1000" model="@posterior" sanitiseHeaders="true" sort="smart">
<log idref="posterior"/>
Expand All @@ -150,8 +159,8 @@ name="alignment">
<log idref='hasGammaRates.s:dna'/>
<log idref='hasInvariantSites.s:dna'/>

<log idref="GammaShapePrior.s:dna"/>
<log idref="PropInvariantPrior.s:dna" />
<log idref="RBGammaShapePrior.s:dna"/>
<log idref="RBPropInvariantPrior.s:dna" />
</logger>

<logger id="screenlog" logEvery="1000">
Expand Down
19 changes: 11 additions & 8 deletions examples/prior.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,25 @@
<stateNode idref="rates"/>
</state>

<distribution spec='CompoundDistribution' id='prior'>
<distribution spec='beast.math.distributions.RBPrior' count='@count' x='@rates'>
<!--
<distr spec="beast.math.distributions.OneOnX"/>
<distr spec="beast.math.distributions.Gamma" alpha='0.0625' beta='16.0'/>
<distr spec="beast.math.distributions.Gamma" alpha='1' beta='1.0'/>
<distr spec="beast.math.distributions.Gamma" alpha='0.2' beta='0.2'/>
-->
<distr spec="beast.math.distributions.Gamma" alpha='0.5' beta='2'/>
</distribution>

<!--
<distribution spec='beast.math.distributions.Prior' x='@count'>
<distr spec='beast.math.distributions.Exponential' mean='2'/>
</distribution>
-->
<distribution spec='CompoundDistribution' id='prior'>
<!--
-->
<distribution spec='beast.math.distributions.RBPrior' count='@count' x='@rates'>
<distr spec='beast.math.distributions.Exponential' mean='1'/>
<!--
<distr spec="beast.math.distributions.Uniform" lower='0.0' upper='1'/>
-->
</distribution>

</distribution>

<operator id='RBOperator' spec='RBOperator' weight="1" rates="@rates" count='@count'/>
Expand All @@ -45,7 +48,7 @@
-->


<logger logEvery="1000" fileName="RB.$(seed).log" model='@prior'>
<logger logEvery="1000" fileName="RBprior.log" model='@prior'>
<log idref="prior"/>
<log idref='count'/>
<log idref='rates'/>
Expand Down
5 changes: 2 additions & 3 deletions src/beast/evolution/operators/RBOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import org.apache.commons.math.MathException;

import beast.core.BEASTObject;
import beast.core.Description;
import beast.core.Input;
import beast.core.Operator;
Expand Down Expand Up @@ -35,7 +34,7 @@ public class RBOperator extends Operator {
public void initAndValidate() throws Exception {
rates = rateInput.get();
distr = new Exponential();
for (BEASTObject plugin : rates.outputs) {
for (Object plugin : rates.getOutputs()) {
if (plugin instanceof RBPrior) {
RBPrior prior = (RBPrior) plugin;
distr = prior.distInput.get();
Expand All @@ -53,7 +52,7 @@ public double proposal() {

if (Randomizer.nextBoolean()) {
// increase nr of rates
if (count == 5) {
if (count == rates.getDimension() ) {
// cannot increase any further
return Double.NEGATIVE_INFINITY;
}
Expand Down
15 changes: 8 additions & 7 deletions src/beast/evolution/sitemodel/BEASTModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
import beast.core.Input;
import beast.core.Input.Validate;
import beast.core.parameter.BooleanParameter;
import beast.core.parameter.IntegerParameter;
import beast.evolution.tree.Node;

@Description("Site model that jumps between with and without gamma sites, as well as with and without invariant sites")
public class BEASTModelTest extends SiteModel {

public Input<BooleanParameter> hasGammaRatesInput = new Input<BooleanParameter>("hasGammaRates", "flag indicating whether gamma rate heterogeneity should be used", Validate.REQUIRED);
public Input<BooleanParameter> hasInvariantSitesInput = new Input<BooleanParameter>("hasInvariantSites", "flag indicating whether invariant sites should be used", Validate.REQUIRED);
public Input<IntegerParameter> hasGammaRatesInput = new Input<IntegerParameter>("hasGammaRates", "flag indicating whether gamma rate heterogeneity should be used", Validate.REQUIRED);
public Input<IntegerParameter> hasInvariantSitesInput = new Input<IntegerParameter>("hasInvariantSites", "flag indicating whether invariant sites should be used", Validate.REQUIRED);

BooleanParameter hasInvariantSites;
BooleanParameter hasGammaRates;
IntegerParameter hasInvariantSites;
IntegerParameter hasGammaRates;

@Override
public void initAndValidate() throws Exception {
Expand Down Expand Up @@ -52,7 +53,7 @@ protected void calculateCategoryRates(final Node node) {
double propVariable = 1.0;
int cat = 0;

if (/*invarParameter != null && */hasInvariantSites.getValue()) {
if (/*invarParameter != null && */hasInvariantSites.getValue() > 0) {
if (hasPropInvariantCategory) {
categoryRates[0] = 0.0;
categoryProportions[0] = invarParameter.getValue();
Expand All @@ -68,7 +69,7 @@ protected void calculateCategoryRates(final Node node) {
}
}

if (hasGammaRates.getValue()) {
if (hasGammaRates.getValue() > 0) {

final double a = shapeParameter.getValue();
double mean = 0.0;
Expand Down Expand Up @@ -144,7 +145,7 @@ protected boolean requiresRecalculation() {

@Override
public double getProportionInvariant() {
if (hasInvariantSites.getValue()) {
if (hasInvariantSites.getValue() > 0) {
return invarParameter.getValue();
} else {
return 0.0;
Expand Down
1 change: 1 addition & 0 deletions src/beast/math/distributions/RBPrior.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package beast.math.distributions;


import beast.core.Description;
import beast.core.Function;
import beast.core.Input;
Expand Down
60 changes: 30 additions & 30 deletions templates/BEASTmodeltest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,40 @@
<parameter id="BMT_SubstModelRates.s:$(n)" dimension="5" lower="0.01" name="stateNode" upper="100.0">1.0</parameter>
<parameter id="BMT_gammaShape.s:$(n)" name="stateNode">1.0</parameter>
<parameter id="BMT_ProportionInvariant.s:$(n)" lower="0.0" name="stateNode" upper="1.0">0.1</parameter>
<stateNode id="hasInvariantSites.s:$(n)" spec="parameter.BooleanParameter">1</stateNode>
<stateNode id="hasGammaRates.s:$(n)" spec="parameter.BooleanParameter">1</stateNode>
<stateNode id="hasInvariantSites.s:$(n)" spec="parameter.IntegerParameter">1</stateNode>
<stateNode id="hasGammaRates.s:$(n)" spec="parameter.IntegerParameter">1</stateNode>
<distribution id="BMT_RatesPrior.s:$(n)" spec="beast.math.distributions.ModelTestPrior" count="@BMT_SubstModel.s:$(n)" x="@BMT_SubstModelRates.s:$(n)">
<Gamma name="distr" alpha="0.2" beta="5.0"/>
</distribution>
<prior id="BMT_GammaShapePrior.s:$(n)" name="distribution" x="@BMT_gammaShape.s:$(n)">
<Exponential name="distr" mean="1.0"/>
</prior>
<prior id="BMT_PropInvariantPrior.s:$(n)" name="distribution" x="@BMT_ProportionInvariant.s:$(n)">
<Uniform name="distr" lower="0.0" upper="1.0"/>
</prior>
<Gamma name="distr" alpha="0.2" beta="5.0"/>
</distribution>
<distribution id="BMT_GammaShapePrior.s:$(n)" spec="beast.math.distributions.ModelTestPrior" count="@hasGammaRates.s:$(n)" x="@BMT_gammaShape.s:$(n)">
<Exponential name="distr" mean="1.0"/>
</distribution>
<distribution id="BMT_PropInvariantPrior.s:$(n)" spec="beast.math.distributions.ModelTestPrior" count="@hasInvariantSites.s:$(n)" x="@BMT_ProportionInvariant.s:$(n)">
<Uniform name="distr" lower="0.0" upper="1.0"/>
</distribution>
<siteModel id="BEASTModelTest.s:$(n)" spec="beast.evolution.sitemodel.BEASTModelTest"
gammaCategoryCount="4" BMT_ProportionInvariant="@BMT_ProportionInvariant.s:$(n)" shape="@BMT_gammaShape.s:$(n)"
hasGammaRates="@hasGammaRates.s:$(n)" hasInvariantSites="@hasInvariantSites.s:$(n)">
<parameter id="BMT_mutationRate.s:$(n)" estimate="false" name="mutationRate">1.0</parameter>
<substModel id="BMT_SubstModel.s:$(n)" spec="ModelTest" count="@BMT_SubstModel.s:$(n)" rates="@BMT_SubstModelRates.s:$(n)">
<frequencies id="freqs.s:$(n)" spec="Frequencies" data="@$(n)"/>
</substModel>
</siteModel>
<siteModel id="BEASTModelTest.s:$(n)" spec="beast.evolution.sitemodel.BEASTModelTest"
gammaCategoryCount="4" BMT_ProportionInvariant="@BMT_ProportionInvariant.s:$(n)" shape="@BMT_gammaShape.s:$(n)"
hasGammaRates="@hasGammaRates.s:$(n)" hasInvariantSites="@hasInvariantSites.s:$(n)">
<parameter id="BMT_mutationRate.s:$(n)" estimate="false" name="mutationRate">1.0</parameter>
<substModel id="BMT_SubstModel.s:$(n)" spec="ModelTest" count="@BMT_SubstModel.s:$(n)" rates="@BMT_SubstModelRates.s:$(n)">
<frequencies id="freqs.s:$(n)" spec="Frequencies" data="@$(n)"/>
</substModel>
</siteModel>
<operator id="ModelTestOperator.s:$(n)" spec="ModelTestOperator" count="@BMT_SubstModel.s:$(n)" rates="@BMT_SubstModelRates.s:$(n)" weight="1.0"/>
<operator id="BMT_ModelTestOperator.s:$(n)" spec="ModelTestOperator" count="@BMT_SubstModel.s:$(n)" rates="@BMT_SubstModelRates.s:$(n)" weight="1.0"/>
<operator id="BMT_SubstModelRatescaler.s:$(n)" spec="ModelTestScaleOperator" count="@BMT_SubstModel.s:$(n)" parameter="@BMT_SubstModelRates.s:$(n)" scaleFactor="0.5" weight="1.0"/>
<operator id="BMT_SubstModelRatescaler.s:$(n)" spec="ModelTestScaleOperator" count="@BMT_SubstModel.s:$(n)" parameter="@BMT_SubstModelRates.s:$(n)" scaleFactor="0.5" weight="1.0"/>
<operator id="BMT_gammaShapeScaler.s:$(n)" spec="ScaleOperator" parameter="@BMT_gammaShape.s:$(n)" scaleFactor="0.5" weight="0.1"/>
<operator id="BMT_ProportionInvariantScaler.s:$(n)" spec="ScaleOperator" parameter="@BMT_ProportionInvariant.s:$(n)" scaleFactor="0.5" weight="0.1"/>
<operator id="hasGammaRatesFlipper.s:$(n)" spec="BitFlipOperator" parameter="@hasGammaRates.s:$(n)" weight="0.1"/>
<operator id="hasInvariantSitesFlipper.s:$(n)" spec="BitFlipOperator" parameter="@hasInvariantSites.s:$(n)" weight="0.1"/>
<operator id="BMT_hasGammaRatesFlipper.s:$(n)" spec="ModelTestOperator" count="@hasGammaRates.s:$(n)" rates="@BMT_gammaShape.s:$(n)" weight="0.1"/>
<operator id="BMT_gammaShapeScaler.s:$(n)" spec="ModelTestScaleOperator" count="@hasGammaRates.s:$(n)" parameter="@BMT_gammaShape.s:$(n)" scaleFactor="0.5" weight="0.5"/>
<operator id="BMT_hasInvariantSitesFlipper.s:$(n)" spec="ModelTestOperator" count="@hasInvariantSites.s:$(n)" rates="@BMT_ProportionInvariant.s:$(n)" weight="0.1"/>
<operator id="BMT_ProportionInvariantScaler.s:$(n)" spec="ModelTestScaleOperator" count="@hasInvariantSites.s:$(n)" parameter="@BMT_ProportionInvariant.s:$(n)" scaleFactor="0.5" weight="0.5"/>
]]>

Expand All @@ -62,12 +62,12 @@
<connect srcID='BMT_GammaShapePrior.s:$(n)' targetID='prior' inputName='distribution' if='inlikelihood(BEASTModelTest.s:$(n)) and BMT_gammaShape.s:$(n)/estimate=true'>Prior on gamma shape parameter for partition s:$(n)</connect>
<connect srcID='BMT_PropInvariantPrior.s:$(n)' targetID='prior' inputName='distribution' if='inlikelihood(BEASTModelTest.s:$(n)) and BMT_ProportionInvariant.s:$(n)/estimate=true'>Prior on proportion invariant for partition s:$(n)</connect>

<connect srcID='ModelTestOperator.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Resersible jump of subst models for partition s:$(n)</connect>
<connect srcID='BMT_ModelTestOperator.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Resersible jump of subst models for partition s:$(n)</connect>
<connect srcID='BMT_SubstModelRatescaler.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n)) and BMT_SubstModelRates.s:$(n)/estimate=true'>Scales subst model rates of partition s:$(n)</connect>
<connect srcID='BMT_gammaShapeScaler.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n)) and BMT_gammaShape.s:$(n)/estimate=true'>Scales gamma shape parameter of partition s:$(n)</connect>
<connect srcID='BMT_ProportionInvariantScaler.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n)) and BMT_ProportionInvariant.s:$(n)/estimate=true'>Scales proportion invariant of partition s:$(n)</connect>
<connect srcID='hasGammaRatesFlipper.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Switches gamma rates on/off of partition s:$(n)</connect>
<connect srcID='hasInvariantSitesFlipper.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Switches invariant sites on/off of partition s:$(n)</connect>
<connect srcID='BMT_hasGammaRatesFlipper.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Switches gamma rates on/off of partition s:$(n)</connect>
<connect srcID='BMT_hasInvariantSitesFlipper.s:$(n)' targetID='mcmc' inputName='operator' if='inlikelihood(BEASTModelTest.s:$(n))'>Switches invariant sites on/off of partition s:$(n)</connect>

<connect srcID='BMT_SubstModel.s:$(n)' targetID='tracelog' inputName='log' if='inlikelihood(BEASTModelTest.s:$(n))'/>
<connect srcID='BMT_SubstModelRates.s:$(n)' targetID='tracelog' inputName='log' if='inlikelihood(BEASTModelTest.s:$(n))'/>
Expand Down

0 comments on commit 43cfe75

Please sign in to comment.