Search in sources :

Example 11 with LatentFactorModel

use of dr.inference.model.LatentFactorModel in project beast-mcmc by beast-dev.

the class FactorIndependenceOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    CoercionMode mode = CoercionMode.parseMode(xo);
    String scaleFactorTemp = (String) xo.getAttribute(SCALE_FACTOR);
    double scaleFactor = Double.parseDouble(scaleFactorTemp);
    String weightTemp = (String) xo.getAttribute(WEIGHT);
    double weight = Double.parseDouble(weightTemp);
    DiagonalMatrix diffusionMatrix;
    diffusionMatrix = (DiagonalMatrix) xo.getChild(DiagonalMatrix.class);
    LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
    return new FactorIndependenceOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) FactorIndependenceOperator(dr.inference.operators.FactorIndependenceOperator) LatentFactorModel(dr.inference.model.LatentFactorModel) CoercionMode(dr.inference.operators.CoercionMode)

Example 12 with LatentFactorModel

use of dr.inference.model.LatentFactorModel in project beast-mcmc by beast-dev.

the class LoadingsHamiltonianMCParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    LatentFactorModel lfm = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    MomentDistributionModel prior = (MomentDistributionModel) xo.getChild(MomentDistributionModel.class);
    double weight = xo.getDoubleAttribute(WEIGHT);
    AdaptationMode mode = AdaptationMode.parseMode(xo);
    int nSteps = xo.getIntegerAttribute(N_STEPS);
    double stepSize = xo.getDoubleAttribute(STEP_SIZE);
    double momentumSd = xo.getDoubleAttribute(MOMENTUM_SD);
    MatrixParameter loadings = (MatrixParameter) xo.getChild(MatrixParameter.class);
    return new LoadingsHamiltonianMC(lfm, prior, weight, mode, stepSize, nSteps, momentumSd, loadings);
}
Also used : AdaptationMode(dr.inference.operators.AdaptationMode) MatrixParameter(dr.inference.model.MatrixParameter) LatentFactorModel(dr.inference.model.LatentFactorModel) MomentDistributionModel(dr.inference.distribution.MomentDistributionModel)

Example 13 with LatentFactorModel

use of dr.inference.model.LatentFactorModel in project beast-mcmc by beast-dev.

the class FactorGibbsOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String weightTemp = (String) xo.getAttribute(WEIGHT);
    double weight = Double.parseDouble(weightTemp);
    DiagonalMatrix diffusionMatrix;
    diffusionMatrix = (DiagonalMatrix) xo.getChild(DiagonalMatrix.class);
    LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
    return new FactorGibbsOperator(LFM, weight, randomScan, diffusionMatrix);
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) LatentFactorModel(dr.inference.model.LatentFactorModel) FactorGibbsOperator(dr.inference.operators.factorAnalysis.FactorGibbsOperator)

Example 14 with LatentFactorModel

use of dr.inference.model.LatentFactorModel in project beast-mcmc by beast-dev.

the class FactorOperatorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    AdaptationMode mode = AdaptationMode.parseMode(xo);
    String scaleFactorTemp = (String) xo.getAttribute(SCALE_FACTOR);
    double scaleFactor = Double.parseDouble(scaleFactorTemp);
    String weightTemp = (String) xo.getAttribute(WEIGHT);
    double weight = Double.parseDouble(weightTemp);
    DiagonalMatrix diffusionMatrix;
    diffusionMatrix = (DiagonalMatrix) xo.getChild(DiagonalMatrix.class);
    LatentFactorModel LFM = (LatentFactorModel) xo.getChild(LatentFactorModel.class);
    boolean randomScan = xo.getAttribute(RANDOM_SCAN, true);
    return new FactorOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
Also used : AdaptationMode(dr.inference.operators.AdaptationMode) DiagonalMatrix(dr.inference.model.DiagonalMatrix) FactorOperator(dr.inference.operators.factorAnalysis.FactorOperator) LatentFactorModel(dr.inference.model.LatentFactorModel)

Example 15 with LatentFactorModel

use of dr.inference.model.LatentFactorModel 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);
    }
}
Also used : MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) NewLoadingsGibbsOperator(dr.inference.operators.factorAnalysis.NewLoadingsGibbsOperator) TreeDataLikelihood(dr.evomodel.treedatalikelihood.TreeDataLikelihood) FactorAnalysisOperatorAdaptor(dr.inference.operators.factorAnalysis.FactorAnalysisOperatorAdaptor) LatentFactorModel(dr.inference.model.LatentFactorModel) MomentDistributionModel(dr.inference.distribution.MomentDistributionModel) IntegratedFactorAnalysisLikelihood(dr.evomodel.treedatalikelihood.continuous.IntegratedFactorAnalysisLikelihood) DistributionLikelihood(dr.inference.distribution.DistributionLikelihood) LoadingsGibbsTruncatedOperator(dr.inference.operators.factorAnalysis.LoadingsGibbsTruncatedOperator)

Aggregations

LatentFactorModel (dr.inference.model.LatentFactorModel)17 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)6 DiagonalMatrix (dr.inference.model.DiagonalMatrix)6 AdaptationMode (dr.inference.operators.AdaptationMode)5 MomentDistributionModel (dr.inference.distribution.MomentDistributionModel)3 CoercionMode (dr.inference.operators.CoercionMode)3 OrderedLatentLiabilityLikelihood (dr.evomodel.continuous.OrderedLatentLiabilityLikelihood)2 MatrixParameterInterface (dr.inference.model.MatrixParameterInterface)2 FullyConjugateMultivariateTraitLikelihood (dr.evomodel.continuous.FullyConjugateMultivariateTraitLikelihood)1 GibbsSampleFromTreeInterface (dr.evomodel.continuous.GibbsSampleFromTreeInterface)1 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)1 IntegratedFactorAnalysisLikelihood (dr.evomodel.treedatalikelihood.continuous.IntegratedFactorAnalysisLikelihood)1 MatrixParameter (dr.inference.model.MatrixParameter)1 FactorGibbsOperator (dr.inference.operators.FactorGibbsOperator)1 FactorIndependenceOperator (dr.inference.operators.FactorIndependenceOperator)1 FactorOperator (dr.inference.operators.FactorOperator)1 LatentFactorLiabilityGibbsOperator (dr.inference.operators.LatentFactorLiabilityGibbsOperator)1 LatentFactorModelPrecisionGibbsOperator (dr.inference.operators.LatentFactorModelPrecisionGibbsOperator)1 LoadingsGibbsOperator (dr.inference.operators.LoadingsGibbsOperator)1 LoadingsGibbsTruncatedOperator (dr.inference.operators.LoadingsGibbsTruncatedOperator)1