Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions fxtemplates/ClockModels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
</operator>

<prior id='ClockPrior.c:$(n)' x='@clockRate.c:$(n)'>
<Gamma name="distr">
<alpha spec="parameter.RealParameter" value="0.01" estimate="false"/>
<beta spec="parameter.RealParameter" value="100.0" estimate="false"/>
</Gamma>
<distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr>
</prior>
]]>
<connect srcID='clockRate.c:$(n)' targetID='state' inputName='stateNode'
Expand Down Expand Up @@ -116,10 +116,10 @@
</logger>

<prior id='MeanRRatePrior.c:s$(n)' x='@meanClockRate.c:$(n)'>
<Gamma name="distr">
<alpha spec="parameter.RealParameter" value="0.01" estimate="false"/>
<beta spec="parameter.RealParameter" value="100.0" estimate="false"/>
</Gamma>
<distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr>
</prior>
]]>
<connect srcID='Indicators.c:$(n)' targetID='state' inputName='stateNode'
Expand Down
15 changes: 12 additions & 3 deletions fxtemplates/Standard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,14 @@ ClusterTree/clusterType/,
</branchRateModel>
</plugin>

<prior id='ClockPrior.c:$(n)' x='@clockRate.c:$(n)'><distr spec="beast.base.inference.distribution.Uniform" upper='Infinity'/></prior>
<prior id='MutationRatePrior.s:$(n)' x='@mutationRate.s:$(n)'><distr spec="OneOnX"/></prior>
<prior id='ClockPrior.c:$(n)' x='@clockRate.c:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>
<prior id='MutationRatePrior.s:$(n)' x='@mutationRate.s:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>

<!-- tree and its properties -->
<taxonset id='TaxonSet.$(n)' spec='beast.base.evolution.alignment.TaxonSet' alignment='@$(n)' />
Expand Down Expand Up @@ -309,7 +315,10 @@ ClusterTree/clusterType/,
<operator id='YuleModelWilsonBalding.t:$(n)' spec='WilsonBalding' weight="3" tree="@Tree.t:$(n)"/>


<prior id='YuleBirthRatePrior.t:$(n)' x='@birthRate.t:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='Infinity'/></prior>
<prior id='YuleBirthRatePrior.t:$(n)' x='@birthRate.t:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>
<prior id='GammaShapePrior.s:$(n)' x='@gammaShape.s:$(n)'><distr spec="beast.base.inference.distribution.Exponential"><mean spec="parameter.RealParameter" estimate="false" value="1.0"/></distr></prior>
<prior id='PropInvariantPrior.s:$(n)' x='@proportionInvariant.s:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1'/></prior>
<operator id='YuleBirthRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@birthRate.t:$(n)"/>
Expand Down
5 changes: 4 additions & 1 deletion fxtemplates/SubstModels.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ MutationRatePrior/index/=Priors/MutationRatePrior/
<shape spec='parameter.RealParameter' id='gammaShape.s:$(n)' value='1.0' lower="0.1" estimate='false'/>
</plugin>

<prior id='MutationRatePrior.s:$(n)' x='@mutationRate.s:$(n)'><distr spec="OneOnX"/></prior>
<prior id='MutationRatePrior.s:$(n)' x='@mutationRate.s:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>
<prior id='GammaShapePrior.s:$(n)' x='@gammaShape.s:$(n)'><distr spec="beast.base.inference.distribution.Exponential" mean='1'/></prior>
<prior id='PropInvariantPrior.s:$(n)' x='@proportionInvariant.s:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1'/></prior>

Expand Down
53 changes: 42 additions & 11 deletions fxtemplates/TreePriors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ CalibratedYuleBirthRatePrior/index/=Priors/CalibratedYuleBirthRatePrior/
<parameter name='birthRate' id="birthRateY.t:$(n)" lower="0.0" value='1.0'/>
</plugin>

<prior id='CalibratedYuleBirthRatePrior.t:$(n)' x='@birthRateY.t:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1000'/></prior>
<prior id='CalibratedYuleBirthRatePrior.t:$(n)' x='@birthRateY.t:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>

<scale id='CalibratedYuleBirthRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@birthRateY.t:$(n)"/>
]]>
Expand Down Expand Up @@ -164,7 +167,10 @@ DeathRatePrior/index/=Priors/DeathRatePrior/'>
<relativeDeathRate spec='parameter.RealParameter' id="BDDeathRate.t:$(n)" value='0.5' lower='0' upper='1' />
</distribution>

