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

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

Introduction

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

Prototype

@Override
public void setEntry(final int row, final int column, final double value) throws MatrixIndexException 

Source Link

Usage

From source file:edu.cudenver.bios.matrixsvc.test.ResourceTestCase.java

/**
 *  a method to test MatrixUtils.getKroneckerProduct()
 *//*  w ww .  ja va 2s  .c om*/
public void testGetKroneckerProduct() {
    Array2DRowRealMatrix input1 = new Array2DRowRealMatrix(2, 1);
    input1.setEntry(0, 0, 2.0);
    input1.setEntry(1, 0, 4.0);

    Array2DRowRealMatrix input2 = new Array2DRowRealMatrix(1, 2);
    input2.setEntry(0, 0, 10.0);
    input2.setEntry(0, 1, 20.0);

    NamedRealMatrix result = new NamedRealMatrix(MatrixUtils.getKroneckerProduct(input1, input2));

    assertEquals(20.0, result.getEntry(0, 0));
    assertEquals(40.0, result.getEntry(0, 1));
    assertEquals(40.0, result.getEntry(1, 0));
    assertEquals(80.0, result.getEntry(1, 1));
    System.out.println("testGetKroneckerProduct() succeeded.  All values correct.");
}

From source file:edu.cudenver.bios.matrixsvc.test.ResourceTestCase.java

/**
 * A method to test MatrixUtils.isPositiveDefinite(), with both
 * a positiveDefinite matrix, and a matrix which is not positiveDefinite.
 *//*from   w  w  w . j a v a  2s.co m*/
public void testPositiveDefinite() {
    try {
        Array2DRowRealMatrix input = new Array2DRowRealMatrix(2, 2);
        input.setEntry(0, 0, 1.0);
        input.setEntry(0, 1, 0.0);
        input.setEntry(1, 0, 0.0);
        input.setEntry(1, 1, 1.0);
        assertTrue(MatrixUtils.isPositiveDefinite(input, MatrixConstants.EIGEN_TOLERANCE_DEFAULT));
        input.setEntry(0, 0, -1.0);
        input.setEntry(0, 1, -1.0);
        input.setEntry(1, 0, -1.0);
        input.setEntry(1, 1, -1.0);
        assertFalse(MatrixUtils.isPositiveDefinite(input, MatrixConstants.EIGEN_TOLERANCE_DEFAULT));
        System.out.println("testPositiveDefinite() succeeded.");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
    }
}

From source file:edu.cudenver.bios.matrixsvc.test.ResourceTestCase.java

/**
 * Test the isSymmetrical() method written in MatrixUtils.
 *///from  w  w w .  j  a v a  2 s . c  o m
public void testIsSymmetrical() {
    try {
        //create a symmetrical matrix
        Array2DRowRealMatrix input = new Array2DRowRealMatrix(3, 3);
        input.setEntry(0, 0, 1.0);
        input.setEntry(0, 1, 9.0);
        input.setEntry(0, 2, 4.0);
        input.setEntry(1, 0, 9.0);
        input.setEntry(1, 1, 2.0);
        input.setEntry(1, 2, 6.0);
        input.setEntry(2, 0, 4.0);
        input.setEntry(2, 1, 6.0);
        input.setEntry(2, 2, 3.0);

        assertTrue(MatrixUtils.isSymmetric(input));
        System.out.println("testIsSymmetrical() succeeded.");
    } catch (Exception e) {
        fail(e.getMessage());
    }
}

From source file:edu.cudenver.bios.matrixsvc.test.ResourceTestCase.java

/**
 * Test the isSymmetrical() method of MatrixUtils, with a non-symmetrical
 * matrix./*from w  w w  .  j av  a 2s  .co  m*/
 */
public void testNonSymmetrical() {
    try {
        //create a non-symmetrical matrix
        Array2DRowRealMatrix input = new Array2DRowRealMatrix(3, 3);
        input.setEntry(0, 0, 1.0);
        input.setEntry(0, 1, 999.0);//non conforming
        input.setEntry(0, 2, 4.0);
        input.setEntry(1, 0, 9.0);
        input.setEntry(1, 1, 2.0);
        input.setEntry(1, 2, 6.0);
        input.setEntry(2, 0, 4.0);
        input.setEntry(2, 1, 6.0);
        input.setEntry(2, 2, 3.0);
        assertFalse(MatrixUtils.isSymmetric(input));
        System.out.println("testNonSymmetrical() succeeded.");
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
    }
}

From source file:org.micromanager.plugins.magellan.propsandcovariants.LaserPredNet.java

private static void relu(Array2DRowRealMatrix activations) {
    for (int r = 0; r < activations.getRowDimension(); r++) {
        for (int c = 0; c < activations.getColumnDimension(); c++) {
            if (activations.getEntry(r, c) < 0) {
                activations.setEntry(r, c, 0.0);
            }// w  ww .j  ava2  s .c o  m
        }
    }
}