use of dr.inference.operators.factorAnalysis.NewLoadingsGibbsOperator in project beast-mcmc by beast-dev.
the class LoadingsGibbsOperatorParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
// Get XML attributes
double weight = xo.getDoubleAttribute(WEIGHT);
boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
int numThreads = xo.getAttribute(NUM_THREADS, 4);
boolean multiThreaded = xo.getAttribute(MULTI_THREADED, false);
boolean useNewMode = xo.getAttribute(MODE, false);
// Get main objects
LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
// TODO The next 3 lines are not necessary, nor in XML rules
MatrixParameterInterface loadings = null;
if (xo.getChild(MatrixParameterInterface.class) != null) {
loadings = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
}
// Get priors
DistributionLikelihood prior = (DistributionLikelihood) xo.getChild(DistributionLikelihood.class);
MomentDistributionModel prior2 = (MomentDistributionModel) xo.getChild(MomentDistributionModel.class);
DistributionLikelihood cutoffPrior = null;
if (xo.hasChildNamed(CUTOFF_PRIOR)) {
cutoffPrior = (DistributionLikelihood) xo.getChild(CUTOFF_PRIOR).getChild(DistributionLikelihood.class);
}
DistributionLikelihood WorkingPrior = null;
if (xo.getChild(WORKING_PRIOR) != null) {
WorkingPrior = (DistributionLikelihood) xo.getChild(WORKING_PRIOR).getChild(DistributionLikelihood.class);
}
// Dispatch
if (prior != null) {
if (useNewMode) {
final FactorAnalysisOperatorAdaptor adaptor;
if (LFM != null) {
adaptor = new FactorAnalysisOperatorAdaptor.SampledFactors(LFM);
} else {
IntegratedFactorAnalysisLikelihood integratedLikelihood = (IntegratedFactorAnalysisLikelihood) xo.getChild(IntegratedFactorAnalysisLikelihood.class);
TreeDataLikelihood treeLikelihood = (TreeDataLikelihood) xo.getChild(TreeDataLikelihood.class);
adaptor = new FactorAnalysisOperatorAdaptor.IntegratedFactors(integratedLikelihood, treeLikelihood);
}
NewLoadingsGibbsOperator.ConstrainedSampler sampler = NewLoadingsGibbsOperator.ConstrainedSampler.parse(xo.getAttribute(CONSTRAINT, NewLoadingsGibbsOperator.ConstrainedSampler.NONE.getName()));
return new NewLoadingsGibbsOperator(adaptor, prior, weight, randomScan, WorkingPrior, multiThreaded, numThreads, sampler);
} else {
// return new LoadingsGibbsOperator(LFM, prior, weight, randomScan, WorkingPrior, multiThreaded, numThreads);
return null;
}
} else {
return new LoadingsGibbsTruncatedOperator(LFM, prior2, weight, randomScan, loadings, cutoffPrior);
}
}
Aggregations