<prior id='BirthRatePrior.t:$(n)' x='@BDBirthRate.t:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1000'/></prior>
<prior id='BirthRatePrior.t:$(n)' x='@BDBirthRate.t:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>
<prior id='DeathRatePrior.t:$(n)' x='@BDDeathRate.t:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1'/></prior>

<scale id='BirthRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@BDBirthRate.t:$(n)"/>
Expand Down Expand Up @@ -234,7 +240,10 @@ PopSizeScaler/index/=Operators/BactrianRateScaler/index/'>

<operator id='PopSizeScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@popSize.t:$(n)"/>
<prior id='PopSizePrior.t:$(n)' x='@popSize.t:$(n)'>
<distr spec="OneOnX"/>
<distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr>
</prior>
]]>
<plate fragment="TreeOperators" var="m" range="CoalescentConstant"/>
Expand Down Expand Up @@ -292,7 +301,10 @@ GrowthRateRandomWalk/index/=Operators/BactrianRandomWalk'>
<operator id="GrowthRateRandomWalk.t:$(n)" spec="kernel.BactrianRandomWalkOperator" scaleFactor='0.1' weight="3" parameter="@growthRate.t:$(n)"/>

<prior id='ePopSizePrior.t:$(n)' x='@ePopSize.t:$(n)'>
<distr spec="OneOnX"/>
<distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr>
</prior>
<prior id='GrowthRatePrior.t:$(n)' x='@growthRate.t:$(n)'>
<distr spec="LaplaceDistribution">
Expand Down Expand Up @@ -367,11 +379,19 @@ groupSizesDelta/index/=Operators/BactrianDeltaExchange/index/'>
<treeIntervals spec='beast.base.evolution.tree.TreeIntervals' id='BSPTreeIntervals.t:$(n)' tree='@Tree.t:$(n)'/>
</distribution>

<distribution id='MarkovChainedPopSizes.t:$(n)' spec="beast.base.inference.distribution.MarkovChainDistribution"
jeffreys="true"
parameter="@bPopSizes.t:$(n)"/>
<!-- The first popSize has an exponential prior with an estimated mean, instead of the
improper Jeffreys (1/x) prior; that mean has a proper LogNormal(0, 8) prior. -->
<distribution id='MarkovChainedPopSizes.t:$(n)' spec="beast.base.inference.distribution.MarkovChainDistribution"
parameter="@bPopSizes.t:$(n)">
<initialMean id='bPopSizesInitialMean.t:$(n)' spec='parameter.RealParameter' value="380.0" lower="0.0" estimate='true'/>
</distribution>
<prior id='bPopSizesInitialMeanPrior.t:$(n)' x='@bPopSizesInitialMean.t:$(n)'><distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr></prior>

<operator id='popSizesScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="15" parameter="@bPopSizes.t:$(n)"/>
<operator id='popSizesInitialMeanScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@bPopSizesInitialMean.t:$(n)"/>
<operator id='groupSizesDelta.t:$(n)' spec='kernel.BactrianDeltaExchangeOperator' delta="1" weight="6" integer="true"
intparameter="@bGroupSizes.t:$(n)"/>

Expand All @@ -386,25 +406,36 @@ groupSizesDelta/index/=Operators/BactrianDeltaExchange/index/'>
if='inposterior(BayesianSkyline.t:$(n)) and inposterior(bPopSizes.t:$(n))'/>
<connect srcID='bGroupSizes.t:$(n)' targetID='state' inputName='stateNode'
if='inposterior(BayesianSkyline.t:$(n)) and inposterior(bGroupSizes.t:$(n))'/>
<connect srcID='bPopSizesInitialMean.t:$(n)' targetID='state' inputName='stateNode'
if='inposterior(BayesianSkyline.t:$(n)) and inposterior(bPopSizesInitialMean.t:$(n))'/>

<connect srcID='MarkovChainedPopSizes.t:$(n)' targetID='prior' inputName='distribution'
if='inposterior(BayesianSkyline.t:$(n))'>Markov chained prior on population sizes of Bayesian
skyline plot
</connect>
<connect srcID='bPopSizesInitialMeanPrior.t:$(n)' targetID='prior' inputName='distribution'
if='inposterior(BayesianSkyline.t:$(n))'>Prior on the mean of the first population size of
the Bayesian skyline plot
</connect>

