<beast version='2.0'
       namespace='beastfx.app.beauti:beast.pkgmgmt:beast.base.core:beast.base.inference:beast.base.evolution.branchratemodel:beast.base.evolution.speciation:beast.base.evolution.tree.coalescent:beast.base.util:beast.base.math:beast.evolution.nuc:beast.base.evolution.operator:beast.base.inference.operator:beast.base.evolution.sitemodel:beast.base.evolution.substitutionmodel:beast.base.evolution.likelihood:beast.evolution:beast.base.inference.distribution'>







       
    <mergewith point='misc'>
        <fragment id='TreeOperators' spec="beastfx.app.beauti.Fragment">
            <![CDATA[
<!--            
			replace tree scale operator with more efficient BICESPS operators.
			<operator id='$(m)TreeScaler.t:$(n)' spec='BactrianScaleOperator' scaleFactor="0.1" weight="3" tree="@Tree.t:$(n)"/>
-->                        
		    <operator id="$(m)BICEPSEpochTop.t:$(n)" spec="beast.base.evolution.operator.EpochFlexOperator" tree="@Tree.t:$(n)" weight="2.0" scaleFactor="0.1"/>
            <operator id="$(m)BICEPSEpochAll.t:$(n)" spec="beast.base.evolution.operator.EpochFlexOperator" tree="@Tree.t:$(n)" weight="2.0" scaleFactor="0.1" fromOldestTipOnly="false"/>      
            <operator id="$(m)BICEPSTreeFlex.t:$(n)" spec="beast.base.evolution.operator.TreeStretchOperator" scaleFactor="0.01" tree="@Tree.t:$(n)" weight="2.0"/>
            <operator id='$(m)TreeRootScaler.t:$(n)' spec='beast.base.evolution.operator.kernel.BactrianScaleOperator' scaleFactor="0.1" weight="3" tree="@Tree.t:$(n)" rootOnly='true'/>
            <operator id='$(m)UniformOperator.t:$(n)' spec='beast.base.evolution.operator.kernel.BactrianNodeOperator' weight="30" tree="@Tree.t:$(n)"/>
            <operator id='$(m)SubtreeSlide.t:$(n)' spec='beast.base.evolution.operator.kernel.BactrianSubtreeSlide' weight="15" size="1.0" tree="@Tree.t:$(n)"/>
            <operator id='$(m)Narrow.t:$(n)' spec='Exchange' isNarrow='true' weight="15" tree="@Tree.t:$(n)"/>
            <operator id='$(m)Wide.t:$(n)' spec='Exchange' isNarrow='false' weight="3" tree="@Tree.t:$(n)"/>
            <operator id='$(m)WilsonBalding.t:$(n)' spec='WilsonBalding' weight="3" tree="@Tree.t:$(n)"/>
            ]]>
            <connect srcID='$(m)BICEPSEpochTop.t:$(n)'            targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Epoch operator that only scale internal nodes above least recent node for tree t:$(n)</connect>
            <connect srcID='$(m)BICEPSEpochAll.t:$(n)'            targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Epoch operator that scales all internal nodes for tree t:$(n)</connect>
            <connect srcID='$(m)BICEPSTreeFlex.t:$(n)'            targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Flex operators for all internal nodes for tree t:$(n)</connect>
            <connect srcID='$(m)TreeRootScaler.t:$(n)'            targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Scales root node for tree t:$(n)</connect>
            <connect srcID='$(m)UniformOperator.t:$(n)'           targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Draws new internal node heights uniformally for tree t:$(n)</connect>
            <connect srcID='$(m)SubtreeSlide.t:$(n)'              targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Performs subtree slide rearrangement of tree t:$(n)</connect>
            <connect srcID='$(m)Narrow.t:$(n)'                    targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Narrow exchange performs local rearrangement of tree t:$(n)</connect>
            <connect srcID='$(m)Wide.t:$(n)'                      targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Wide exchange performs global rearrangement of tree t:$(n)</connect>
            <connect srcID='$(m)WilsonBalding.t:$(n)'             targetID='mcmc' inputName='operator' if='inposterior($(m).t:$(n)) and Tree.t:$(n)/estimate=true'>Performs Wilson-Balding global rearrangement of tree t:$(n)</connect>
        </fragment>
    </mergewith>

    <!-- tree priors -->
    <mergewith point='treePriorTemplates'>
        <!-- Yule -->
        <subtemplate id='YuleModel' class='beast.base.evolution.speciation.YuleModel' mainid='YuleModel.t:$(n)' hmc='
