Example usage for org.apache.commons.math.linear RealMatrix getEntry

List of usage examples for org.apache.commons.math.linear RealMatrix getEntry

Introduction

In this page you can find the example usage for org.apache.commons.math.linear RealMatrix getEntry.

Prototype

double getEntry(int row, int column) throws MatrixIndexException;

Source Link

Document

Returns the entry in the specified row and column.

Usage

From source file:juicebox.tools.utils.juicer.apa.APAUtils.java

public static RealMatrix centerNormalization(RealMatrix matrix) {

    int center = matrix.getRowDimension() / 2;
    double centerVal = matrix.getEntry(center, center);

    if (centerVal == 0) {
        centerVal = MatrixTools.minimumPositive(matrix);
        if (centerVal == 0)
            centerVal = 1;/* w ww.  ja v  a2 s  . c om*/
    }

    return matrix.copy().scalarMultiply(1. / centerVal);
}

From source file:juicebox.tools.utils.juicer.apa.APAUtils.java

public static double peakEnhancement(RealMatrix matrix) {
    int rows = matrix.getRowDimension();
    int center = rows / 2;
    double centerVal = matrix.getEntry(center, center);
    double remainingSum = APARegionStatistics.sum(matrix.getData()) - centerVal;
    double remainingAverage = remainingSum / (rows * rows - 1);
    return centerVal / remainingAverage;
}

From source file:juicebox.tools.utils.juicer.arrowhead.DynamicProgrammingUtils.java

/**
 * Dynamic programming to calculate "right" matrix
 * Initialize by setting the diagonal to the diagonal of original
 * Iterate to the right and up./*from   w w  w  .j av a 2 s . c  o m*/
 *
 * @param matrix
 * @param maxSize
 * @return rightMatrix
 */
public static RealMatrix right(RealMatrix matrix, int maxSize) {

    RealMatrix rightMatrix = MatrixTools.extractDiagonal(matrix);
    int n = rightMatrix.getRowDimension();

    // j is column, i is row
    for (int j = 1; j < n; j++) {
        int endPoint = Math.max(j - 1 - maxSize, 0);
        for (int i = j - 1; i >= endPoint; i--) {
            rightMatrix.setEntry(i, j, matrix.getEntry(i, j) + rightMatrix.getEntry(i + 1, j));
        }
    }
    return rightMatrix;
}

From source file:juicebox.tools.utils.juicer.arrowhead.DynamicProgrammingUtils.java

/**
 * Dynamic programming to calculate "upper" matrix
 * Initialize by setting the diagonal to the diagonal of original
 * Iterate down (for each row) and to the left.
 *
 * @param matrix//from   w  w  w . ja  v a  2s  .c om
 * @param maxSize
 * @return upperMatrix
 */
public static RealMatrix upper(RealMatrix matrix, int maxSize) {

    RealMatrix upperMatrix = MatrixTools.extractDiagonal(matrix);
    int n = upperMatrix.getRowDimension();

    // j is column, i is row
    for (int i = 0; i < n; i++) {
        int endPoint = Math.min(i + 1 + maxSize, n - 1);
        for (int j = i + 1; j <= endPoint; j++) {
            upperMatrix.setEntry(i, j, matrix.getEntry(i, j) + upperMatrix.getEntry(i, j - 1));
        }
    }
    return upperMatrix;
}

From source file:juicebox.tools.utils.juicer.apa.APAUtils.java

/**
 * @param data/* www .  j  a  va2s . c o  m*/
 * @return
 */
public static RealMatrix rankPercentile(RealMatrix data) {
    int n = data.getColumnDimension();
    StatPercentile percentile = new StatPercentile(MatrixTools.flattenedRowMajorOrderMatrix(data));

    RealMatrix matrix = new Array2DRowRealMatrix(n, n);
    for (int r = 0; r < n; r++) {
        for (int c = 0; c < n; c++) {
            double currValue = data.getEntry(r, c);
            if (currValue == 0) {
                matrix.setEntry(r, c, 0);
            } else {
                matrix.setEntry(r, c, percentile.evaluate(currValue));
            }
            //matrix.setEntry(r, c, percentile.evaluate());
        }
    }
    return matrix;
}

From source file:juicebox.tools.utils.common.MatrixTools.java

/**
 * @return max element in matrix/* w ww .j a  va  2  s .  c o m*/
 */
public static double calculateMax(RealMatrix matrix) {
    double max = matrix.getEntry(0, 0);
    for (int i = 0; i < matrix.getRowDimension(); i++) {
        for (int j = 0; j < matrix.getColumnDimension(); j++) {
            double val = matrix.getEntry(i, j);
            if (max < val) {
                max = val;
            }
        }
    }
    return max;
}

From source file:juicebox.tools.utils.juicer.arrowhead.DynamicProgrammingUtils.java

/**
 * Calculate cumulative sums across upper right matrix
 * iterative result is entry to left + entry below + orig value - diagonal down (else we double count)
 *
 * @param matrix/*from w  w  w  .  j  ava  2  s. com*/
 * @param superDiagonal
 * @return
 */
public static RealMatrix sum(RealMatrix matrix, int superDiagonal) {

    int n = Math.min(matrix.getRowDimension(), matrix.getColumnDimension());

    RealMatrix diagMatrix = MatrixTools.cleanArray2DMatrix(matrix.getRowDimension(),
            matrix.getColumnDimension());
    if (superDiagonal <= 0) {
        diagMatrix = MatrixTools.extractDiagonal(matrix);
        superDiagonal = 1;
    }

    // d = distance from diagonal
    for (int d = superDiagonal; d < n; d++) {
        // i = row, column is i +d;

        for (int i = 0; i < n - d; i++) {
            diagMatrix.setEntry(i, i + d, diagMatrix.getEntry(i, i + d - 1) + diagMatrix.getEntry(i + 1, i + d)
                    + matrix.getEntry(i, i + d) - diagMatrix.getEntry(i + 1, i + d - 1));
        }
    }
    return diagMatrix;
}

From source file:juicebox.tools.utils.common.MatrixTools.java

public static void thresholdValues(RealMatrix matrix, int val) {
    for (int i = 0; i < matrix.getRowDimension(); i++) {
        for (int j = 0; j < matrix.getColumnDimension(); j++) {
            if (matrix.getEntry(i, j) > val) {
                matrix.setEntry(i, j, val);
            }// ww  w . jav a  2s  . c  om
        }
    }
}

From source file:juicebox.tools.utils.common.MatrixTools.java

/**
 * Fill lower left triangle with values from upper right triangle
 *
 * @param matrix//  www  .  jav  a  2s . c  o m
 * @return
 */
public static RealMatrix fillLowerLeftTriangle(RealMatrix matrix) {
    for (int r = 0; r < matrix.getRowDimension(); r++)
        for (int c = 0; c < matrix.getColumnDimension(); c++)
            matrix.setEntry(c, r, matrix.getEntry(r, c));
    return matrix;
}

From source file:juicebox.tools.utils.common.MatrixTools.java

/**
 * Replace NaNs in given matrix with given value
 *//* www  .ja  va2  s . co  m*/
public static void setNaNs(RealMatrix matrix, int val) {
    for (int i = 0; i < matrix.getRowDimension(); i++) {
        for (int j = 0; j < matrix.getColumnDimension(); j++) {
            if (Double.isNaN(matrix.getEntry(i, j))) {
                matrix.setEntry(i, j, val);
            }
        }
    }
}