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

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

Introduction

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

Prototype

void setEntry(int row, int column, double value) throws MatrixIndexException;

Source Link

Document

Set the entry in the specified row and column.

Usage

From source file:fi.smaa.libror.r.RHelper.java

public static RealMatrix rArrayMatrixToRealMatrix(double[] matrix, int nRows) {
    if (nRows < 1) {
        throw new IllegalArgumentException("PRECOND violation: nRows < 1");
    }/*from  w  w w . j a va  2s.c  o  m*/
    int nCols = matrix.length / nRows;
    if (matrix.length != nRows * nCols) {
        throw new IllegalArgumentException("PRECOND violation: matrix.length != nRows * nCols");
    }
    RealMatrix perfMatrix = new Array2DRowRealMatrix(nRows, nCols);
    for (int i = 0; i < nRows; i++) {
        for (int j = 0; j < nCols; j++) {
            perfMatrix.setEntry(i, j, matrix[j * nRows + i]);
        }
    }
    return perfMatrix;
}

From source file:MathFunctions.java

private static void insertPoint2DInMatrix(RealMatrix m, Point2D.Double pt, int row) {
    // Set row to [x,y,1]:
    m.setEntry(row, 0, pt.x);
    m.setEntry(row, 1, pt.y);/*ww  w  .  ja  va2  s . c  o m*/
    m.setEntry(row, 2, 1);
}

From source file:math2605.gn_rat.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;/*  w w w . j a v  a 2 s  .  c o m*/
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = (a * x) / (x + b) + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:math2605.gn_log.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;/*from   w w w .j  a  v  a2 s . com*/
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.log10(x + b) + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:math2605.gn_qua.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;//  w  w  w.  j  a  va 2 s.co  m
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.pow(x, 2) + b * x + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:math2605.gn_exp.java

private static void setR(List<String[]> pairs, double a, double b, double c, RealMatrix r) {
    int row = 0;//from   w  w w. j a  v a  2  s. c o  m
    for (String[] p : pairs) {
        double x = Double.parseDouble(p[0]);
        double fx = a * Math.pow(Math.E, b * x) + c;
        double y = Double.parseDouble(p[1]);
        double resid = y - fx;
        r.setEntry(row, 0, resid);
        row++;
    }
}

From source file:edu.valelab.GaussianFit.CoordinateMapper.java

/**
 * Helper function for generateAffineTransformFromPointPairs
 * @param m//w w  w .  j a  va  2s.  co m
 * @param pt
 * @param row 
 */
private static void insertPoint2DInMatrix(RealMatrix m, Point2D.Double pt, int row) {
    // Set row to [x,y,1]:
    m.setEntry(row, 0, pt.x);
    m.setEntry(row, 1, pt.y);
    m.setEntry(row, 2, 1);
}

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 a  v 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  ww.j av a  2s. c  o m
 * @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//  w  w  w.j  a  va  2  s  .co 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;
}