YuleModelUniformOperator/index/=Operators/BactrianNodeOperator/,
YuleModelSubtreeSlide/index/=Operators/SubtreeSlide/,
YuleModelNarrow/index/=Operators/Exchange/,
YuleModelWide/index/=Operators/Exchange/,
YuleModelWilsonBalding/index/=Operators/WilsonBalding/,
YuleModelBICEPSEpochTop/index/=Operators/EpochFlexer/,
YuleModelBICEPSEpochAll/index/=Operators/EpochFlexer/,
YuleModelBICEPSTreeFlex/index/=Operators/TreeStretcher/,
YuleModelTreeRootScaler/index/=Operators/BactrianTreeScaler/,
YuleBirthRateScaler/index/=Operators/BactrianRateScaler/,
YuleBirthRatePrior/index/=Priors/YuleBirthRatePrior/
'>
            <![CDATA[
            <plugin spec='YuleModel' id="YuleModel.t:$(n)" tree='@Tree.t:$(n)'>
                <parameter name='birthDiffRate' id="birthRate.t:$(n)" lower="0.0" value='1.0'/>
            </plugin>

            <prior id='YuleBirthRatePrior.t:$(n)' x='@birthRate.t:$(n)'><distr spec="beast.base.inference.distribution.Uniform" lower='0' upper='1000'/></prior>

  		    <scale id='YuleBirthRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@birthRate.t:$(n)"/>
]]>
			<plate fragment="TreeOperators" var="m" range="YuleModel"/>

            <connect srcID='YuleModel.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'>Yule
                speciation prior on tree t:$(n)
            </connect>
            <connect srcID='birthRate.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and inposterior(birthRate.t:$(n)) and birthRate.t:$(n)/estimate=true'/>

            <connect srcID='YuleBirthRatePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRate.t:$(n)/estimate=true'>
                Yule speciation process birth rate of partition t:$(n)
            </connect>
            <connect srcID='YuleBirthRateScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRate.t:$(n)/estimate=true'>
                Scale birth rate of Yule prior of tree t:$(n)
            </connect>

            <connect srcID='YuleModel.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'/>
            <connect srcID='birthRate.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(YuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRate.t:$(n)/estimate=true'/>

			<connect srcID='birthRate.t:Species' targetID='SBI' inputName='birthRate' if='inposterior(YuleModel.t:Species) and inposterior(birthRate.t:Species)'/>
        </subtemplate>

        <!-- Calibrated Yule -->
        <subtemplate id='CalibratedYuleModel' class='beast.base.evolution.speciation.CalibratedYuleModel'
                     mainid='CalibratedYuleModel.t:$(n)'
                     suppressInputs='beast.base.evolution.speciation.CalibratedYuleModel.logMarginal,beast.base.evolution.speciation.CalibratedYuleModel.tree,beast.base.evolution.speciation.CalibratedYuleModel.treeIntervals,beast.base.evolution.speciation.CalibratedYuleModel.calibrations'
                     hmc="
