Java Code Examples for org.apache.commons.math.linear.RealMatrix#copy()

The following examples show how to use org.apache.commons.math.linear.RealMatrix#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: APAPlotter.java    From Juicebox with MIT License 4 votes vote down vote up
/**
 * Method for plotting apa data
 *
 * @param dataOriginal       for heat map
 * @param axesRange  initial values and increments to annotate axes [x0, dx, y0, dy]
 * @param outputFile where image will saved
 */
public static void plot(RealMatrix dataOriginal, int[] axesRange, File outputFile,
                        String title, int currentRegionWidth,
                        boolean useCellPlottingStandards) {

    // As noted in the Cell supplement:
    // "The color scale in all APA plots is set as follows.
    // The minimum of the color range is 0. The maximum is 5 x UR, where
    // UR is the mean value of the bins in the upper-right corner of the matrix.
    // The upper-right corner of the 10 kb resolution APA
    // plots is a 6 x 6 window (or 3 x 3 for 5 kb resolution APA plots)."
    // TODO

    RealMatrix data = dataOriginal.copy(); // don't want original edited

    APARegionStatistics apaStats = new APARegionStatistics(data, currentRegionWidth);
    DecimalFormat df = new DecimalFormat("0.000");
    title += ", P2LL = " + df.format(apaStats.getPeak2LL());

    Color lowColor;
    Color highColor;
    double maxAllowedValueCell = 5 * apaStats.getMeanUR();
    double minAllowedValueCell = 0;
    if (useCellPlottingStandards) {
        double dataMin = MatrixTools.calculateMin(data);
        double dataMax = MatrixTools.calculateMax(data);
        if (dataMax > maxAllowedValueCell) {
            dataMax = maxAllowedValueCell;
        }
        if (dataMin < minAllowedValueCell) {
            dataMin = minAllowedValueCell;
        }
        MatrixTools.thresholdValuesDouble(data, minAllowedValueCell, maxAllowedValueCell);

        int lowColorGB = (int) (255 - dataMin / maxAllowedValueCell * 255);
        int highColorGB = (int) (255 - dataMax / maxAllowedValueCell * 255);
        lowColor = new Color(255, lowColorGB, lowColorGB);
        highColor = new Color(255, highColorGB, highColorGB);
    } else {
        lowColor = Color.white;
        highColor = Color.red;
    }

    // initialize heat map
    HeatChart map = new HeatChart(data.getData());
    map.setXValues(axesRange[0], axesRange[1]);
    map.setYValues(axesRange[2], axesRange[3]);
    map.setTitle(title);

    map.setLowValueColour(lowColor);
    map.setHighValueColour(highColor);

    try {
        // calculate dimensions for plot wrapper
        initializeSizes(map);

        // create blank white image
        BufferedImage apaImage = new BufferedImage(fullWidth, fullHeight, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = apaImage.createGraphics();
        g2.setBackground(Color.WHITE);
        g2.fillRect(0, 0, fullWidth, fullHeight);

        // plot in heat map, color bar, etc
        g2.drawImage(map.getChartImage(), 0, 0, heatmapWidth, fullHeight, null);
        drawHeatMapBorder(g2, map);
        plotColorScaleBar(g2);

        if (useCellPlottingStandards) {
            plotSpecialColorScaleValues(g2, map, minAllowedValueCell, maxAllowedValueCell);
        } else {
            plotColorScaleValues(g2, map);
        }

        // top left, top right, bottom left, bottom right values (from apa)

        drawCornerRegions(g2, map, new Dimension(currentRegionWidth, currentRegionWidth),
                apaStats.getRegionCornerValues());

        // save data
        ImageIO.write(apaImage, "png", outputFile);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 3
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 4
Source File: LeastSquaresConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Build a simple converter for correlated residuals with the specific weights.
 * <p>
 * The scalar objective function value is computed as:
 * <pre>
 * objective = y<sup>T</sup>y with y = scale&times;(observation-objective)
 * </pre>
 * </p>
 * <p>
 * The array computed by the objective function, the observations array and the
 * the scaling matrix must have consistent sizes or a {@link FunctionEvaluationException}
 * will be triggered while computing the scalar objective.
 * </p>
 * @param function vectorial residuals function to wrap
 * @param observations observations to be compared to objective function to compute residuals
 * @param scale scaling matrix
 * @exception IllegalArgumentException if the observations vector and the scale
 * matrix dimensions don't match (objective function dimension is checked only when
 * the {@link #value(double[])} method is called)
 */
public LeastSquaresConverter(final MultivariateVectorialFunction function,
                             final double[] observations, final RealMatrix scale)
    throws IllegalArgumentException {
    if (observations.length != scale.getColumnDimension()) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimension mismatch {0} != {1}",
                observations.length, scale.getColumnDimension());
    }
    this.function     = function;
    this.observations = observations.clone();
    this.weights      = null;
    this.scale        = scale.copy();
}
 
Example 5
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 * 
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */    
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy(); 
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 6
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 7
Source File: LeastSquaresConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Build a simple converter for correlated residuals with the specific weights.
 * <p>
 * The scalar objective function value is computed as:
 * <pre>
 * objective = y<sup>T</sup>y with y = scale&times;(observation-objective)
 * </pre>
 * </p>
 * <p>
 * The array computed by the objective function, the observations array and the
 * the scaling matrix must have consistent sizes or a {@link FunctionEvaluationException}
 * will be triggered while computing the scalar objective.
 * </p>
 * @param function vectorial residuals function to wrap
 * @param observations observations to be compared to objective function to compute residuals
 * @param scale scaling matrix
 * @exception IllegalArgumentException if the observations vector and the scale
 * matrix dimensions don't match (objective function dimension is checked only when
 * the {@link #value(double[])} method is called)
 */
public LeastSquaresConverter(final MultivariateVectorialFunction function,
                             final double[] observations, final RealMatrix scale)
    throws IllegalArgumentException {
    if (observations.length != scale.getColumnDimension()) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimension mismatch {0} != {1}",
                observations.length, scale.getColumnDimension());
    }
    this.function     = function;
    this.observations = observations.clone();
    this.weights      = null;
    this.scale        = scale.copy();
}
 
Example 8
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 * 
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */    
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy(); 
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 9
Source File: LeastSquaresConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Build a simple converter for correlated residuals with the specific weights.
 * <p>
 * The scalar objective function value is computed as:
 * <pre>
 * objective = y<sup>T</sup>y with y = scale&times;(observation-objective)
 * </pre>
 * </p>
 * <p>
 * The array computed by the objective function, the observations array and the
 * the scaling matrix must have consistent sizes or a {@link FunctionEvaluationException}
 * will be triggered while computing the scalar objective.
 * </p>
 * @param function vectorial residuals function to wrap
 * @param observations observations to be compared to objective function to compute residuals
 * @param scale scaling matrix
 * @exception IllegalArgumentException if the observations vector and the scale
 * matrix dimensions don't match (objective function dimension is checked only when
 * the {@link #value(double[])} method is called)
 */
public LeastSquaresConverter(final MultivariateVectorialFunction function,
                             final double[] observations, final RealMatrix scale)
    throws IllegalArgumentException {
    if (observations.length != scale.getColumnDimension()) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimension mismatch {0} != {1}",
                observations.length, scale.getColumnDimension());
    }
    this.function     = function;
    this.observations = observations.clone();
    this.weights      = null;
    this.scale        = scale.copy();
}
 
