Example usage for org.apache.commons.math3.linear LUDecomposition LUDecomposition

List of usage examples for org.apache.commons.math3.linear LUDecomposition LUDecomposition

Introduction

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

Prototype

public LUDecomposition(RealMatrix matrix) 

Source Link

Document

Calculates the LU-decomposition of the given matrix.

Usage

From source file:Matrix_Operations.java

public static void main(String[] args) {

    Scanner keyboard = new Scanner(System.in);

    //Allow user to enter number of columns
    int rows = getRowsNumberFromUser();
    int columns = getColumnNumberFromUser();
    double matrixA[][] = new double[rows][columns];

    //Enter values for matrix
    System.out.println("Enter values for each position in the matrix below. ");
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < columns; j++) {
            matrixA[i][j] = keyboard.nextDouble();

        }/*from   www .j av a  2  s.  c o m*/
        System.out.println("");
    }

    showMatrix(matrixA);
    System.out.println("");
    RealMatrix A = MatrixUtils.createRealMatrix(matrixA);

    LUDecomposition lu = new LUDecomposition(A);

    showMatrix(matrixA);

    System.out.println(lu.getDeterminant());

}

From source file:com.opengamma.strata.math.impl.linearalgebra.LUDecompositionCommons.java

@Override
public LUDecompositionResult apply(DoubleMatrix x) {
    ArgChecker.notNull(x, "x");
    RealMatrix temp = CommonsMathWrapper.wrap(x);
    LUDecomposition lu = new LUDecomposition(temp);
    return new LUDecompositionCommonsResult(lu);
}

From source file:com.itemanalysis.psychometrics.polycor.PolychoricTwoStepVariance.java

public double[][] variance(double[] x) {
    RealMatrix m = this.hessianAt(x);
    LUDecomposition SLUD = new LUDecomposition(m);
    RealMatrix inv = SLUD.getSolver().getInverse();
    return inv.getData();
}

From source file:io.warp10.script.functions.INV.java

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {

    Object o = stack.pop();//  ww  w  .ja  v  a  2s  .  com

    if (!(o instanceof RealMatrix)) {
        throw new WarpScriptException(getName() + " expects a matrix on top of the stack.");
    }

    RealMatrix matrix = (RealMatrix) o;

    stack.push(new LUDecomposition(matrix).getSolver().getInverse());

    return stack;
}

From source file:io.warp10.script.functions.DET.java

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {

    Object o = stack.pop();// www . ja v a 2  s . c o m

    if (!(o instanceof RealMatrix)) {
        throw new WarpScriptException(getName() + " expects a matrix on top of the stack.");
    }

    RealMatrix matrix = (RealMatrix) o;

    stack.push(new LUDecomposition(matrix).getDeterminant());

    return stack;
}

From source file:com.github.thorbenlindhauer.math.MathUtil.java

protected void ensureLUDecompositionInitialized() {
    if (luDecomposition == null) {
        luDecomposition = new LUDecomposition(matrix);
    }
}

From source file:com.itemanalysis.psychometrics.cfa.MaximumLikelihoodEstimation.java

public MaximumLikelihoodEstimation(ConfirmatoryFactorAnalysisModel model, RealMatrix varcov,
        double numberOfExaminees) {
    super(model, varcov, numberOfExaminees);
    CVLUD = new LUDecomposition(varcov);
    detVc = CVLUD.getDeterminant();//from  ww w  . ja v  a 2s  .  co m
}

From source file:imagingbook.lib.math.MahalanobisDistance.java

public MahalanobisDistance(double[][] samples) {
    N = samples.length;/*  w w w . j ava  2 s  .  com*/
    K = samples[0].length;
    Covariance cov = new Covariance(samples);
    RealMatrix S = cov.getCovarianceMatrix();
    // condition the covariance matrix to avoid singularity 
    // (add a small quantity to the diagonal)
    for (int i = 0; i < K; i++) {
        S.addToEntry(i, i, 0.0001);
    }
    // get the inverse covariance matrix
    RealMatrix iSM = new LUDecomposition(S).getSolver().getInverse();
    iS = iSM.getData();
}

From source file:com.opengamma.strata.math.impl.matrix.CommonsMatrixAlgebra.java

@Override
public double getDeterminant(Matrix m) {
    ArgChecker.notNull(m, "m");
    if (m instanceof DoubleMatrix) {
        RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix) m);
        LUDecomposition lud = new LUDecomposition(temp);
        return lud.getDeterminant();
    }//www .  j av a  2s.c o  m
    throw new IllegalArgumentException("Can only find determinant of DoubleMatrix; have " + m.getClass());
}

From source file:com.itemanalysis.psychometrics.mixture.MvNormalComponentDistribution.java

/**
 *
 * @param x a matrix of dimension 1 x k, where k is the number of variables
 * @return/*from  w  w  w  .java2  s  . co m*/
 */
public double density(RealMatrix x) throws SingularMatrixException {
    double prob = 0.0;
    RealMatrix xTran = x.transpose();
    int d = xTran.getRowDimension();
    double det = new LUDecomposition(sigma).getDeterminant();
    double nconst = 1.0 / Math.sqrt(det * Math.pow(2.0 * Math.PI, d));
    RealMatrix Sinv = new LUDecomposition(sigma).getSolver().getInverse();
    RealMatrix delta = xTran.subtract(mu);
    RealMatrix dist = (delta.transpose().multiply(Sinv).multiply(delta));
    prob = nconst * Math.exp(-0.5 * dist.getEntry(0, 0));
    return prob;
}