<connect srcID='BayesianSkyline.t:$(n)' targetID='tracelog' inputName='log'
if='inposterior(BayesianSkyline.t:$(n))'/>
<connect srcID='bPopSizes.t:$(n)' targetID='tracelog' inputName='log'
if='inposterior(BayesianSkyline.t:$(n))'/>
<connect srcID='bGroupSizes.t:$(n)' targetID='tracelog' inputName='log'
if='inposterior(BayesianSkyline.t:$(n))'/>
<connect srcID='bPopSizesInitialMean.t:$(n)' targetID='tracelog' inputName='log'
if='inposterior(BayesianSkyline.t:$(n))'/>

<connect srcID='popSizesScaler.t:$(n)' targetID='mcmc' inputName='operator'
if='inposterior(BayesianSkyline.t:$(n))'>Scale population size of Coalscent prior of tree t:$(n)
</connect>
<connect srcID='groupSizesDelta.t:$(n)' targetID='mcmc' inputName='operator'
if='inposterior(BayesianSkyline.t:$(n))'>Exchange group sizes of Coalscent prior of tree t:$(n)
</connect>
<connect srcID='popSizesInitialMeanScaler.t:$(n)' targetID='mcmc' inputName='operator'
if='inposterior(BayesianSkyline.t:$(n))'>Scale the mean of the first population size of tree t:$(n)
</connect>
</subtemplate>


Expand Down Expand Up @@ -447,10 +478,10 @@ EBSPLogger/mode/
</population>

