use of dr.inference.smc.SMCOptions in project beast-mcmc by beast-dev.
the class MCMCParser method parseSMC.
/**
* Parse the SMC variant of MCMC.
* @param xo the XML object
* @return the SMC object
* @throws XMLParseException an exception of there is an XML parse error
*/
private SMC parseSMC(String id, XMLObject xo) throws XMLParseException {
List<StateLoaderSaver> particleStates = new ArrayList<StateLoaderSaver>();
String particleFolder = System.getProperty("smc.particle_folder");
File folder = new File(particleFolder);
if (!folder.isDirectory()) {
throw new XMLParseException("Specified particle folder is not a folder");
}
File[] particleFiles = folder.listFiles();
if (particleFiles == null || particleFiles.length == 0) {
throw new XMLParseException("Specified particle folder is empty");
}
for (final File particleFile : particleFiles) {
if (particleFile.isFile() && particleFile.getName().endsWith(".part")) {
final File saveFile = new File(particleFile.getAbsolutePath() + ".out");
particleStates.add(Factory.INSTANCE.getStateLoaderSaver(particleFile, saveFile));
}
}
if (particleStates.size() == 0) {
throw new XMLParseException("No particle files were found in the folder");
}
SMC smc = new SMC(id, particleStates);
long chainLength = xo.getLongIntegerAttribute(CHAIN_LENGTH);
SMCOptions options = new SMCOptions(chainLength);
OperatorSchedule opsched = (OperatorSchedule) xo.getChild(OperatorSchedule.class);
Likelihood likelihood = (Likelihood) xo.getChild(Likelihood.class);
likelihood.setUsed();
ArrayList<Logger> loggers = new ArrayList<Logger>();
for (int i = 0; i < xo.getChildCount(); i++) {
Object child = xo.getChild(i);
if (child instanceof Logger) {
loggers.add((Logger) child);
}
}
Logger[] loggerArray = new Logger[loggers.size()];
loggers.toArray(loggerArray);
java.util.logging.Logger.getLogger("dr.inference").info("\nCreating the SMC chain set:" + "\n particles = " + particleStates.size() + "\n chain length = " + options.getChainLength());
smc.init(options, likelihood, opsched, loggerArray);
return smc;
}
Aggregations