Example usage for org.apache.commons.math3.linear FieldMatrix getRowDimension

List of usage examples for org.apache.commons.math3.linear FieldMatrix getRowDimension

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear FieldMatrix getRowDimension.

Prototype

int getRowDimension();

Source Link

Document

Returns the number of rows in the matrix.

Usage

From source file:org.rhwlab.BHCnotused.GaussianGIWPrior.java

public void init() {
    int n = data.size();
    int d = m.getDimension();
    Dfp rP = r.add(n);//from www  .  j  a va 2s  .co  m
    //        System.out.printf("rP=%s\n",rP.toString());
    double nuP = nu + n;
    //        System.out.printf("nuP=%e\n", nuP);
    FieldMatrix C = new Array2DRowFieldMatrix(field, d, d);
    for (int row = 0; row < C.getRowDimension(); ++row) {
        for (int col = 0; col < C.getColumnDimension(); ++col) {
            C.setEntry(row, col, field.getZero());
        }
    }
    FieldVector X = new ArrayFieldVector(field, d); // a vector of zeros

    for (FieldVector v : data) {
        X = X.add(v);
        FieldMatrix v2 = v.outerProduct(v);
        C = C.add(v2);
    }
    FieldVector mP = (m.mapMultiply(r).add(X)).mapDivide(r.add(n));
    FieldMatrix Sp = C.add(S);

    FieldMatrix rmmP = mP.outerProduct(mP).scalarMultiply(rP);
    Sp = Sp.add(rmm).subtract(rmmP);

    FieldLUDecomposition ed = new FieldLUDecomposition(Sp);
    Dfp det = (Dfp) ed.getDeterminant();

    Dfp detSp = det.pow(field.newDfp(nuP / 2.0));

    Dfp gamma = field.getOne();

    Dfp gammaP = field.getOne();

    for (int i = 1; i <= d; ++i) {
        gamma = gamma.multiply(Gamma.gamma((nu + 1 - i) / 2.0));
        gammaP = gammaP.multiply(Gamma.gamma((nuP + 1 - i) / 2.0));
    }

    Dfp t1 = field.getPi().pow(-n * d / 2.0);
    Dfp t2 = r.divide(rP).pow(d / 2.0);
    Dfp t3 = detS.divide(detSp);

    Dfp t4 = gammaP.divide(gamma);
    Dfp t34 = t3.multiply(t4);
    /*        
            System.out.printf("detSp=%s\n", detSp.toString());
            System.out.printf("det=%s\n", det.toString());
            System.out.printf("gamma=%s\n", gamma.toString());
            System.out.printf("gammaP=%s\n", gammaP.toString());        
            System.out.printf("t1=%s\n", t1.toString());  
            System.out.printf("t2=%s\n", t2.toString());
            System.out.printf("t3=%s\n", t3.toString());
            System.out.printf("t4=%s\n", t4.toString());
    */
    likelihood = t2.multiply(t34).multiply(t1);
    double realLike = likelihood.getReal();
    //       System.out.printf("Likelihood=%e\n", realLike);
    int uhfd = 0;
}