当前位置: 首页>>代码示例>>Java>>正文


Java RealMatrix.getColumnDimension方法代码示例

本文整理汇总了Java中org.apache.commons.math3.linear.RealMatrix.getColumnDimension方法的典型用法代码示例。如果您正苦于以下问题:Java RealMatrix.getColumnDimension方法的具体用法?Java RealMatrix.getColumnDimension怎么用?Java RealMatrix.getColumnDimension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.math3.linear.RealMatrix的用法示例。


在下文中一共展示了RealMatrix.getColumnDimension方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: ThreadController

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public ThreadController(final ExecutionContext exec,
        final RealMatrix globalKernelMatrix,
        final RealMatrix trainingKernelMatrix, final String[] labels,
        final int numNeighbors, final boolean normalize) {
    m_exec = exec;
    m_globalKernelMatrix = globalKernelMatrix;
    m_trainingKernelMatrix = trainingKernelMatrix;
    m_labels = labels;
    m_numNeighbors = numNeighbors;
    m_normalize = normalize;

    m_noveltyScores = new double[globalKernelMatrix.getColumnDimension()];
}
 
开发者ID:knime,项目名称:knime-activelearning,代码行数:14,代码来源:ThreadController.java

示例8: sqrt

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public static RealMatrix sqrt(final RealMatrix matrix) {
    final double[][] data = matrix.getData();
    for (int r = 0; r < matrix.getRowDimension(); r++) {
        for (int c = 0; c < matrix.getColumnDimension(); c++) {
            data[r][c] = Math.sqrt(data[r][c]);
        }
    }
    return MatrixUtils.createRealMatrix(data);
}
 
开发者ID:knime,项目名称:knime-activelearning,代码行数:10,代码来源:MatrixFunctions.java

示例9: 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

示例10: CancerPrediction

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
public CancerPrediction(RealMatrix dens, RealVector thetas, boolean cancerPos) {
    int nTheta = dens.getColumnDimension();
    int nType = dens.getRowDimension();
    thetaPreds = new double[nType];
    maxDens = new Double[nType];
    double[] baseDens = dens.getColumn(0); // the likelihoods if the sample is normal

    for (int i=0; i<nType; i++) {
        RealVector rowDens;
        if (cancerPos) {
            rowDens = dens.getRowVector(i).getSubVector(1,nTheta - 1);
            thetaPreds[i] = thetaPred(rowDens, thetas.getSubVector(1,nTheta-1));
        }
        else {
            rowDens = dens.getRowVector(i);
            thetaPreds[i] = thetaPred(rowDens, thetas);
        }
        maxDens[i] = rowDens.getMaxValue();
    }
    //sort type by maxDens-baseDens
    typeRanks  = new Integer[nType];
    for(int i=0 ; i < nType; i++ ) typeRanks[i] = i;
    Arrays.sort(typeRanks, (i1, i2) -> { // descending
        return Double.compare(maxDens[i2]-baseDens[i2], maxDens[i1]-baseDens[i1]); // log scale
    });
    bestTheta = thetaPreds[typeRanks[0]];
    bestDens = maxDens[typeRanks[0]];
    bestRatio = bestDens-baseDens[typeRanks[0]]; // log scale
}
 
开发者ID:jasminezhoulab,项目名称:CancerLocator,代码行数:30,代码来源:CancerPrediction.java

示例11: printMatrix

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
/**
 * Helper method for printing a matrix to the console
 *
 * @param matrix
 */
public static void printMatrix(RealMatrix matrix) {
    for (int rowIndex = 0; rowIndex < matrix.getRowDimension(); 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,代码行数:15,代码来源:AnalysisData.java

示例12: 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,代码来源:SampleComparisonTest.java

示例13: computeBeta

import org.apache.commons.math3.linear.RealMatrix; //导入方法依赖的package包/类
/**
 *
 * @param y     the response vector
 * @param x     the design matrix
 */
private RealMatrix computeBeta(RealVector y, RealMatrix x) {
    if (solver == Solver.QR) {
        return computeBetaQR(y, x);
    } else {
        final int n = x.getRowDimension();
        final int p = x.getColumnDimension();
        final int offset = hasIntercept() ? 1 : 0;
        final RealMatrix xT = x.transpose();
        final RealMatrix xTxInv = new LUDecomposition(xT.multiply(x)).getSolver().getInverse();
        final RealVector betaVector = xTxInv.multiply(xT).operate(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 covMatrix = xTxInv.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,代码行数:36,代码来源:XDataFrameLeastSquares.java

示例14: 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


注:本文中的org.apache.commons.math3.linear.RealMatrix.getColumnDimension方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。