<prior id="populationMeanPrior.alltrees" x="@populationMean.alltrees">
<Gamma name="distr">
<alpha spec="parameter.RealParameter" value="0.01" estimate="false"/>
<beta spec="parameter.RealParameter" value="100.0" estimate="false"/>
</Gamma>
<distr spec="beast.base.inference.distribution.LogNormalDistributionModel" meanInRealSpace='false'>
<parameter name='M' value="0.0" estimate='false'/>
<parameter name='S' value="8.0" estimate='false'/>
</distr>
</prior>
<prior id="indicatorsPrior.alltrees">
<x arg="@indicators.alltrees" id="indsSun.alltrees" spec="beast.base.evolution.Sum"/>
Expand Down
40 changes: 38 additions & 2 deletions src/beastfx/app/inputeditor/BeautiConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ public class BeautiConfig extends BEASTObject {
public List<BeautiSubTemplate> subTemplates;
public List<BeautiAlignmentProvider> alignmentProvider;

/** hyperprior for a positive parameter: LogNormal(0, 8) with a scale operator */
public BeautiSubTemplate hyperPriorTemplate = null;
/** hyperprior for a parameter that may be negative (e.g. a LogNormal's M = 0):
* Normal(0, 8) with a random-walk operator. Uses the same IDs as hyperPriorTemplate,
* so BeautiDoc's sync rules (which apply hyperPriorTemplate's connectors) work for both. */
public BeautiSubTemplate realHyperPriorTemplate = null;

@Override
public void initAndValidate() {
Expand Down Expand Up @@ -125,6 +130,7 @@ public void initAndValidate() {
try {
XMLParser parser = new XMLParser();
hyperPriorTemplate = (BeautiSubTemplate) parser.parseBareFragment(HYPER_PRIOR_XML, true);
realHyperPriorTemplate = (BeautiSubTemplate) new XMLParser().parseBareFragment(REAL_HYPER_PRIOR_XML, true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand All @@ -134,11 +140,14 @@ public void initAndValidate() {
final static String HYPER_PRIOR_XML =
" <beast version='2.0'\n" +
" namespace='beastfx.app.beauti:beast.base.core:beast.base.evolution.operators:beast.base.inference.distribution'>\n" +
" <!-- Parameter Hyper Prior -->\n" +
" <!-- Hyper prior for a positive parameter: LogNormal(0, 8) in log space (median 1, 95% from 1.6e-7 to 6.4e6) -->\n" +
" <subtemplate spec='beastfx.app.inputeditor.BeautiSubTemplate' id='HyperPrior' class='beast.base.inference.distribution.Prior' mainid='HyperPrior.$(n)'>\n" +
" <![CDATA[\n" +
" <beastObject id='HyperPrior.$(n)' spec='Prior' x='@parameter.$(n)'>\n" +
" <distr spec='OneOnX'/>\n" +
" <distr spec='beast.base.inference.distribution.LogNormalDistributionModel' meanInRealSpace='false'>\n" +
" <parameter name='M' value='0.0' estimate='false'/>\n" +
" <parameter name='S' value='8.0' estimate='false'/>\n" +
" </distr>\n" +
" </beastObject>\n" +
"\n" +
" <beastObject id='hyperScaler.$(n)' spec='ScaleOperator' scaleFactor='0.5' weight='0.1' parameter='@parameter.$(n)'/>\n" +
Expand All @@ -153,6 +162,32 @@ public void initAndValidate() {
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='HyperPrior.$(n)' targetID='prior' inputName='distribution' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'>Hyper prior for parameter $(n)</connect>\n" +
" </subtemplate>\n" +
" </beast>\n";

final static String REAL_HYPER_PRIOR_XML =
" <beast version='2.0'\n" +
" namespace='beastfx.app.beauti:beast.base.core:beast.base.evolution.operators:beast.base.inference.distribution'>\n" +
" <!-- Hyper prior for a parameter that may be negative: Normal(0, 8), with a random-walk operator, since a scale operator cannot cross zero -->\n" +
" <subtemplate spec='beastfx.app.inputeditor.BeautiSubTemplate' id='HyperPrior' class='beast.base.inference.distribution.Prior' mainid='HyperPrior.$(n)'>\n" +
" <![CDATA[\n" +
" <beastObject id='HyperPrior.$(n)' spec='Prior' x='@parameter.$(n)'>\n" +
" <distr spec='beast.base.inference.distribution.Normal'>\n" +
" <parameter name='mean' value='0.0' estimate='false'/>\n" +
" <parameter name='sigma' value='8.0' estimate='false'/>\n" +
" </distr>\n" +
" </beastObject>\n" +
"\n" +
" <beastObject id='hyperScaler.$(n)' spec='beast.base.inference.operator.RealRandomWalkOperator' windowSize='1.0' weight='0.1' parameter='@parameter.$(n)'/>\n" +
" ]]>\n" +
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='parameter.$(n)' targetID='state' inputName='stateNode' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'/>\n" +
"\n" +
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='hyperScaler.$(n)' targetID='mcmc' inputName='operator' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'>Scale hyper parameter $(n)</connect>\n" +
"\n" +
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='parameter.$(n)' targetID='tracelog' inputName='log' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'/>\n" +
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='HyperPrior.$(n)' targetID='tracelog' inputName='log' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'/>\n" +
"\n" +
" <connect spec='beastfx.app.inputeditor.BeautiConnector' srcID='HyperPrior.$(n)' targetID='prior' inputName='distribution' if='inposterior(parameter.$(n)) and parameter.$(n)/estimate=true'>Hyper prior for parameter $(n)</connect>\n" +
" </subtemplate>\n" +
" </beast>\n";

public void setDoc(BeautiDoc doc) {
partitionTemplate.get().setDoc(doc);
Expand All @@ -161,6 +196,7 @@ public void setDoc(BeautiDoc doc) {
}
doc.setExpertMode(isExpertInput.get());
hyperPriorTemplate.doc = doc;
realHyperPriorTemplate.doc = doc;
}

public void clear() {
Expand Down
9 changes: 8 additions & 1 deletion src/beastfx/app/inputeditor/ParameterInputEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


import beast.base.core.BEASTInterface;
import beast.base.inference.parameter.RealParameter;
import beast.base.core.Input;
import beast.base.core.Log;
import beast.base.evolution.branchratemodel.BranchRateModel;
Expand Down Expand Up @@ -278,7 +279,13 @@ public void toggleEstimate() {

PartitionContext context = new PartitionContext(id.substring("parameter.".length()));
Log.warning.println(context + " " + id);
doc.beautiConfig.hyperPriorTemplate.createSubNet(context, true);
// A log-normal hyperprior and a scale operator suit a positive parameter. Legacy
// parameters often have no lower bound even when positive (e.g. a LogNormal's S),
// so a parameter counts as positive if its lower bound is >= 0 or its value is > 0;
// otherwise (e.g. a LogNormal's M = 0) it gets a normal hyperprior and a
// random-walk operator, since a scale operator cannot move a value of 0.
boolean positive = !(parameter2 instanceof RealParameter rp) || rp.getLower() >= 0 || rp.getValue() > 0;
(positive ? doc.beautiConfig.hyperPriorTemplate : doc.beautiConfig.realHyperPriorTemplate).createSubNet(context, true);
}
hardSync();
refreshPanel();
Expand Down
Loading