Java Code Examples for org.apache.commons.math3.analysis.polynomials.PolynomialFunction#degree()
The following examples show how to use
org.apache.commons.math3.analysis.polynomials.PolynomialFunction#degree() .
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: SparseGradientTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (double x = 0.1; x < 1.2; x += 0.001) { SparseGradient sgX = SparseGradient.createVariable(0, x); SparseGradient sgY1 = sgX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { sgY1 = sgY1.multiply(sgX).add(poly.getCoefficients()[i]); } SparseGradient sgY2 = sgX.compose(poly.value(x), poly.derivative().value(x)); SparseGradient zero = sgY1.subtract(sgY2); checkF0F1(zero, 0.0, 0.0); } }
Example 2
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }
Example 3
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }
Example 4
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }
Example 5
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }
Example 6
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }
Example 7
Source File: SparseGradientTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (double x = 0.1; x < 1.2; x += 0.001) { SparseGradient sgX = SparseGradient.createVariable(0, x); SparseGradient sgY1 = sgX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { sgY1 = sgY1.multiply(sgX).add(poly.getCoefficients()[i]); } SparseGradient sgY2 = sgX.compose(poly.value(x), poly.derivative().value(x)); SparseGradient zero = sgY1.subtract(sgY2); checkF0F1(zero, 0.0, 0.0); } }
Example 8
Source File: DerivativeStructureTest.java From astor with GNU General Public License v2.0 | 5 votes |
@Test public void testCompose() { double[] epsilon = new double[] { 1.0e-20, 5.0e-14, 2.0e-13, 3.0e-13, 2.0e-13, 1.0e-20 }; PolynomialFunction poly = new PolynomialFunction(new double[] { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 }); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { PolynomialFunction[] p = new PolynomialFunction[maxOrder + 1]; p[0] = poly; for (int i = 1; i <= maxOrder; ++i) { p[i] = p[i - 1].polynomialDerivative(); } for (double x = 0.1; x < 1.2; x += 0.001) { DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x); DerivativeStructure dsY1 = dsX.getField().getZero(); for (int i = poly.degree(); i >= 0; --i) { dsY1 = dsY1.multiply(dsX).add(poly.getCoefficients()[i]); } double[] f = new double[maxOrder + 1]; for (int i = 0; i < f.length; ++i) { f[i] = p[i].value(x); } DerivativeStructure dsY2 = dsX.compose(f); DerivativeStructure zero = dsY1.subtract(dsY2); for (int n = 0; n <= maxOrder; ++n) { Assert.assertEquals(0.0, zero.getPartialDerivative(n), epsilon[n]); } } } }