Example 10
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 11
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 12
Source File: LeastSquaresConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Build a simple converter for correlated residuals with the specific weights.
 * <p>
 * The scalar objective function value is computed as:
 * <pre>
 * objective = y<sup>T</sup>y with y = scale&times;(observation-objective)
 * </pre>
 * </p>
 * <p>
 * The array computed by the objective function, the observations array and the
 * the scaling matrix must have consistent sizes or a {@link FunctionEvaluationException}
 * will be triggered while computing the scalar objective.
 * </p>
 * @param function vectorial residuals function to wrap
 * @param observations observations to be compared to objective function to compute residuals
 * @param scale scaling matrix
 * @exception IllegalArgumentException if the observations vector and the scale
 * matrix dimensions don't match (objective function dimension is checked only when
 * the {@link #value(double[])} method is called)
 */
public LeastSquaresConverter(final MultivariateVectorialFunction function,
                             final double[] observations, final RealMatrix scale)
    throws IllegalArgumentException {
    if (observations.length != scale.getColumnDimension()) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimension mismatch {0} != {1}",
                observations.length, scale.getColumnDimension());
    }
    this.function     = function;
    this.observations = observations.clone();
    this.weights      = null;
    this.scale        = scale.copy();
}
 
Example 13
Source File: LeastSquaresConverter.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Build a simple converter for correlated residuals with the specific weights.
 * <p>
 * The scalar objective function value is computed as:
 * <pre>
 * objective = y<sup>T</sup>y with y = scale&times;(observation-objective)
 * </pre>
 * </p>
 * <p>
 * The array computed by the objective function, the observations array and the
 * the scaling matrix must have consistent sizes or a {@link FunctionEvaluationException}
 * will be triggered while computing the scalar objective.
 * </p>
 * @param function vectorial residuals function to wrap
 * @param observations observations to be compared to objective function to compute residuals
 * @param scale scaling matrix
 * @exception IllegalArgumentException if the observations vector and the scale
 * matrix dimensions don't match (objective function dimension is checked only when
 * the {@link #value(double[])} method is called)
 */
public LeastSquaresConverter(final MultivariateVectorialFunction function,
                             final double[] observations, final RealMatrix scale)
    throws IllegalArgumentException {
    if (observations.length != scale.getColumnDimension()) {
        throw MathRuntimeException.createIllegalArgumentException(
                "dimension mismatch {0} != {1}",
                observations.length, scale.getColumnDimension());
    }
    this.function     = function;
    this.observations = observations.clone();
    this.weights      = null;
    this.scale        = scale.copy();
}
 
Example 14
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 * 
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */    
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy(); 
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 15
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Create a SpearmansCorrelation with the given input data matrix
 * and ranking algorithm.
 *
 * @param dataMatrix matrix of data with columns representing
 * variables to correlate
 * @param rankingAlgorithm ranking algorithm
 */
public SpearmansCorrelation(final RealMatrix dataMatrix, final RankingAlgorithm rankingAlgorithm) {
    this.data = dataMatrix.copy();
    this.rankingAlgorithm = rankingAlgorithm;
    rankTransform(data);
    rankCorrelation = new PearsonsCorrelation(data);
}
 
Example 16
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Computes the Spearman's rank correlation matrix for the columns of the
 * input matrix.
 *
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
    RealMatrix matrixCopy = matrix.copy();
    rankTransform(matrixCopy);
    return new PearsonsCorrelation().computeCorrelationMatrix(matrixCopy);
}
 