CalibratedYuleModelUniformOperator/index/=Operators/BactrianNodeOperator/index,
CalibratedYuleModelSubtreeSlide/index/=Operators/SubtreeSlide/,
CalibratedYuleModelNarrow/index/=Operators/Exchange/,
CalibratedYuleModelWide/index/=Operators/Exchange/,
CalibratedYuleModelWilsonBalding/index/=Operators/WilsonBalding/,
CalibratedYuleModelBICEPSEpochTop/index/=Operators/EpochFlexer/,
CalibratedYuleModelBICEPSEpochAll/index/=Operators/EpochFlexer/,
CalibratedYuleModelBICEPSTreeFlex/index/=Operators/TreeStretcher/,
CalibratedYuleModelTreeRootScaler/index/=Operators/BactrianTreeScaler/,
CalibratedYuleBirthRateScaler/index/=Operators/BactrianRateScaler/,
CalibratedYuleBirthRatePrior/index/=Priors/CalibratedYuleBirthRatePrior/
">
            <![CDATA[
            <plugin spec='CalibratedYuleModel' id="CalibratedYuleModel.t:$(n)" tree='@Tree.t:$(n)'>
                <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>

  		    <scale id='CalibratedYuleBirthRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@birthRateY.t:$(n)"/>
]]>
			<plate fragment="TreeOperators" var="m" range="CalibratedYuleModel"/>

            <connect srcID='CalibratedYuleModel.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'>
                Calibrated Yule speciation prior on tree t:$(n)
            </connect>
            <connect srcID='birthRateY.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and inposterior(birthRateY.t:$(n)) and birthRateY.t:$(n)/estimate=true'/>

            <connect srcID='CalibratedYuleBirthRatePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRateY.t:$(n)/estimate=true'>
                Calibrated Yule speciation process birth rate for t:$(n)
            </connect>
            <connect srcID='CalibratedYuleBirthRateScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRateY.t:$(n)/estimate=true'>
                Scale birth rate of Calibrated Yule prior of tree t:$(n)
            </connect>

            <connect srcID='CalibratedYuleModel.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'/>
            <connect srcID='birthRateY.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CalibratedYuleModel.t:$(n)) and inposterior(Tree.t:$(n)) and birthRateY.t:$(n)/estimate=true'/>

			<connect srcID="CalibratedYuleModel.t:Species" targetID='SBI' inputName='calibratedYule' if='inposterior(CalibratedYuleModel.t:Species)'/>
			<connect srcID='birthRateY.t:Species' targetID='SBI' inputName='birthRate' if='inposterior(YuleModel.t:Species) and inposterior(birthRateY.t:Species)'/>
        </subtemplate>

        <!-- Birth Death model according to Gernhard'08 -->
        <subtemplate id='BirthDeathModel' class='beast.base.evolution.speciation.BirthDeathGernhard08Model'
                     mainid='BirthDeath.t:$(n)'
hmc='
BirthDeathUniformOperator/index/=Operators/BactrianNodeOperator/index,
BirthDeathSubtreeSlide/index/=Operators/SubtreeSlide/,
BirthDeathNarrow/index/=Operators/Exchange/,
BirthDeathWide/index/=Operators/Exchange/,
BirthDeathWilsonBalding/index/=Operators/WilsonBalding/,
BirthDeathBICEPSEpochTop/index/=Operators/EpochFlexer/,
BirthDeathBICEPSEpochAll/index/=Operators/EpochFlexer/,
BirthDeathBICEPSTreeFlex/index/=Operators/TreeStretcher/,
BirthDeathTreeRootScaler/index/=Operators/BactrianTreeScaler/,
BirthRateScaler/index/=Operators/BactrianRateScaler/,
DeathRateScaler/index/=Operators/BactrianRateScaler/,
BirthRatePrior/index/=Priors/BirthRatePrior/,
DeathRatePrior/index/=Priors/DeathRatePrior/'>
            <![CDATA[
            <distribution id="BirthDeath.t:$(n)" spec="BirthDeathGernhard08Model" tree='@Tree.t:$(n)'>
                <birthDiffRate spec='parameter.RealParameter' id="BDBirthRate.t:$(n)" value='1' lower='0' upper='10000' />
            	<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='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)"/>
  		    <scale id='DeathRateScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@BDDeathRate.t:$(n)"/>
]]>
			<plate fragment="TreeOperators" var="m" range="BirthDeath"/>

            <connect srcID='BirthDeath.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'>
                Birth-Death speciation prior on tree t:$(n)
            </connect>
            <connect srcID='BDBirthRate.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDBirthRate.t:$(n)) and BDBirthRate.t:$(n)/estimate=true'/>
            <connect srcID='BDDeathRate.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDDeathRate.t:$(n)) and BDDeathRate.t:$(n)/estimate=true'/>

            <connect srcID='BirthRatePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDBirthRate.t:$(n)) and BDBirthRate.t:$(n)/estimate=true'>
                Birth-Death speciation process rate of partition t:$(n)
            </connect>
            <connect srcID='DeathRatePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDDeathRate.t:$(n)) and BDDeathRate.t:$(n)/estimate=true'>
                Death/Birth speciation process relative death rate of partition t:$(n)
            </connect>

            <connect srcID='BirthRateScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDBirthRate.t:$(n)) and BDBirthRate.t:$(n)/estimate=true'>
                Scale Death-Birth rate of Yule prior of tree t:$(n)
            </connect>
            <connect srcID='DeathRateScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDDeathRate.t:$(n)) and BDDeathRate.t:$(n)/estimate=true'>
                Scale Death/Birth rate of Yule prior of tree t:$(n)
            </connect>

            <connect srcID='BirthDeath.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(Tree.t:$(n)) and Tree.t:$(n)/estimate=true'/>
            <connect srcID='BDBirthRate.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDBirthRate.t:$(n)) and BDBirthRate.t:$(n)/estimate=true'/>
            <connect srcID='BDDeathRate.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(BirthDeath.t:$(n)) and inposterior(BDDeathRate.t:$(n)) and BDDeathRate.t:$(n)/estimate=true'/>

			<connect srcID='BDBirthRate.t:Species' targetID='SBI' inputName='birthRate' if='inposterior(BirthDeath.t:Species) and inposterior(BDBirthRate.t:Species)'/>
        </subtemplate>


        <!-- Coalescent for Constant population -->
        <subtemplate id='CoalescentConstantPopulation' class='beast.base.evolution.tree.coalescent.Coalescent'
                     mainid='CoalescentConstant.t:$(n)' hmc='
