use of bacter.model.SimulatedACG in project bacter by tgvaughan.
the class AddRemoveConversionTest method testHR.
/**
* Tests that probability density of forward move calculated
* by drawNewConversion() matches probability density of backward
* move calculated by getConversionProb().
*
* @throws Exception
*/
@Test
public void testHR() throws Exception {
ConstantPopulation popFunc = new ConstantPopulation();
popFunc.initByName("popSize", new RealParameter("1.0"));
Locus locus = new Locus("locus", 10000);
TaxonSet taxonSet = getTaxonSet(10);
SimulatedACG acg = new SimulatedACG();
acg.initByName("rho", 1.0 / locus.getSiteCount(), "delta", 50.0, "locus", locus, "taxonset", taxonSet, "populationModel", popFunc);
AddRemoveConversion operator = new AddRemoveConversion();
// Loop until a valid proposal is made
double logP1;
List<Conversion> oldConversions;
do {
operator.initByName("weight", 1.0, "acg", acg, "delta", new RealParameter("50.0"), "populationModel", popFunc);
oldConversions = Lists.newArrayList(acg.getConversions(locus));
logP1 = operator.drawNewConversion();
} while (Double.isInfinite(logP1));
System.out.println("logP1 = " + logP1);
// Identify new recomination
Conversion newRecomb = null;
for (Conversion recomb : acg.getConversions(locus)) {
if (!oldConversions.contains(recomb))
newRecomb = recomb;
}
assertNotNull(newRecomb);
double logP2 = operator.getConversionProb(newRecomb);
System.out.println("logP2 = " + logP2);
assertTrue(Math.abs(logP1 - logP2) < 1e-10);
}
use of bacter.model.SimulatedACG in project bacter by tgvaughan.
the class AddRemoveConversionTest method testProbability.
/**
* Tests whether probability of proposing a conversion lines up with
* conversion probability found in ACGCoalescent.
* @throws java.lang.Exception
*/
@Test
public void testProbability() throws Exception {
ConstantPopulation popFunc = new ConstantPopulation();
popFunc.initByName("popSize", new RealParameter("1.0"));
Locus locus = new Locus("locus", 10000);
TaxonSet taxonSet = getTaxonSet(10);
SimulatedACG acg = new SimulatedACG();
acg.initByName("rho", 1.0 / locus.getSiteCount(), "delta", 50.0, "locus", locus, "taxonset", taxonSet, "populationModel", popFunc);
RealParameter rho = new RealParameter(Double.toString(1.0 / locus.getSiteCount()));
RealParameter delta = new RealParameter("50.0");
AddRemoveConversion operator = new AddRemoveConversion();
operator.initByName("weight", 1.0, "acg", acg, "delta", delta, "populationModel", popFunc);
ACGCoalescent coal = new ACGCoalescent();
coal.initByName("tree", acg, "populationModel", popFunc, "rho", rho, "delta", delta);
double logP1 = 0.0;
double logP2 = 0.0;
for (Conversion conv : acg.getConversions(locus)) {
logP1 += operator.getConversionProb(conv);
logP2 += coal.calculateConversionLogP(conv);
}
System.out.println("logP1 = " + logP1);
System.out.println("logP2 = " + logP2);
assertTrue(Math.abs(logP1 - logP2) < 1e-10);
}
use of bacter.model.SimulatedACG in project bacter by tgvaughan.
the class CustomConnectors method applyRestrictions.
public static void applyRestrictions(BeautiDoc doc) {
for (BEASTInterface p : doc.getPartitions("Tree")) {
ACGLikelihood acgLikelihood = (ACGLikelihood) p;
SimulatedACG acg = (SimulatedACG) ((ACGLikelihood) p).treeInput.get();
ACGCoalescent coalescent = null;
for (BEASTInterface output : acg.getOutputs()) {
if (output instanceof ACGCoalescent) {
coalescent = (ACGCoalescent) output;
break;
}
}
if (coalescent == null)
continue;
acg.setWholeLocusMode(coalescent.wholeLocusConversionsInput.get());
}
}
Aggregations