diff --git a/fxtemplates/SelfTuningMCMC.xml b/fxtemplates/SelfTuningMCMC.xml new file mode 100644 index 0000000..099beea --- /dev/null +++ b/fxtemplates/SelfTuningMCMC.xml @@ -0,0 +1,60 @@ + + +beastfx.app.inputeditor.BeautiConnector +beastfx.app.inputeditor.BeautiSubTemplate +beast.base.inference.distribution.Uniform +beast.base.inference.distribution.Normal +beast.base.inference.distribution.OneOnX +beast.base.inference.distribution.LogNormalDistributionModel +beast.base.inference.distribution.Exponential +beast.base.inference.distribution.Gamma +beast.base.inference.distribution.Beta +beast.base.inference.distribution.LaplaceDistribution +beast.base.inference.distribution.InverseGamma +beast.base.inference.distribution.Prior + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +]]> + + + + + + diff --git a/src/beastlabs/evolution/likelihood/SelfTuningCompoundDistribution.java b/src/beastlabs/evolution/likelihood/SelfTuningCompoundDistribution.java index e51eb22..e185f6c 100644 --- a/src/beastlabs/evolution/likelihood/SelfTuningCompoundDistribution.java +++ b/src/beastlabs/evolution/likelihood/SelfTuningCompoundDistribution.java @@ -23,6 +23,7 @@ import beast.base.evolution.branchratemodel.BranchRateModel; import beast.base.evolution.likelihood.BeagleTreeLikelihood.PartialsRescalingScheme; import beast.base.evolution.likelihood.GenericTreeLikelihood; +import beast.base.evolution.likelihood.ThreadedTreeLikelihood; import beast.base.evolution.likelihood.TreeLikelihood; import beast.base.evolution.sitemodel.SiteModel; import beast.base.evolution.tree.TreeInterface; @@ -55,7 +56,6 @@ public class SelfTuningCompoundDistribution extends Distribution { final public Input includeMPTLInput = new Input<>("includeMPTL", "include multi-partition (BEAGLE 3) tree likelihood in configurations", true); final public Input includeSPTLInput = new Input<>("includeSPTL", "include single-partition (BEAGLE 2) tree likelihood in configurations", true); - class Configuration { long nrOfSamples; @@ -210,6 +210,8 @@ public void initAndValidate() { initialMeasurement = true; switchTime = System.currentTimeMillis(); + + } @@ -235,7 +237,7 @@ private MultiPartitionTreeLikelihood createMultiPartitionTreeLikelihood() { tree = tl0.treeInput.get(); branchRateModel = tl0.branchRateModelInput.get(); useAmbiguities = (boolean) tl0.getInput("useAmbiguities").get(); - useTipLikelihoods = (boolean) tl0.getInput("useTipLikelihoods").get(); + useTipLikelihoods = tl0 instanceof TreeLikelihood ? (boolean) tl0.getInput("useTipLikelihoods").get() : false; rescalingScheme = MultiPartitionTreeLikelihood.getRescalingScheme(tl0); dataType = tl0.dataInput.get().getDataType().toString(); } else { @@ -263,7 +265,7 @@ private MultiPartitionTreeLikelihood createMultiPartitionTreeLikelihood() { tl.getID() + " and " + tl0.getID()+" -- MultiPartitionTreeLikelihood not considered"); return null; } - if (useTipLikelihoods != (boolean)tl.getInput("useTipLikelihoods").get()) { + if (tl instanceof TreeLikelihood && useTipLikelihoods != (boolean)tl.getInput("useTipLikelihoods").get()) { Log.warning("All partitions must use tip likelihoods, or ignore tip likelihoods, but found a difference between " + tl.getID() + " and " + tl0.getID() + " -- MultiPartitionTreeLikelihood not considered"); return null; diff --git a/src/beastlabs/evolution/likelihood/SelfTuningMCMC.java b/src/beastlabs/evolution/likelihood/SelfTuningMCMC.java index 4470c83..002da6e 100644 --- a/src/beastlabs/evolution/likelihood/SelfTuningMCMC.java +++ b/src/beastlabs/evolution/likelihood/SelfTuningMCMC.java @@ -5,24 +5,45 @@ import beast.base.core.BEASTInterface; import beast.base.core.Description; import beast.base.core.Input; +import beast.base.core.ProgramStatus; import beast.base.inference.CompoundDistribution; +import beast.base.inference.Logger; import beast.base.inference.MCMC; @Description("MCMC that can tune the treelikelihood for efficiency") public class SelfTuningMCMC extends MCMC { + final public Input useThreadsInput = new Input<>("useThreads", "calculated the distributions in parallel using threads (default true)-- only used if no SelfTuningCompoundDistribution specified.", true); + final public Input minNrOfThreadsInput = new Input<>("minThreads","minimum number of threads to use (default 1)-- only used if no SelfTuningCompoundDistribution specified.", 1); + final public Input maxNrOfThreadsInput = new Input<>("maxThreads","maximum number of threads to use, if less than 1 the number of threads in BeastMCMC is used (default -1)-- only used if no SelfTuningCompoundDistribution specified.", -1); + + final public Input swithcCountInput = new Input<>("switchCount", "number of milli seconds to calculate likelihood before switching configuration-- only used if no SelfTuningCompoundDistribution specified.", 500l); + final public Input reconfigCountInput = new Input<>("reconfigCount", "number of times to calculate likelihood before self tuning again-- only used if no SelfTuningCompoundDistribution specified.", 100000l); + final public Input stopAfterSamerResultsInput = new Input<>("stopAfterSamerResults", "number of times the same configuration is optimal in a row before stopping to tune-- only used if no SelfTuningCompoundDistribution specified.", 3); + + final public Input includeMPTLInput = new Input<>("includeMPTL", "include multi-partition (BEAGLE 3) tree likelihood in configurations-- only used if no SelfTuningCompoundDistribution specified.", true); + final public Input includeSPTLInput = new Input<>("includeSPTL", "include single-partition (BEAGLE 2) tree likelihood in configurations-- only used if no SelfTuningCompoundDistribution specified.", true); + + SelfTuningCompoundDistribution stCompoundDistribution; @Override public void initAndValidate() { - super.initAndValidate(); - stCompoundDistribution = findSTCompoundDistribution(posteriorInput.get()); - if (stCompoundDistribution == null) { - // no SelfTuningCompoundDistribution found, so replace CompoundDistribution with id="likelihood" - // with one - stCompoundDistribution = createdSTCompoundDistribution(posteriorInput.get()); + if (!ProgramStatus.name.equals("BEAUti")) { + stCompoundDistribution = findSTCompoundDistribution(posteriorInput.get()); + if (stCompoundDistribution == null) { + // no SelfTuningCompoundDistribution found, so replace CompoundDistribution with id="likelihood" + // with one + stCompoundDistribution = createdSTCompoundDistribution(posteriorInput.get()); + } + + for (Logger logger: loggersInput.get()) { + logger.initAndValidate(); + } } + + super.initAndValidate(); } private SelfTuningCompoundDistribution createdSTCompoundDistribution(BEASTInterface o) { @@ -30,7 +51,17 @@ private SelfTuningCompoundDistribution createdSTCompoundDistribution(BEASTInterf CompoundDistribution cd = (CompoundDistribution) o; // replace cd with SelfTuningCompoundDistribution SelfTuningCompoundDistribution stcd = new SelfTuningCompoundDistribution(); - stcd.initByName("distribution", cd.pDistributions.get(), "ignore", cd.ignoreInput.get()); + stcd.initByName("distribution", cd.pDistributions.get(), + "ignore", cd.ignoreInput.get(), + "useThreads", useThreadsInput.get(), + "minThreads",minNrOfThreadsInput.get(), + "maxThreads",maxNrOfThreadsInput.get(), + "switchCount",swithcCountInput.get(), + "reconfigCount",reconfigCountInput.get(), + "stopAfterSamerResults",stopAfterSamerResultsInput.get(), + "includeMPTL",includeMPTLInput.get(), + "includeSPTL",includeSPTLInput.get() + ); for (BEASTInterface out : cd.getOutputs()) { for (Input in : out.listInputs()) { if (in.get() instanceof List) { @@ -80,5 +111,5 @@ protected void callUserFunction(final long sample) { robustlyCalcPosterior(posterior); } } - + }