Skip to content

Commit

Permalink
move addUpDownOperator to the same class creating all operators #109
Browse files Browse the repository at this point in the history
  • Loading branch information
walterxie committed Jan 15, 2024
1 parent dbc1cf6 commit 8ac4505
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import beast.base.evolution.substitutionmodel.SubstitutionModel;
import beast.base.evolution.tree.Tree;
import beast.base.inference.distribution.Prior;
import beast.base.inference.operator.kernel.BactrianUpDownOperator;
import beast.base.inference.parameter.RealParameter;
import beastclassic.evolution.alignment.AlignmentFromTrait;
import beastclassic.evolution.likelihood.AncestralStateTreeLikelihood;
Expand All @@ -33,6 +32,7 @@
import lphybeast.BEASTContext;
import lphybeast.GeneratorToBEAST;
import lphybeast.tobeast.loggers.TraitTreeLogger;
import lphybeast.tobeast.operators.DefaultOperatorStrategy;

import java.util.Map;

Expand Down Expand Up @@ -215,7 +215,7 @@ public static void constructTreeAndBranchRate(PhyloCTMC phyloCTMC, GenericTreeLi
treeLikelihood.setInputValue("branchRateModel", clockModel);

if (clockRate instanceof RandomVariable && timeTreeValue instanceof RandomVariable && skipBranchOperators == false) {
addUpDownOperator(tree, clockRatePara, context);
DefaultOperatorStrategy.addUpDownOperator(tree, clockRatePara, context);
}
}
}
Expand Down Expand Up @@ -323,21 +323,6 @@ private static void addRelaxedClockOperators(Tree tree, UCRelaxedClockModel rela
context.addExtraOperator(smallPulley);
}

// when both mu and tree are random var
private static void addUpDownOperator(Tree tree, RealParameter clockRate, BEASTContext context) {
String idStr = clockRate.getID() + "Up" + tree.getID() + "DownOperator";
// avoid to duplicate updown ops from the same pair of rate and tree
if (!context.hasExtraOperator(idStr)) {
BactrianUpDownOperator upDownOperator = new BactrianUpDownOperator();
upDownOperator.setID(idStr);
upDownOperator.setInputValue("up", clockRate);
upDownOperator.setInputValue("down", tree);
upDownOperator.setInputValue("scaleFactor", 0.9);
upDownOperator.setInputValue("weight", BEASTContext.getOperatorWeight(tree.getInternalNodeCount()+1));
context.addExtraOperator(upDownOperator);
}
}

@Override
public Class<PhyloCTMC> getGeneratorClass() {
return PhyloCTMC.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import beast.base.inference.operator.IntRandomWalkOperator;
import beast.base.inference.operator.kernel.BactrianDeltaExchangeOperator;
import beast.base.inference.operator.kernel.BactrianRandomWalkOperator;
import beast.base.inference.operator.kernel.BactrianUpDownOperator;
import beast.base.inference.parameter.BooleanParameter;
import beast.base.inference.parameter.IntegerParameter;
import beast.base.inference.parameter.RealParameter;
Expand Down Expand Up @@ -187,5 +188,20 @@ private Operator createBitFlipOperator(BooleanParameter parameter) {
return operator;
}


//*** static methods ***//

// when both mu and tree are random var
public static void addUpDownOperator(Tree tree, RealParameter clockRate, BEASTContext context) {
String idStr = clockRate.getID() + "Up" + tree.getID() + "DownOperator";
// avoid to duplicate updown ops from the same pair of rate and tree
if (!context.hasExtraOperator(idStr)) {
BactrianUpDownOperator upDownOperator = new BactrianUpDownOperator();
upDownOperator.setID(idStr);
upDownOperator.setInputValue("up", clockRate);
upDownOperator.setInputValue("down", tree);
upDownOperator.setInputValue("scaleFactor", 0.9);
upDownOperator.setInputValue("weight", BEASTContext.getOperatorWeight(tree.getInternalNodeCount()+1));
context.addExtraOperator(upDownOperator);
}
}
}

0 comments on commit 8ac4505

Please sign in to comment.