當前位置: 首頁>>代碼示例>>Java>>正文


Java RealMatrix.getRowDimension方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.linear.RealMatrix.getRowDimension方法的典型用法代碼示例。如果您正苦於以下問題:Java RealMatrix.getRowDimension方法的具體用法?Java RealMatrix.getRowDimension怎麽用?Java RealMatrix.getRowDimension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.linear.RealMatrix的用法示例。


在下文中一共展示了RealMatrix.getRowDimension方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: apacheCommonsExample

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public void apacheCommonsExample() {
    double[][] A = {
        {0.1950, 0.0311},
        {0.3588, 0.2203},
        {0.1716, 0.5931},
        {0.2105, 0.3242}};

    double[][] B = {
        {0.0502, 0.9823, 0.9472},
        {0.5732, 0.2694, 0.916}};

    RealMatrix aRealMatrix = new Array2DRowRealMatrix(A);
    RealMatrix bRealMatrix = new Array2DRowRealMatrix(B);

    RealMatrix cRealMatrix = aRealMatrix.multiply(bRealMatrix);
    System.out.println();
    for (int i = 0; i < cRealMatrix.getRowDimension(); i++) {
        System.out.println(cRealMatrix.getRowVector(i));
    }
}
 
開發者ID:PacktPublishing,項目名稱:Machine-Learning-End-to-Endguide-for-Java-developers,代碼行數:21,代碼來源:MathExamples.java

