Search in sources :

Example 6 with MatrixParameterInterface

use of dr.inference.model.MatrixParameterInterface 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 7 with MatrixParameterInterface

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

the class DeterminentalPointProcessPriorParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    String name = xo.getName();
    double theta = xo.getDoubleAttribute(THETA);
    MatrixParameterInterface data = (MatrixParameterInterface) xo.getChild(MatrixParameterInterface.class);
    return new DeterminentalPointProcessPrior(name, theta, data);
}
Also used : DeterminentalPointProcessPrior(dr.inference.distribution.DeterminentalPointProcessPrior) MatrixParameterInterface(dr.inference.model.MatrixParameterInterface)

Example 8 with MatrixParameterInterface

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

the class LoadingsIndependenceOperator method getTruncatedMean.

private void getTruncatedMean(int newRowDimension, int dataColumn, double[][] variance, double[] midMean, double[] mean) {
    //        MatrixParameter answer=new MatrixParameter(null);
    //        answer.setDimensions(this.getRowDimension(), Right.getRowDimension());
    //        System.out.println(answer.getRowDimension());
    //        System.out.println(answer.getColumnDimension());
    MatrixParameterInterface data = LFM.getScaledData();
    MatrixParameterInterface Left = LFM.getFactors();
    int p = data.getColumnDimension();
    for (int i = 0; i < newRowDimension; i++) {
        double sum = 0;
        for (int k = 0; k < p; k++) sum += Left.getParameterValue(i, k) * data.getParameterValue(dataColumn, k);
        sum = sum * LFM.getColumnPrecision().getParameterValue(dataColumn, dataColumn);
        sum += priorMeanPrecision;
        midMean[i] = sum;
    }
    for (int i = 0; i < newRowDimension; i++) {
        double sum = 0;
        for (int k = 0; k < newRowDimension; k++) sum += variance[i][k] * midMean[k];
        mean[i] = sum;
    }
}
Also used : MatrixParameterInterface(dr.inference.model.MatrixParameterInterface)

Aggregations

MatrixParameterInterface (dr.inference.model.MatrixParameterInterface)8 DiagonalMatrix (dr.inference.model.DiagonalMatrix)2 Parameter (dr.inference.model.Parameter)2 DeterminentalPointProcessPrior (dr.inference.distribution.DeterminentalPointProcessPrior)1 DistributionLikelihood (dr.inference.distribution.DistributionLikelihood)1 MomentDistributionModel (dr.inference.distribution.MomentDistributionModel)1 CompoundParameter (dr.inference.model.CompoundParameter)1 LatentFactorModel (dr.inference.model.LatentFactorModel)1 LoadingsGibbsOperator (dr.inference.operators.LoadingsGibbsOperator)1 LoadingsGibbsTruncatedOperator (dr.inference.operators.LoadingsGibbsTruncatedOperator)1