CoalescentConstantPopulationUniformOperator/index/=Operators/BactrianNodeOperator/index,
CoalescentConstantPopulationSubtreeSlide/index/=Operators/SubtreeSlide/,
CoalescentConstantPopulationNarrow/index/=Operators/Exchange/,
CoalescentConstantPopulationWide/index/=Operators/Exchange/,
CoalescentConstantPopulationWilsonBalding/index/=Operators/WilsonBalding/,
CoalescentConstantPopulationBICEPSEpochTop/index/=Operators/EpochFlexer/,
CoalescentConstantPopulationBICEPSEpochAll/index/=Operators/EpochFlexer/,
CoalescentConstantPopulationBICEPSTreeFlex/index/=Operators/TreeStretcher/,
CoalescentConstantPopulationTreeRootScaler/index/=Operators/BactrianTreeScaler/,
PopSizePrior/index/=Priors/PopSizePrior/,
PopSizeScaler/index/=Operators/BactrianRateScaler/index/'>
            <![CDATA[
            <distribution id="CoalescentConstant.t:$(n)" spec="Coalescent">
                <treeIntervals spec='beast.base.evolution.tree.TreeIntervals' id='TreeIntervals.t:$(n)' tree='@Tree.t:$(n)'/>
                <populationModel spec="ConstantPopulation" id='ConstantPopulation.t:$(n)'>
                     <parameter name="popSize" id="popSize.t:$(n)" value='0.3' lower="0.0" estimate='true'/>
                 </populationModel>
            </distribution>

  		    <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"/>
	        </prior>
]]>
			<plate fragment="TreeOperators" var="m" range="CoalescentConstant"/>

            <connect srcID='CoalescentConstant.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CoalescentConstant.t:$(n)) and Tree.t:$(n)/estimate=true'>Coalescent prior with
                constant rate on tree t:$(n)
            </connect>
            <connect srcID='PopSizePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CoalescentConstant.t:$(n)) and inposterior(popSize.t:$(n)) and popSize.t:$(n)/estimate=true'>
                Coalescent population size parameter of partition t:$(n)
            </connect>

            <connect srcID='popSize.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(CoalescentConstant.t:$(n)) and inposterior(popSize.t:$(n)) and popSize.t:$(n)/estimate=true'/>

            <connect srcID='PopSizeScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(CoalescentConstant.t:$(n)) and inposterior(popSize.t:$(n)) and popSize.t:$(n)/estimate=true'>
                Scale population size of Coalescent prior of tree t:$(n)
            </connect>

            <connect srcID='popSize.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CoalescentConstant.t:$(n)) and inposterior(popSize.t:$(n)) and popSize.t:$(n)/estimate=true'/>
            <connect srcID='CoalescentConstant.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CoalescentConstant.t:$(n)) and Tree.t:$(n)/estimate=true'/>
        </subtemplate>


        <!-- Coalescent for Exponential population -->
        <subtemplate id='CoalescentExponentialPopulation' class='beast.base.evolution.tree.coalescent.Coalescent'
                     mainid='CoalescentExponential.t:$(n)' hmc='