Example 17
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Computes the Spearman's rank correlation matrix for the columns of the
 * input matrix.
 * 
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
    RealMatrix matrixCopy = matrix.copy();
    rankTransform(matrixCopy);
    return new PearsonsCorrelation().computeCorrelationMatrix(matrixCopy);
}
 
Example 18
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Computes the Spearman's rank correlation matrix for the columns of the
 * input matrix.
 *
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
    RealMatrix matrixCopy = matrix.copy();
    rankTransform(matrixCopy);
    return new PearsonsCorrelation().computeCorrelationMatrix(matrixCopy);
}
 
Example 19
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Computes the Spearman's rank correlation matrix for the columns of the
 * input matrix.
 *
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
    RealMatrix matrixCopy = matrix.copy();
    rankTransform(matrixCopy);
    return new PearsonsCorrelation().computeCorrelationMatrix(matrixCopy);
}
 
Example 20
Source File: SpearmansCorrelation.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Computes the Spearman's rank correlation matrix for the columns of the
 * input matrix.
 *
 * @param matrix matrix with columns representing variables to correlate
 * @return correlation matrix
 */
public RealMatrix computeCorrelationMatrix(RealMatrix matrix) {
    RealMatrix matrixCopy = matrix.copy();
    rankTransform(matrixCopy);
    return new PearsonsCorrelation().computeCorrelationMatrix(matrixCopy);
}