//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void differenceMatrix1DTest() public virtual void differenceMatrix1DTest() { int n = 7; DoubleMatrix d0 = PenaltyMatrixGenerator.getDifferenceMatrix(n, 0); //zeroth order AssertMatrix.assertEqualsMatrix(DoubleMatrix.identity(n), d0, 1e-15); DoubleArray zeroVector = DoubleArray.filled(n); DoubleMatrix d1 = PenaltyMatrixGenerator.getDifferenceMatrix(n, 1); //first order difference matrix assertEquals(n, d1.rowCount()); assertEquals(n, d1.columnCount()); AssertMatrix.assertEqualsVectors(zeroVector, d1.row(0), 1e-15); //first row should be zero DoubleArray x = DoubleArray.filled(n, 1.0); DoubleArray d1x = (DoubleArray)MA.multiply(d1, x); //a constant vector should have zero first order differences AssertMatrix.assertEqualsVectors(zeroVector, d1x, 1e-14); DoubleMatrix d2 = PenaltyMatrixGenerator.getDifferenceMatrix(n, 2); //second order difference matrix assertEquals(n, d2.rowCount()); assertEquals(n, d2.columnCount()); AssertMatrix.assertEqualsVectors(zeroVector, d2.row(0), 1e-15); //first two rows should be zero AssertMatrix.assertEqualsVectors(zeroVector, d2.row(1), 1e-15); DoubleArray x2 = DoubleArray.of(n, i => i); d1x = (DoubleArray)MA.multiply(d1, x2); //first element of the diff vector is set to zero DoubleArray ones = DoubleArray.filled(n, 1.0).with(0, 0); //vector with differences of one AssertMatrix.assertEqualsVectors(ones, d1x, 1e-14); DoubleArray d2x = (DoubleArray)MA.multiply(d2, x2); //a linear vector should have zero second order differences AssertMatrix.assertEqualsVectors(zeroVector, d2x, 1e-14); DoubleMatrix d3 = PenaltyMatrixGenerator.getDifferenceMatrix(n, 3); //third order difference matrix assertEquals(n, d3.rowCount()); assertEquals(n, d3.columnCount()); AssertMatrix.assertEqualsVectors(zeroVector, d3.row(0), 1e-15); //first three rows should be zero AssertMatrix.assertEqualsVectors(zeroVector, d3.row(1), 1e-15); AssertMatrix.assertEqualsVectors(zeroVector, d3.row(2), 1e-15); DoubleArray x3 = DoubleArray.of(n, i => 0.5 + i + 0.1 * i * i); d1x = (DoubleArray)MA.multiply(d1, x3); // expected first order diff, first element is zero DoubleArray exp = DoubleArray.of(n, i => 0.9 + 0.2 * i).with(0, 0); AssertMatrix.assertEqualsVectors(exp, d1x, 1e-14); // expected second order diff, first two elements are zero exp = DoubleArray.filled(n, 0.2).with(0, 0).with(1, 0); d2x = (DoubleArray)MA.multiply(d2, x3); AssertMatrix.assertEqualsVectors(exp, d2x, 1e-14); DoubleArray d3x = (DoubleArray)MA.multiply(d3, x3); //a quadratic vector should have zero third order differences AssertMatrix.assertEqualsVectors(zeroVector, d3x, 1e-14); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test(expectedExceptions = IllegalArgumentException.class) public void diffOrderTooHighTest() public virtual void diffOrderTooHighTest() { PenaltyMatrixGenerator.getDifferenceMatrix(6, 6); }