CoalescentExponentialPopulationUniformOperator/index/=Operators/BactrianNodeOperator/index,
CoalescentExponentialPopulationSubtreeSlide/index/=Operators/SubtreeSlide/,
CoalescentExponentialPopulationNarrow/index/=Operators/Exchange/,
CoalescentExponentialPopulationWide/index/=Operators/Exchange/,
CoalescentExponentialPopulationWilsonBalding/index/=Operators/WilsonBalding/,
CoalescentExponentialPopulationBICEPSEpochTop/index/=Operators/EpochFlexer/,
CoalescentExponentialPopulationBICEPSEpochAll/index/=Operators/EpochFlexer/,
CoalescentExponentialPopulationBICEPSTreeFlex/index/=Operators/TreeStretcher/,
CoalescentExponentialPopulationTreeRootScaler/index/=Operators/BactrianTreeScaler/,
GrowthRatePrior/index/=Priors/GrowthRatePrior/,
ePopSizePrior/index/=Priors/ePopSizePrior/,
ePopSizeScaler/index/=Operators/BactrianRateScaler/,
GrowthRateRandomWalk/index/=Operators/BactrianRandomWalk'>
            <![CDATA[
            <distribution id="CoalescentExponential.t:$(n)" spec="Coalescent">
                <treeIntervals spec='beast.base.evolution.tree.TreeIntervals' id='TreeIntervals.t:$(n)' tree='@Tree.t:$(n)'/>
                <populationModel spec="ExponentialGrowth" id="ExponentialGrowth.t:$(n)">
                    <parameter name="popSize" id="ePopSize.t:$(n)" value='0.3' lower="0.0" estimate='true'/>
                    <parameter name="growthRate" id="growthRate.t:$(n)" value='3e-4' estimate='true'/>
                </populationModel>
            </distribution>

  		    <operator id='ePopSizeScaler.t:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter="@ePopSize.t:$(n)"/>
	        <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"/>
	        </prior>
	        <prior id='GrowthRatePrior.t:$(n)' x='@growthRate.t:$(n)'>
	        	<distr spec="LaplaceDistribution">
	        		<parameter name="mu" value='0.001' estimate="false"/>
	        		<parameter name="scale" value='0.5' estimate="false"/>
	        	</distr>
	        </prior>

]]>
			<plate fragment="TreeOperators" var="m" range="CoalescentExponential"/>

            <connect srcID='CoalescentExponential.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CoalescentExponential.t:$(n)) and Tree.t:$(n)/estimate=true'>Coalesenct prior with
                exponential rate on tree t:$(n)
            </connect>
            <connect srcID='ePopSizePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(ePopSize.t:$(n)) and ePopSize.t:$(n)/estimate=true'>
                Coalescent population size parameter of partition t:$(n)
            </connect>
            <connect srcID='GrowthRatePrior.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(growthRate.t:$(n)) and growthRate.t:$(n)/estimate=true'>
                Coalescent growth rate of partition t:$(n)
            </connect>

            <connect srcID='ePopSize.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(ePopSize.t:$(n))  and ePopSize.t:$(n)/estimate=true'/>
            <connect srcID='growthRate.t:$(n)' targetID='state' inputName='stateNode'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(growthRate.t:$(n)) and growthRate.t:$(n)/estimate=true'/>

            <connect srcID='ePopSizeScaler.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(ePopSize.t:$(n))  and ePopSize.t:$(n)/estimate=true'>
                Scale population size of Coalescent prior of tree t:$(n)
            </connect>
            <connect srcID='GrowthRateRandomWalk.t:$(n)' targetID='mcmc' inputName='operator'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(growthRate.t:$(n)) and growthRate.t:$(n)/estimate=true'>
                Scale growth rate of Coalescent prior of tree t:$(n)
            </connect>

            <connect srcID='CoalescentExponential.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CoalescentExponential.t:$(n)) and Tree.t:$(n)/estimate=true'/>
            <connect srcID='ePopSize.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(ePopSize.t:$(n)) and ePopSize.t:$(n)/estimate=true'/>
            <connect srcID='growthRate.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(CoalescentExponential.t:$(n)) and inposterior(growthRate.t:$(n)) and growthRate.t:$(n)/estimate=true'/>
        </subtemplate>


        <!-- Coalescent for Bayesian skyline -->
        <subtemplate id='CoalescentBayesianSkyline' class='beast.base.evolution.tree.coalescent.Coalescent'
                     mainid='BayesianSkyline.t:$(n)'
                     suppressInputs='beast.base.inference.distribution.MarkovChainDistribution.parameter,
                     beast.base.inference.distribution.MarkovChainDistribution.initialMean' hmc='
