Skip to content

Commit

Permalink
add an example for CalibratedYule distribution #497
Browse files Browse the repository at this point in the history
  • Loading branch information
EvaLiyt committed Jun 19, 2024
1 parent 1660499 commit 1d567ac
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 6 additions & 0 deletions examples/birth-death/calibratedYule.lphy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
λ ~ LogNormal(meanlog=3.0, sdlog=1.0);
clade1TaxaNames = ["1","2","3"];
clade2TaxaNames = ["1","2","3"];
clade1MRCAAge ~ Uniform(lower=5, upper=8);
clade2MRCAAge ~ Uniform(lower=5, upper=8);
ψ ~ CalibratedYule(lambda=λ, n=16, cladeTaxa=[clade1TaxaNames,clade2TaxaNames], cladeMRCAAge=[clade1MRCAAge,clade2MRCAAge]);
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private int getTaxaLength(Value taxa) {
}

@GeneratorInfo(name = "CalibratedYule",
category = GeneratorCategory.BD_TREE,
category = GeneratorCategory.BD_TREE, examples = {"calibratedYule.lphy"},
description = "The CalibratedYule method accepts one or more clade taxa and generates a tip-labelled time tree. If a root age is provided, the method conditions the tree generation on this root age.")
@Override
public RandomVariable<TimeTree> sample() {
Expand Down Expand Up @@ -141,7 +141,6 @@ public RandomVariable<TimeTree> sample() {
// get a certain lambda for Yule coalescent
double lambda = (double) getBirthRate().value();

System.out.println("done initialising");
// coalescent
double t = 0.0;

Expand Down Expand Up @@ -174,7 +173,6 @@ public RandomVariable<TimeTree> sample() {
} else coalesceNodes(activeNodes, t);
}

System.out.println("done coalescent");
// set root to construct the tree
if (tree != null) {
tree.setRoot(activeNodes.get(0), true);
Expand All @@ -191,8 +189,7 @@ public RandomVariable<TimeTree> sample() {
}
}

System.out.println("calibrated yule tree is " + tree);
return new RandomVariable<>(null, tree, this);
return new RandomVariable<>("calibratedYuleTree", tree, this);
}

/**
Expand Down Expand Up @@ -350,20 +347,17 @@ private static TimeTreeNode randomNode(List<TimeTreeNode> nodeList) {
public Map<String, Value> getParams() {
Map<String, Value> map = super.getParams();
map.put(BirthDeathConstants.lambdaParamName, birthRate);
map.put(BirthDeathConstants.rootAgeParamName, rootAge);
map.put(cladeMRCAAgeName, cladeMRCAAge);
map.put(cladeTaxaName, cladeTaxaValue);
map.put(otherTaxaName,otherTaxa);
if (rootAge != null) map.put(BirthDeathConstants.rootAgeParamName, rootAge);
if (otherTaxa != null) map.put(otherTaxaName,otherTaxa);
return map;
}

public void setParam(String paramName, Value value){
if (paramName.equals(BirthDeathConstants.lambdaParamName)) birthRate = value;
else if (paramName.equals(BirthDeathConstants.rootAgeParamName)) rootAge = value;
else if (paramName.equals(cladeTaxaName)) {
cladeTaxaValue = value;
constructCladeTaxa();
}
else if (paramName.equals(cladeTaxaName)) cladeTaxaValue = value;
else if (paramName.equals(cladeMRCAAgeName)) cladeMRCAAge = value;
else if (paramName.equals(otherTaxaName)) otherTaxa = value;
else super.setParam(paramName, value);
Expand Down
2 changes: 1 addition & 1 deletion lphy-base/src/main/java/lphy/base/spi/LPhyBaseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public List<Class<? extends GenerativeDistribution>> declareDistributions() {
Uniform.class, UniformDiscrete.class, Weibull.class, WeightedDirichlet.class,
Multinomial.class,
// tree distribution
Yule.class, BirthDeathTree.class, FullBirthDeathTree.class, BirthDeathTreeDT.class,
Yule.class, CalibratedYule.class, BirthDeathTree.class, FullBirthDeathTree.class, BirthDeathTreeDT.class,
BirthDeathSamplingTree.class, BirthDeathSamplingTreeDT.class, BirthDeathSerialSamplingTree.class,
RhoSampleTree.class, FossilBirthDeathTree.class,
SimBDReverse.class, SimFBDAge.class, SimFossilsPoisson.class,
Expand Down

0 comments on commit 1d567ac

Please sign in to comment.