Search in sources :

Example 1 with DiagonalMatrix

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

the class FactorOperatorParser 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 FactorOperator(LFM, weight, randomScan, diffusionMatrix, scaleFactor, mode);
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) FactorOperator(dr.inference.operators.FactorOperator) LatentFactorModel(dr.inference.model.LatentFactorModel) CoercionMode(dr.inference.operators.CoercionMode)

Example 2 with DiagonalMatrix

use of dr.inference.model.DiagonalMatrix 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.FactorGibbsOperator)

Example 3 with DiagonalMatrix

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

the class LatentFactorLiabilityGibbsOperator method doUnorderedOperation.

void doUnorderedOperation() {
    double[] LxF = lfm.getLxF();
    DiagonalMatrix colPrec = (DiagonalMatrix) lfm.getColumnPrecision();
    Parameter continuous = lfm.getContinuous();
    MatrixParameterInterface lfmData = lfm.getScaledData();
    for (int i = 0; i < lfmData.getColumnDimension(); i++) {
        int LLpointer = 0;
        int[] data = liabilityLikelihood.getData(i);
        for (int index = 0; index < data.length; ++index) {
            int datum = data[index];
            Parameter numClasses = liabilityLikelihood.numClasses;
            int dim = (int) numClasses.getParameterValue(index);
            if (datum >= dim && continuous.getParameterValue(LLpointer) == 0) {
                double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + LLpointer], colPrec.getParameterValue(LLpointer, LLpointer), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
                lfmData.setParameterValue(LLpointer, i, draw);
            }
            if (dim == 1.0) {
                if (continuous.getParameterValue(LLpointer) == 0) {
                    double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + LLpointer], colPrec.getParameterValue(LLpointer, LLpointer), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
                    lfmData.setParameterValue(LLpointer, i, draw);
                }
                LLpointer++;
            } else if (dim == 2.0) {
                if (datum == 0) {
                    double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + LLpointer], colPrec.getParameterValue(LLpointer, LLpointer), Double.NEGATIVE_INFINITY, 0);
                    lfmData.setParameterValue(LLpointer, i, draw);
                } else {
                    double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + LLpointer], colPrec.getParameterValue(LLpointer, LLpointer), 0, Double.POSITIVE_INFINITY);
                    lfmData.setParameterValue(LLpointer, i, draw);
                }
                LLpointer++;
            } else {
                double[] trait = new double[dim];
                trait[0] = 0.0;
                if (datum == 0) {
                    for (int l = 0; l < dim - 1; l++) {
                        lfmData.setParameterValue(LLpointer + l, i, drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + (LLpointer + l)], colPrec.getParameterValue((LLpointer + l), (LLpointer + l)), Double.NEGATIVE_INFINITY, 0));
                    }
                } else {
                    trait[datum] = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + (LLpointer + datum - 1)], colPrec.getParameterValue((LLpointer + datum - 1), (LLpointer + datum - 1)), 0, Double.POSITIVE_INFINITY);
                    lfmData.setParameterValue(LLpointer + datum - 1, i, trait[datum]);
                    for (int l = 1; l < dim; l++) {
                        if (l != datum) {
                            //                                System.out.println("Free Rolls");
                            //                                System.out.println(LxF[i * lfmData.getRowDimension() + (LLpointer + l - 1)]);
                            trait[l] = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + (LLpointer + l - 1)], colPrec.getParameterValue((LLpointer + l - 1), (LLpointer + l - 1)), Double.NEGATIVE_INFINITY, trait[datum]);
                            lfmData.setParameterValue(LLpointer + l - 1, i, trait[l]);
                        }
                    }
                //                        double max = Double.NEGATIVE_INFINITY;
                //                        for (int j = 0; j < trait.length; j++) {
                //                            if(max < trait[j]){
                //                                max = trait[j];
                //                            }
                //                        }
                //                        System.out.println("Constrained");
                //                        System.out.println(LxF[i * lfmData.getRowDimension() + (LLpointer + datum - 1)]);
                }
                //                    valid = isMax(trait, datum);
                LLpointer += dim - 1;
            }
        }
    }
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) Parameter(dr.inference.model.Parameter)

Example 4 with DiagonalMatrix

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

the class LatentFactorLiabilityGibbsOperator method doOrderedOperation.

void doOrderedOperation() {
    double[] LxF = lfm.getLxF();
    DiagonalMatrix colPrec = (DiagonalMatrix) lfm.getColumnPrecision();
    Parameter continuous = lfm.getContinuous();
    MatrixParameterInterface lfmData = lfm.getScaledData();
    Parameter threshold = liabilityLikelihood.getThreshold();
    for (int i = 0; i < lfmData.getColumnDimension(); i++) {
        int Thresholdpointer = 0;
        int[] data = liabilityLikelihood.getData(i);
        for (int index = 0; index < data.length; ++index) {
            int datum = data[index];
            Parameter numClasses = liabilityLikelihood.numClasses;
            int dim = (int) numClasses.getParameterValue(index);
            if (datum >= dim && continuous.getParameterValue(index) == 0) {
                double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + index], colPrec.getParameterValue(index, index), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
                lfmData.setParameterValue(index, i, draw);
            } else {
                if (dim == 1.0) {
                    if (continuous.getParameterValue(index) == 0) {
                        double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + index], colPrec.getParameterValue(index, index), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
                        lfmData.setParameterValue(index, i, draw);
                    }
                } else if (dim == 2.0) {
                    if (datum == 0) {
                        double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + index], colPrec.getParameterValue(index, index), Double.NEGATIVE_INFINITY, 0);
                        lfmData.setParameterValue(index, i, draw);
                    } else {
                        double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + index], colPrec.getParameterValue(index, index), 0, Double.POSITIVE_INFINITY);
                        lfmData.setParameterValue(index, i, draw);
                    }
                } else {
                    double[] thresholdList = new double[dim + 1];
                    thresholdList[0] = Double.NEGATIVE_INFINITY;
                    thresholdList[1] = 0;
                    thresholdList[dim] = Double.POSITIVE_INFINITY;
                    for (int j = 0; j < thresholdList.length - 3; j++) {
                        thresholdList[j + 2] = threshold.getParameterValue(Thresholdpointer + j);
                    }
                    Thresholdpointer += dim - 2;
                    double draw = drawTruncatedNormalDistribution(LxF[i * lfmData.getRowDimension() + index], colPrec.getParameterValue(index, index), thresholdList[datum], thresholdList[datum + 1]);
                    lfmData.setParameterValue(index, i, draw);
                }
            }
        //                    valid = isMax(trait, datum);
        }
    }
}
Also used : DiagonalMatrix(dr.inference.model.DiagonalMatrix) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface) Parameter(dr.inference.model.Parameter)

Example 5 with DiagonalMatrix

use of dr.inference.model.DiagonalMatrix 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)

Aggregations

DiagonalMatrix (dr.inference.model.DiagonalMatrix)5 LatentFactorModel (dr.inference.model.LatentFactorModel)3 MatrixParameterInterface (dr.inference.model.MatrixParameterInterface)2 Parameter (dr.inference.model.Parameter)2 CoercionMode (dr.inference.operators.CoercionMode)2 FactorGibbsOperator (dr.inference.operators.FactorGibbsOperator)1 FactorIndependenceOperator (dr.inference.operators.FactorIndependenceOperator)1 FactorOperator (dr.inference.operators.FactorOperator)1