BayesianSkylineUniformOperator/index/=Operators/BactrianNodeOperator/index,
BayesianSkylineSubtreeSlide/index/=Operators/SubtreeSlide/,
BayesianSkylineNarrow/index/=Operators/Exchange/,
BayesianSkylineWide/index/=Operators/Exchange/,
BayesianSkylineWilsonBalding/index/=Operators/WilsonBalding/,
BayesianSkylineBICEPSEpochTop/index/=Operators/EpochFlexer/,
BayesianSkylineBICEPSEpochAll/index/=Operators/EpochFlexer/,
BayesianSkylineBICEPSTreeFlex/index/=Operators/TreeStretcher/,
BayesianSkylineTreeRootScaler/index/=Operators/BactrianTreeScaler/,
popSizesScaler/index/=Operators/BactrianRateScaler/,
groupSizesDelta/index/=Operators/BactrianDeltaExchange/index/'>
            <![CDATA[
            <distribution spec="BayesianSkyline" id='BayesianSkyline.t:$(n)'>
                <parameter name='popSizes' id='bPopSizes.t:$(n)' dimension="5" value="380.0" lower="0.0" estimate='true'/>
                <groupSizes spec='parameter.IntegerParameter' id='bGroupSizes.t:$(n)' dimension='5' value='1' estimate='true'/>
                <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)"/>

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

]]>
			<plate fragment="TreeOperators" var="m" range="BayesianSkyline"/>

            <connect srcID='BayesianSkyline.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(BayesianSkyline.t:$(n)) and Tree.t:$(n)/estimate=true'>Coalescent with Bayesian
                skyline prior tree t:$(n)
            </connect>
            <connect srcID='bPopSizes.t:$(n)' targetID='state' inputName='stateNode'
                     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='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='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='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>
        </subtemplate>


        <!-- Coalescent for Extended Bayesian skyline -->
        <subtemplate id='CoalescentExtendedBayesianSkyline' class='beast.base.evolution.tree.coalescent.Coalescent'
                     mainid='ExtendedBayesianSkyline.t:$(n)' hmc='
