All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.maizegenetics.matrixalgebra.decomposition.EJMLSingularValueDecomposition Maven / Gradle / Ivy

Go to download

TASSEL is a software package to evaluate traits associations, evolutionary patterns, and linkage disequilibrium.

There is a newer version: 5.2.94
Show newest version
package net.maizegenetics.matrixalgebra.decomposition;

import org.ejml.data.DenseMatrix64F;
import org.ejml.factory.DecompositionFactory;
import org.ejml.ops.SingularOps;

import net.maizegenetics.matrixalgebra.Matrix.DoubleMatrix;
import net.maizegenetics.matrixalgebra.Matrix.DoubleMatrixFactory;
import net.maizegenetics.matrixalgebra.Matrix.EJMLDoubleMatrix;

public class EJMLSingularValueDecomposition implements
		SingularValueDecomposition {
	
	org.ejml.factory.SingularValueDecomposition myDecomposition;
	boolean successful;
	int rank = -1;

	public EJMLSingularValueDecomposition(DenseMatrix64F matrix) {
		myDecomposition = DecompositionFactory.svd(matrix.numRows, matrix.numCols, true, true, true);
		successful = myDecomposition.decompose(matrix);
	}
	
	@Override
	public DoubleMatrix getS() {
		double[] singularValues = myDecomposition.getSingularValues();
		return DoubleMatrixFactory.DEFAULT.diagonal(singularValues);
	}

	@Override
	public double[] getSingularValues() {
		return myDecomposition.getSingularValues();
	}

	@Override
	public DoubleMatrix getU(boolean transpose) {
		return new EJMLDoubleMatrix(myDecomposition.getU(null, transpose));
	}

	@Override
	public DoubleMatrix getV(boolean transpose) {
		return new EJMLDoubleMatrix(myDecomposition.getV(null, transpose));
	}
	
	boolean wasSuccessful() {
		return successful;
	}

	@Override
	public int getRank() {
		rank = SingularOps.rank(myDecomposition, 1e-12);
		return rank;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy