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


Java MatrixUtils.createRealMatrix方法代碼示例

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


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

示例1: makeDataMatrix

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
private RealMatrix makeDataMatrix(List<double[]> X, double[] meanX) {
	if (meanX == null) {
		return makeDataMatrix(X);
	}
	final int m = X.size();
	final int n = X.get(0).length;
	RealMatrix M = MatrixUtils.createRealMatrix(n, m);
	RealVector mean = MatrixUtils.createRealVector(meanX);
	int i = 0;
	for (double[] x : X) {
		RealVector xi = MatrixUtils.createRealVector(x).subtract(mean);
		M.setColumnVector(i, xi);
		i++;
	}
	return M;
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:17,代碼來源:ProcrustesFit.java

示例2: concatHorizontally

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的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

示例3: getResult

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 * Get the covariance matrix.
 * @return covariance matrix
 */
public RealMatrix getResult() {

    int dimension = sums.length;
    RealMatrix result = MatrixUtils.createRealMatrix(dimension, dimension);

    if (n > 1) {
        double c = 1.0 / (n * (isBiasCorrected ? (n - 1) : n));
        int k = 0;
        for (int i = 0; i < dimension; ++i) {
            for (int j = 0; j <= i; ++j) {
                double e = c * (n * productsSums[k++] - sums[i] * sums[j]);
                result.setEntry(i, j, e);
                result.setEntry(j, i, e);
            }
        }
    }

    return result;

}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:25,代碼來源:VectorialCovariance.java

示例4: padSymetricMatrix

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public static RealMatrix padSymetricMatrix(RealMatrix inMatrix, Boolean transMatr){
    RealMatrix padedMatrix          = null;
    RealMatrix templateMatrix       = null;

    //transpose if necessary
    if(transMatr) {
        templateMatrix = inMatrix.copy().transpose();
    }else{
        templateMatrix = inMatrix.copy();
    }

    padedMatrix          = MatrixUtils.createRealMatrix(templateMatrix.getRowDimension()+2,
            templateMatrix.getColumnDimension());

    int iPadStart = 1,iPadEnd = padedMatrix.getRowDimension()-1;

    padedMatrix.setRowVector(0,templateMatrix.getRowVector(0));
    padedMatrix.setRowVector(iPadEnd,templateMatrix.getRowVector(templateMatrix.getRowDimension()-1));

    // symetrical padding
    for(int i=iPadStart;i<iPadEnd;i++){
            padedMatrix.setRowVector(i,templateMatrix.getRowVector(i-1));
    }

    return(padedMatrix);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:27,代碼來源:SME_ENS_Utils.java

示例5: elementMultiply

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public static RealMatrix elementMultiply(RealMatrix inMatrix1,RealMatrix inMatrix2,Boolean absVal){
    int nrows = inMatrix1.getRowDimension();
    int ncols = inMatrix1.getColumnDimension();

    RealMatrix retuRealMatrix = MatrixUtils.createRealMatrix(nrows,ncols);

    for(int i=0;i<nrows;i++){
        for(int j=0;j<ncols;j++){
            if(absVal) {
                retuRealMatrix.setEntry(i, j, Math.abs(inMatrix1.getEntry(i, j) * inMatrix2.getEntry(i, j)));
            }else {
                retuRealMatrix.setEntry(i, j, inMatrix1.getEntry(i, j) * inMatrix2.getEntry(i, j));
            }
        }
    }

    return(retuRealMatrix);
}
 
開發者ID:biocompibens,項目名稱:SME,代碼行數:19,代碼來源:SME_ENS_Utils.java

示例6: averageHankelMatrix

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public static RealMatrix averageHankelMatrix(RealMatrix hankelMat, int windowSize) {

        int k = hankelMat.getRowDimension();
        int m = hankelMat.getColumnDimension() / windowSize;
        int n = k + windowSize - 1;

        RealMatrix result = MatrixUtils.createRealMatrix(n, m);

        for (int t = 0; t < n; ++t) {
            int i = (t < windowSize) ? 0 : (t - windowSize + 1);
            int j = (t < windowSize) ? t : (windowSize - 1);
            int counter = 0;

            for (; i < k && j >= 0; ++i, --j, ++counter) {
                for (int h = 0; h < m; ++h) {
                    result.addToEntry(t, h, hankelMat.getEntry(i, j * m + h));
                }
            }

            for (int h = 0; h < m; ++h) {
                result.setEntry(t, h, result.getEntry(t, h) / counter);
            }
        }

        return result;
    }
 
開發者ID:yahoo,項目名稱:egads,代碼行數:27,代碼來源:SpectralMethods.java

示例7: solveLinearEquationSystem

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
private void solveLinearEquationSystem(double targetDelay, int iterations) {
    driveStrengthMatrix_x = MatrixUtils.createRealMatrix(this.cellInstances.size(), 1);

    for (int i = 0; i < iterations; i++) {
        RealMatrix effortLoadMatrix = this.effortMatrix_T.multiply(driveStrengthMatrix_x);
        driveStrengthMatrix_x = effortLoadMatrix.add(this.staticLoadMatrix_b).scalarMultiply(1 / targetDelay);
    }
}
 
開發者ID:hpiasg,項目名稱:asgdrivestrength,代碼行數:9,代碼來源:EqualDelayMatrixOptimizer.java

示例8: inverse

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
/**
 * @param A a square matrix.
 * @return the inverse of A or null if A is non-square or singular.
 */
public static double[][] inverse(final double[][] A) {
	RealMatrix M = MatrixUtils.createRealMatrix(A);
	if (!M.isSquare())
		return null;
	else {
		double[][] Ai = null;
		try {
			RealMatrix Mi = MatrixUtils.inverse(M); //new LUDecomposition(M).getSolver().getInverse();
			Ai = Mi.getData();
		} catch (SingularMatrixException e) {}
		return Ai;
	}
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:18,代碼來源:Matrix.java

示例9: getTruncatedUT

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
static double[][] getTruncatedUT(INDArray matrix, int k) {
  double[][] data = getDoubles(matrix);

  SingularValueDecomposition svd = new SingularValueDecomposition(MatrixUtils.createRealMatrix(data));

  double[][] truncatedU = new double[svd.getU().getRowDimension()][k];
  svd.getU().copySubMatrix(0, truncatedU.length - 1, 0, k - 1, truncatedU);
  return truncatedU;
}
 
開發者ID:tteofili,項目名稱:par2hier,代碼行數:10,代碼來源:Par2HierUtils.java

示例10: testOnes

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
@Test
public void testOnes() {
    final RealMatrix expected1 = MatrixUtils.createRealMatrix(
            new double[][] { { 1, 1, 1 }, { 1, 1, 1 }, { 1, 1, 1 } });
    assertEquals(expected1, MatrixFunctions.ones(3, 3));
    final RealMatrix expected2 = MatrixUtils.createRealMatrix(
            new double[][] { { 1, 1 }, { 1, 1 }, { 1, 1 } });
    assertEquals(expected2, MatrixFunctions.ones(3, 2));
    final RealMatrix expected3 = MatrixUtils
            .createRealMatrix(new double[][] { { 1, 1, 1 }, { 1, 1, 1 } });
    assertEquals(expected3, MatrixFunctions.ones(2, 3));
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:13,代碼來源:MatrixFunctionsTest.java

示例11: getTransformationMatrix

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
@Override
public RealMatrix getTransformationMatrix() {
	RealMatrix cR = R.scalarMultiply(c);
	RealMatrix M = MatrixUtils.createRealMatrix(n, n + 1);
	M.setSubMatrix(cR.getData(), 0, 0);
	M.setColumnVector(n, t);
	return M;
}
 
開發者ID:imagingbook,項目名稱:imagingbook-common,代碼行數:9,代碼來源:ProcrustesFit.java

示例12: testConcatHorizontally

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
@Test
public void testConcatHorizontally() {
    final RealMatrix expected = MatrixUtils
            .createRealMatrix(new double[][] { { 1, 0, 0, 1, 2, 3 },
                    { 0, 1, 0, 1, 2, 3 }, { 0, 0, 1, 1, 2, 3 } });
    assertEquals(expected,
            MatrixFunctions.concatHorizontally(matrixI, matrixA));
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:9,代碼來源:MatrixFunctionsTest.java

示例13: testConcatVertically

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
@Test
public void testConcatVertically() {
    final RealMatrix expected = MatrixUtils
            .createRealMatrix(new double[][] { { 1, 0, 0 }, { 0, 1, 0 },
                    { 0, 0, 1 }, { 1, 2, 3 }, { 1, 2, 3 }, { 1, 2, 3 } });

    assertEquals(expected, MatrixFunctions.concatVertically(matrixI, matrixA));
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:9,代碼來源:MatrixFunctionsTest.java

示例14: MultiClassKNFST

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的package包/類
public MultiClassKNFST(final RealMatrix kernelMatrix, final String[] labels)
        throws KNFSTException {
    m_labels = labels;
    // obtain unique class labels
    final ClassWrapper[] classes = ClassWrapper.classes(labels);

    // calculate projection of KNFST
    m_projection = projection(kernelMatrix, labels);

    // calculate target points ( = projections of training data into the
    // null space)
    m_targetPoints = MatrixUtils.createRealMatrix(classes.length,
            m_projection.getColumnDimension());
    int n = 0;
    int nOld = 0;
    for (int c = 0; c < classes.length; c++) {
        n += classes[c].getCount();
        m_targetPoints
                .setRowVector(c,
                        MatrixFunctions
                                .columnMeans(kernelMatrix
                                        .getSubMatrix(nOld, n - 1, 0,
                                                kernelMatrix
                                                        .getColumnDimension()
                                                        - 1)
                                .multiply(m_projection)));
        nOld = n;
    }

    // set betweenClassDistances
    m_betweenClassDistances =
            MatrixFunctions.calculateRowVectorDistances(m_targetPoints);
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:34,代碼來源:MultiClassKNFST.java

示例15: squared_euclidean_distances

import org.apache.commons.math3.linear.MatrixUtils; //導入方法依賴的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


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