ExtendedBayesianSkylineUniformOperator/index/=Operators/BactrianNodeOperator/index,
ExtendedBayesianSkylineSubtreeSlide/index/=Operators/SubtreeSlide/,
ExtendedBayesianSkylineNarrow/index/=Operators/Exchange/,
ExtendedBayesianSkylineWide/index/=Operators/Exchange/,
ExtendedBayesianSkylineWilsonBalding/index/=Operators/WilsonBalding/,
ExtendedBayesianSkylineBICEPSEpochTop/index/=Operators/EpochFlexer/,
ExtendedBayesianSkylineBICEPSEpochAll/index/=Operators/EpochFlexer/,
ExtendedBayesianSkylineBICEPSTreeFlex/index/=Operators/TreeStretcher/,
ExtendedBayesianSkylineTreeRootScaler/index/=Operators/BactrianTreeScaler/,
bitflip.alltrees/index/=Operators/BitFlipper/,
indicatorSampler.alltrees/index/=Operators/BactrianDeltaExchange/,
indicatorScaler.alltrees/index/=Operators/BactrianDeltaExchange/,
populationMeanPrior/index/=Priors/populationMeanPrior/,
indicatorsPrior/index/=Priors/indicatorsPrior/,
EBSPupDownOperator.alltrees/index/=Operators/BactrianUpDown/,
EBSPLogger/fileName/,
EBSPLogger/sort/,
EBSPLogger/sanitiseHeaders/,
EBSPLogger/logEvery/,
EBSPLogger/mode/
'>
            <![CDATA[
	        <stateNode id="indicators.alltrees" spec="parameter.BooleanParameter" value="false"/>
            <stateNode id="populationMean.alltrees" spec="parameter.RealParameter" lower="0.0" value="1"/>
	        <stateNode id="popSizes.alltrees" spec="parameter.RealParameter" lower="0.0" value="1"/>

            <distribution id="ExtendedBayesianSkyline.t:$(n)" spec="Coalescent">
                 <treeIntervals id="treeIntervals.t:$(n)" spec='beast.base.evolution.tree.TreeIntervals' tree="@Tree.t:$(n)"/>
                 <populationModel id="scaledDemo.t:$(n)" spec="beast.base.evolution.tree.coalescent.ScaledPopulationFunction" factor='1' population='@demographic.alltrees'/>
            </distribution>

            <population id="demographic.alltrees" populationIndicators="@indicators.alltrees" populationSizes="@popSizes.alltrees" spec="beast.base.evolution.tree.coalescent.CompoundPopulationFunction" type="linear" useIntervalsMiddle="false">
                <itree idref="treeIntervals.t:$(n)"/>
			</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>
            </prior>
            <prior id="indicatorsPrior.alltrees">
                <x arg="@indicators.alltrees" id="indsSun.alltrees" spec="beast.base.evolution.Sum"/>
                <distr spec="Poisson"  id='Poisson.EBSP'>
                    <parameter name="lambda" upper="0.0" value="0.69314718056" estimate='false'/>
                </distr>
            </prior>
            <prior id="popSizePrior.alltrees" x="@popSizes.alltrees">
                <distr id="popPriorDist.EBSP" mean="@populationMean.alltrees" spec="Exponential"/>
            </prior>

            <logger id="EBSPLogger" fileName='EBSP.log' logEvery='5000' model="@demographic.alltrees">
                <log idref='demographic.alltrees'/>
            </logger>
            <log id='sumIndicators' spec='beast.base.evolution.Sum' arg='@indicators.alltrees'/>


			<operator id="bitflip.alltrees" parameter="@indicators.alltrees" spec="BitFlipOperator" uniform="true" weight="30.0"/>
			<operator id="indicatorSampler.alltrees" dist="@popPriorDist.EBSP" indicators="@indicators.alltrees" spec="beast.base.evolution.tree.coalescent.SampleOffValues" values="@popSizes.alltrees" weight="15.0"/>
			<operator id="indicatorScaler.alltrees" degreesOfFreedom="1" indicator="@indicators.alltrees" parameter="@popSizes.alltrees" scaleAll="false" scaleAllIndependently="false" scaleFactor="0.5" spec="kernel.BactrianScaleOperator" weight="15.0"/>
			<operator id="EBSPupDownOperator.alltrees" scaleFactor="0.7" spec="kernel.BactrianUpDownOperator" weight="5.0">
				<up idref="popSizes.alltrees"/>
				<up idref="populationMean.alltrees"/>
			</operator>
]]>
			<plate fragment="TreeOperators" var="m" range="ExtendedBayesianSkyline"/>

            <connect srcID='ExtendedBayesianSkyline.t:$(n)' targetID='prior' inputName='distribution'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n)) and Tree.t:$(n)/estimate=true'>Coalescent with
                extended Bayesian skyline prior tree t:$(n)
            </connect>
            <connect srcID='treeIntervals.t:$(n)' targetID='demographic.alltrees' inputName='itree'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n)) and Tree.t:$(n)/estimate=true'/>

            <connect srcID='indicators.alltrees' targetID='state' inputName='stateNode'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='populationMean.alltrees' targetID='state' inputName='stateNode'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='popSizes.alltrees' targetID='state' inputName='stateNode'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>

            <connect srcID='populationMeanPrior.alltrees' targetID='prior' inputName='distribution'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>Extended Bayesian Skyline population prior mean of
                partition t:$(n)
            </connect>
            <connect srcID='indicatorsPrior.alltrees' targetID='prior' inputName='distribution'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>Average number of population change points of
                partition t:$(n)
            </connect>
            <connect srcID='popSizePrior.alltrees' targetID='prior' inputName='distribution'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>Extended Bayesian Skyline population prior of
                partition t:$(n)
            </connect>

            <connect srcID='ExtendedBayesianSkyline.t:$(n)' targetID='tracelog' inputName='log'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='indicators.alltrees' targetID='tracelog' inputName='log'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='populationMean.alltrees' targetID='tracelog' inputName='log'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='popSizes.alltrees' targetID='tracelog' inputName='log'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>
            <connect srcID='sumIndicators' targetID='tracelog' inputName='log'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>

            <connect srcID='EBSPLogger' targetID='mcmc' inputName='logger'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'/>

            <connect srcID='bitflip.alltrees' targetID='mcmc' inputName='operator'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>EBSP bitflip operator
            </connect>
            <connect srcID='indicatorSampler.alltrees' targetID='mcmc' inputName='operator'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>EBSP indicator sampler
            </connect>
            <connect srcID='indicatorScaler.alltrees' targetID='mcmc' inputName='operator'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>EBSP population sizes
            </connect>
            <connect srcID='EBSPupDownOperator.alltrees' targetID='mcmc' inputName='operator'
                     if='inposterior(ExtendedBayesianSkyline.t:$(n))'>Up/down scale substitution rates of EBSP prior and
                tree
            </connect>
        </subtemplate>

    </mergewith>
</beast>


