List of usage examples for org.apache.commons.math3.linear RealMatrix getColumnDimension
int getColumnDimension();
From source file:edu.ucdenver.bios.powersvc.resource.PowerResourceHelper.java
/** * Create a sigma covariate matrix from the study design. * @param studyDesign study design object * @return sigma covariate matrix// w w w . j a v a 2 s.c o m */ public static RealMatrix sigmaCovariateMatrixFromStudyDesign(StudyDesign studyDesign) { if (studyDesign.getViewTypeEnum() == StudyDesignViewTypeEnum.MATRIX_MODE) { return toRealMatrix(studyDesign.getNamedMatrix(PowerConstants.MATRIX_SIGMA_GAUSSIAN)); } else { // in Guided Mode, the user specifies this as a standard deviation, so we square it RealMatrix sigmaG = toRealMatrix(studyDesign.getNamedMatrix(PowerConstants.MATRIX_SIGMA_GAUSSIAN)); if (sigmaG != null && sigmaG.getRowDimension() > 0 && sigmaG.getColumnDimension() > 0) { double stddev = sigmaG.getEntry(0, 0); sigmaG.setEntry(0, 0, stddev * stddev); } return sigmaG; } }
From source file:edu.cmu.tetrad.util.MatrixUtils.java
public static RealMatrix transposeWithoutCopy(final RealMatrix apacheData) { return new AbstractRealMatrix(apacheData.getColumnDimension(), apacheData.getRowDimension()) { @Override/*from w w w . j a va2 s .com*/ public int getRowDimension() { return apacheData.getColumnDimension(); } @Override public int getColumnDimension() { return apacheData.getRowDimension(); } @Override public RealMatrix createMatrix(int rowDimension, int columnDimension) throws NotStrictlyPositiveException { return apacheData.createMatrix(rowDimension, columnDimension); } @Override public RealMatrix copy() { throw new IllegalArgumentException("Can't copy"); } @Override public double getEntry(int i, int j) throws OutOfRangeException { // throw new UnsupportedOperationException(); return apacheData.getEntry(j, i); } @Override public void setEntry(int i, int j, double v) throws OutOfRangeException { throw new UnsupportedOperationException(); } }; }
From source file:edu.cmu.tetrad.util.MatrixUtils1.java
public static double[][] pseudoInverse(double[][] x) { SingularValueDecomposition svd = new SingularValueDecomposition(new BlockRealMatrix(x)); RealMatrix U = svd.getU();/*from ww w . j a va 2 s. co m*/ RealMatrix V = svd.getV(); RealMatrix S = svd.getS(); for (int i = 0; i < S.getRowDimension(); i++) { for (int j = 0; j < S.getColumnDimension(); j++) { double v = S.getEntry(i, j); S.setEntry(i, j, v == 0 ? 0.0 : 1.0 / v); } } return V.multiply(S.multiply(U.transpose())).getData(); }
From source file:com.itemanalysis.psychometrics.factoranalysis.QuartiminCriteria.java
public void computeValues(RealMatrix L) { int k = L.getColumnDimension(); int p = L.getRowDimension(); RealMatrix I = new IdentityMatrix(p); RealMatrix L2 = MatrixUtils.multiplyElements(L, L); RealMatrix N = new Array2DRowRealMatrix(k, k); N.walkInRowOrder(new DefaultRealMatrixChangingVisitor() { @Override/*from ww w . j a va 2 s . c o m*/ public double visit(int row, int column, double value) { if (row == column) return 0.0; return 1.0; } }); RealMatrix X = L2.multiply(N); double sum = MatrixUtils.sumMatrix(MatrixUtils.multiplyElements(L2, X)); functionValue = sum / 4.0; gradient = MatrixUtils.multiplyElements(L, X); }
From source file:com.itemanalysis.psychometrics.measurement.DiagonalMatrix.java
/** * Extracts the diagonal elements from a matrix. * * @param matrix a matrix from which teh diagonal elements are extracted. *///from www . ja v a 2 s. c o m public DiagonalMatrix(RealMatrix matrix) { super(matrix.getColumnDimension(), matrix.getColumnDimension()); int ncol = matrix.getColumnDimension(); for (int i = 0; i < ncol; i++) { for (int j = 0; j < ncol; j++) { if (i == j) { this.setEntry(i, j, matrix.getEntry(i, j)); } else { this.setEntry(i, j, 0.0); } } } }
From source file:com.itemanalysis.psychometrics.statistics.MatrixToVector.java
public MatrixToVector(RealMatrix matrix) { this.matrix = matrix; numEelements = (int) ((matrix.getColumnDimension() * (matrix.getColumnDimension() + 1)) / 2.0); realVector = new Array2DRowRealMatrix(numEelements, 1); }
From source file:com.caseystella.analytics.outlier.batch.rpca.RidgeRegression.java
private double[] getDiagonal(RealMatrix X) { double[] diag = new double[X.getColumnDimension()]; for (int i = 0; i < diag.length; i++) { diag[i] = X.getEntry(i, i);/*from w ww .ja v a2 s .c om*/ } return diag; }
From source file:com.itemanalysis.psychometrics.factoranalysis.ObliminCriteria.java
public void computeValues(RealMatrix L) { final int k = L.getColumnDimension(); final int p = L.getRowDimension(); RealMatrix I = new IdentityMatrix(p); RealMatrix L2 = MatrixUtils.multiplyElements(L, L); RealMatrix N = new Array2DRowRealMatrix(k, k); N.walkInRowOrder(new DefaultRealMatrixChangingVisitor() { @Override//from w w w .j a v a 2 s . c o m public double visit(int row, int column, double value) { if (row == column) return 0.0; return 1.0; } }); RealMatrix C = new Array2DRowRealMatrix(p, p); C.walkInRowOrder(new DefaultRealMatrixChangingVisitor() { @Override public double visit(int row, int column, double value) { return gam / (double) p; } }); RealMatrix X = I.subtract(C).multiply(L2).multiply(N); double sum = MatrixUtils.sumMatrix(MatrixUtils.multiplyElements(L2, X)); functionValue = sum / 4.0; gradient = MatrixUtils.multiplyElements(L, X); }
From source file:io.warp10.script.functions.TOVEC.java
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { Object o = stack.pop();/*from w w w . j a va2s . c o m*/ if (o instanceof RealMatrix) { RealMatrix matrix = (RealMatrix) o; if (1 != matrix.getColumnDimension()) { throw new WarpScriptException( getName() + " expects a matrix with a single column on top of the stack."); } RealVector vector = matrix.getColumnVector(0); stack.push(vector); return stack; } if (!(o instanceof List)) { throw new WarpScriptException(getName() + " expects a list onto the stack."); } double[] data = new double[((List) o).size()]; for (int i = 0; i < data.length; i++) { Object oo = ((List) o).get(i); if (!(oo instanceof Number)) { throw new WarpScriptException(getName() + " expects a list of numbers onto the stack."); } data[i] = ((Number) oo).doubleValue(); } stack.push(MatrixUtils.createRealVector(data)); return stack; }
From source file:com.clust4j.algo.preprocess.MedianCenterer.java
@Override public MedianCenterer fit(RealMatrix X) { synchronized (fitLock) { final int n = X.getColumnDimension(); // need to mean center... this.medians = new double[n]; final double[][] y = X.transpose().getData(); // First pass, compute median... for (int j = 0; j < n; j++) { this.medians[j] = VecUtils.median(y[j]); }//from w w w .j av a 2 s .co m return this; } }