LinguaPhylo / LPhyBeast

Convert LPhy scripts to BEAST 2 XML
GNU Lesser General Public License v2.1
3 stars 1 forks source link

Migrate to BEAST 2.7 operators #128

Open walterxie opened 10 months ago

walterxie commented 10 months ago

TODO:

  1. AVMNNoperator for frequencies, site and substitution models, and trees;
  2. Strict clock UpDownOperator with AVMNNoperators;
  3. relax clock ?
  4. replace tree scale operator with more efficient BICESPS operators.
walterxie commented 3 months ago

It is very complex. Each AdaptableVarianceMultivariateNormalOperator will map to each beast partition.

The code needs a Map to store the idref of parameters in an AVMN operator, which has be partially implemented in the branch AVMNNoperator. Check TODO in lphybeast.tobeast.operators.DefaultOperatorStrategy

walterxie commented 2 months ago

The proposed implementation is to add AVMNNoperator separately, after adding all default operators but before adding extra operators. So it needs:

  1. guess partition from index added in ID, e.g. _0, _1, ...
  2. link the required operators in the same partition
  3. create XML.

Here is the BEAST template for guide:

            <operator id="AVMNOperator.$(n)" spec="beast.base.evolution.operator.kernel.AdaptableVarianceMultivariateNormalOperator" weight="0.1" 
                coefficient="1.0"
                scaleFactor="1"
                beta="0.05"
                initial="800"
                burnin="400"
                every="1" allowNonsense="true">
                <transformations id="AVMNSumTransform.$(n)" spec="beast.base.inference.operator.kernel.Transform$LogConstrainedSumTransform" sum="1.0">
                    <!-- frequencies -->
                </transformations>
                <transformations id="AVMNLogTransform.$(n)" spec="beast.base.inference.operator.kernel.Transform$LogTransform">
                    <!-- site and substitution model parameters -->
                </transformations>
                <transformations id="AVMNNoTransform.$(n)" spec="beast.base.inference.operator.kernel.Transform$NoTransform">
                    <!-- tree -->
                </transformations>
            </operator>

            <operator id="StrictClockRateScaler.c:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="1.5">
                <parameter idref="clockRate.c:$(n)"/>
                <operator idref="AVMNOperator.$(n)"/>
                <operator id='StrictClockRateScalerX.c:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.75" weight="3" parameter='@clockRate.c:$(n)'/>
            </operator>

            <operator id="strictClockUpDownOperator.c:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="1.5">
                <parameter idref="clockRate.c:$(n)"/>
                <tree idref="Tree.t:$(n)"/>
                <operator idref="AVMNOperator.$(n)"/>
                <operator id='strictClockUpDownOperatorX.c:$(n)' spec='kernel.BactrianUpDownOperator' scaleFactor="0.75" weight="3">
                    <up idref="clockRate.c:$(n)"/>
                    <down idref="Tree.t:$(n)"/>
                </operator>
            </operator>

            <operator id="proportionInvariantScaler.s:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="0.05">
                <parameter idref="proportionInvariant.s:$(n)"/>
                <operator idref="AVMNOperator.$(n)"/>
                <operator id='proportionInvariantScalerX.s:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@proportionInvariant.s:$(n)"/>
            </operator>

            <operator id="mutationRateScaler.s:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="0.05">
                <parameter idref="mutationRate.s:$(n)"/>
                <operator idref="AVMNOperator.$(n)"/>
                <operator id='mutationRateScalerX.s:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@mutationRate.s:$(n)"/>
            </operator>

            <operator id="gammaShapeScaler.s:$(n)" spec="beast.base.evolution.operator.AdaptableOperatorSampler" weight="0.05">
                <parameter idref="gammaShape.s:$(n)"/>
                <operator idref="AVMNOperator.$(n)"/>
                <operator id='gammaShapeScalerX.s:$(n)' spec='kernel.BactrianScaleOperator' scaleFactor="0.5" weight="0.1" parameter="@gammaShape.s:$(n)"/>
            </operator>