示例2: multiplyElementWise

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix multiplyElementWise(final RealMatrix matrix1,
        final RealMatrix matrix2) {
    if (matrix1.getRowDimension() != matrix2.getRowDimension() || matrix1
            .getColumnDimension() != matrix2.getColumnDimension()) {
        throw new IllegalArgumentException(
                "The matrices must be of the same dimensions!");
    }

    final RealMatrix result = matrix1.createMatrix(
            matrix1.getRowDimension(), matrix1.getColumnDimension());

    for (int r = 0; r < matrix1.getRowDimension(); r++) {
        for (int c = 0; c < matrix1.getColumnDimension(); c++) {
            result.setEntry(r, c,
                    matrix1.getEntry(r, c) * matrix2.getEntry(r, c));
        }
    }

    return result;
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:21,代碼來源:MatrixFunctions.java

示例3: concatHorizontally

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix concatHorizontally(final RealMatrix left,
        final RealMatrix right) {
    if (left.getRowDimension() != right.getRowDimension()) {
        throw new IllegalArgumentException(
                "The matrices must have the same row dimension!");
    }

    final double[][] result =
            new double[left.getRowDimension()][left.getColumnDimension()
                    + right.getColumnDimension()];

    final int lc = left.getColumnDimension();

    for (int r = 0; r < left.getRowDimension(); r++) {
        for (int c = 0; c < left.getColumnDimension(); c++) {
            result[r][c] = left.getEntry(r, c);
        }
        for (int c = 0; c < right.getColumnDimension(); c++) {
            result[r][lc + c] = right.getEntry(r, c);
        }
    }

    return MatrixUtils.createRealMatrix(result);
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:25,代碼來源:MatrixFunctions.java

示例4: concatVertically

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix concatVertically(final RealMatrix top,
        final RealMatrix bottom) {
    if (top.getColumnDimension() != bottom.getColumnDimension()) {
        throw new IllegalArgumentException(
                "The matrices must have the same column dimension!");
    }

    final double[][] result = new double[top.getRowDimension()
            + bottom.getRowDimension()][top.getColumnDimension()];

    final int tr = top.getRowDimension();

    for (int c = 0; c < top.getColumnDimension(); c++) {
        for (int r = 0; r < top.getRowDimension(); r++) {
            result[r][c] = top.getEntry(r, c);
        }
        for (int r = 0; r < bottom.getRowDimension(); r++) {
            result[tr + r][c] = bottom.getEntry(r, c);
        }
    }

    return MatrixUtils.createRealMatrix(result);
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:24,代碼來源:MatrixFunctions.java

示例5: centerKernelMatrix

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
private static RealMatrix
        centerKernelMatrix(final RealMatrix kernelMatrix) {
    // get size of kernelMatrix
    final int n = kernelMatrix.getRowDimension();

    // get mean values for each row/column
    final RealVector columnMeans =
            MatrixFunctions.columnMeans(kernelMatrix);
    final double matrixMean = MatrixFunctions.mean(kernelMatrix);

    RealMatrix centeredKernelMatrix = kernelMatrix.copy();

    for (int k = 0; k < n; k++) {
        centeredKernelMatrix.setRowVector(k,
                centeredKernelMatrix.getRowVector(k).subtract(columnMeans));
        centeredKernelMatrix.setColumnVector(k, centeredKernelMatrix
                .getColumnVector(k).subtract(columnMeans));
    }

    centeredKernelMatrix = centeredKernelMatrix.scalarAdd(matrixMean);

    return centeredKernelMatrix;
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:24,代碼來源:KNFST.java

示例6: correlation2Distance

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix correlation2Distance(RealMatrix rMat) {

        // Copy to retain Dimensions
        RealMatrix dMat = rMat.copy();

        for (int row = 0; row < rMat.getRowDimension(); row++) {
            for (int col = 0; col < rMat.getColumnDimension(); col++) {
                double r = rMat.getEntry(row, col);

                //Apply cosine theorem:
                //https://stats.stackexchange.com/questions/165194/using-correlation-as-distance-metric-for-hierarchical-clustering
                double d = Math.sqrt(2*(1-r));
                dMat.setEntry(row, col, d);
            }
        }

        return dMat;
    }
 
開發者ID:jmueller95,項目名稱:CORNETTO,代碼行數:19,代碼來源:AnalysisData.java

示例7: printX

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private void printX(RealMatrix x, int iteration) {
    for (int i = 0; i < x.getRowDimension(); i++) {
        double value = x.getEntry(i, 0);
        System.out.print(value);
        if ( i < x.getRowDimension() - 1 ){
            System.out.print(',');
        }
    }
    System.out.print('\n');
}
 
開發者ID:hpiasg,項目名稱:asgdrivestrength,代碼行數:12,代碼來源:EqualDelayMatrixOptimizer.java

示例8: testSqrtMatrix

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
@Test
public void testSqrtMatrix() {
    final RealMatrix result = MatrixFunctions.sqrt(matrixA);
    for (int r = 0; r < result.getRowDimension(); r++) {
        for (int c = 0; c < result.getColumnDimension(); c++) {
            assertEquals(Math.sqrt(matrixA.getEntry(r, c)),
                    result.getEntry(r, c), 0);
        }
    }
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:11,代碼來源:MatrixFunctionsTest.java

示例9: testPow

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
@Test
public void testPow() {
    final RealMatrix result = MatrixFunctions.pow(matrixA, 2);
    for (int r = 0; r < result.getRowDimension(); r++) {
        for (int c = 0; c < result.getColumnDimension(); c++) {
            assertEquals(Math.pow(matrixA.getEntry(r, c), 2),
                    result.getEntry(r, c), 0);
        }
    }
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:11,代碼來源:MatrixFunctionsTest.java

示例10: squared_euclidean_distances

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
private RealMatrix squared_euclidean_distances(final RealMatrix x,
        final RealMatrix y) {
    final RealMatrix distmat = MatrixUtils
            .createRealMatrix(x.getRowDimension(), y.getRowDimension());

    for (int i = 0; i < x.getRowDimension(); i++) {
        for (int j = 0; j < y.getRowDimension(); j++) {
            final RealVector buff =
                    x.getRowVector(i).subtract(y.getRowVector(j));
            distmat.setEntry(i, j, buff.dotProduct(buff));
        }
    }

    return distmat;
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:16,代碼來源:MultiClassKNFST.java

示例11: printMatrix

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
/**
 * Helper method for printing a matrix
 *
 * @param matrix
 */
public void printMatrix(RealMatrix matrix) {
    for (int rowIndex = 0; rowIndex < matrix.getRowDimension(); rowIndex++) {
        double[] currentRow = matrix.getRow(rowIndex);
        for (int colIndex = 0; colIndex < matrix.getColumnDimension(); colIndex++) {
            System.out.printf("%.3f", matrix.getEntry(rowIndex, colIndex));
            System.out.print("\t");
        }
        System.out.println();
    }
}
 
開發者ID:jmueller95,項目名稱:CORNETTO,代碼行數:16,代碼來源:MyGraphTest.java

示例12: OneClassKNFST

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public OneClassKNFST(final RealMatrix kernelMatrix) throws KNFSTException {
    final int n = kernelMatrix.getRowDimension();

    // include dot products of training samples and the origin in feature
    // space (these dot products are always zero!)
    final RealMatrix k = MatrixFunctions.concatVertically(
            MatrixFunctions.concatHorizontally(kernelMatrix,
                    MatrixUtils.createRealMatrix(
                            kernelMatrix.getRowDimension(), 1)),
            MatrixUtils.createRealMatrix(1,
                    kernelMatrix.getColumnDimension() + 1));

    // create one-class labels + a different label for the origin
    final String[] labels = new String[n + 1];
    for (int l = 0; l <= n; l++) {
        labels[l] = (l == n) ? "0" : "1";
    }

    // get model parameters
    final RealMatrix projection = projection(k, labels);
    final int[] indices = new int[n];
    for (int i = 0; i < n; i++) {
        indices[i] = i;
    }
    m_targetPoints =
            MatrixUtils
                    .createRowRealMatrix(
                            MatrixFunctions
                                    .columnMeans(k
                                            .getSubMatrix(0, n - 1, 0,
                                                    k.getColumnDimension()
                                                            - 1)
                                    .multiply(projection)).toArray());
    m_projection = projection.getSubMatrix(0, n - 1, 0,
            projection.getColumnDimension() - 1);
    m_betweenClassDistances =
            new double[] { Math.abs(m_targetPoints.getEntry(0, 0)) };
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:39,代碼來源:OneClassKNFST.java

示例13: computeBetaQR

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
/**
 * Computes model parameters and parameter variance using a QR decomposition of the X matrix
 * @param y     the response vector
 * @param x     the design matrix
 */
private RealMatrix computeBetaQR(RealVector y, RealMatrix x) {
    final int n = x.getRowDimension();
    final int p = x.getColumnDimension();
    final int offset = hasIntercept() ? 1 : 0;
    final QRDecomposition decomposition = new QRDecomposition(x, threshold);
    final RealVector betaVector = decomposition.getSolver().solve(y);
    final RealVector residuals = y.subtract(x.operate(betaVector));
    this.rss = residuals.dotProduct(residuals);
    this.errorVariance = rss / (n - p);
    this.stdError = Math.sqrt(errorVariance);
    this.residuals = createResidualsFrame(residuals);
    final RealMatrix rAug = decomposition.getR().getSubMatrix(0, p - 1, 0, p - 1);
    final RealMatrix rInv = new LUDecomposition(rAug).getSolver().getInverse();
    final RealMatrix covMatrix = rInv.multiply(rInv.transpose()).scalarMultiply(errorVariance);
    final RealMatrix result = new Array2DRowRealMatrix(p, 2);
    if (hasIntercept()) {
        result.setEntry(0, 0, betaVector.getEntry(0));      //Intercept coefficient
        result.setEntry(0, 1, covMatrix.getEntry(0, 0));    //Intercept variance
    }
    for (int i = 0; i < getRegressors().size(); i++) {
        final int index = i + offset;
        final double variance = covMatrix.getEntry(index, index);
        result.setEntry(index, 1, variance);
        result.setEntry(index, 0, betaVector.getEntry(index));
    }
    return result;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:33,代碼來源:XDataFrameLeastSquares.java

示例14: pow

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
public static RealMatrix pow(final RealMatrix matrix, final double power) {
    final RealMatrix result = matrix.createMatrix(matrix.getRowDimension(),
            matrix.getColumnDimension());
    for (int r = 0; r < result.getRowDimension(); r++) {
        for (int c = 0; c < result.getColumnDimension(); c++) {
            result.setEntry(r, c, Math.pow(matrix.getEntry(r, c), power));
        }
    }
    return result;
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:11,代碼來源:MatrixFunctions.java

示例15: conditionCovarianceMatrix

import org.apache.commons.math3.linear.RealMatrix; //導入方法依賴的package包/類
/**
 * Conditions the supplied covariance matrix by enforcing
 * positive eigenvalues along its main diagonal. 
 * @param S original covariance matrix
 * @return modified covariance matrix
 */
private RealMatrix conditionCovarianceMatrix(RealMatrix S) {
	EigenDecomposition ed = new EigenDecomposition(S);  // S  ->  V . D . V^T
	RealMatrix V  = ed.getV();
	RealMatrix D  = ed.getD();	// diagonal matrix of eigenvalues
	RealMatrix VT = ed.getVT();
	for (int i = 0; i < D.getRowDimension(); i++) {
		D.setEntry(i, i, Math.max(D.getEntry(i, i), 10E-6));	// setting eigenvalues to zero is not enough!
	}
	return V.multiply(D).multiply(VT);
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:17,代碼來源:MahalanobisDistance.java


注:本文中的org.apache.commons.math3.linear.RealMatrix.getRowDimension方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。