View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  package org.hipparchus.analysis.integration.gauss;
23  
24  import java.util.ArrayList;
25  import java.util.Collection;
26  
27  import org.hipparchus.util.Binary64;
28  import org.hipparchus.util.Binary64Field;
29  import org.hipparchus.util.FastMath;
30  import org.junit.runner.RunWith;
31  import org.junit.runners.Parameterized;
32  import org.junit.runners.Parameterized.Parameters;
33  
34  /**
35   * Test of the {@link FieldHermiteRuleFactory}.
36   * This parameterized test extends the standard test for Gaussian quadrature
37   * rule, where each monomial is tested in turn.
38   * Parametrization allows to test automatically 0, 1, ... , {@link #MAX_NUM_POINTS}
39   * quadrature rules.
40   *
41   */
42  @RunWith(value=Parameterized.class)
43  public class FieldHermiteParametricTest extends FieldGaussianQuadratureAbstractTest {
44      private static final double SQRT_PI = FastMath.sqrt(Math.PI);
45      private static final FieldGaussIntegratorFactory<Binary64> factory = new FieldGaussIntegratorFactory<>(Binary64Field.getInstance());
46  
47      /**
48       * The highest order quadrature rule to be tested.
49       */
50      public static final int MAX_NUM_POINTS = 30;
51  
52      /**
53       * Creates a new instance of this test, with the specified number of nodes
54       * for the Gauss-Hermite quadrature rule.
55       *
56       * @param numberOfPoints Order of integration rule.
57       * @param maxDegree Maximum degree of monomials to be tested.
58       * @param eps Value of &epsilon;.
59       * @param numUlps Value of the maximum relative error (in ulps).
60       */
61      public FieldHermiteParametricTest(int numberOfPoints,
62                                   int maxDegree,
63                                   double eps,
64                                   double numUlps) {
65          super(factory.hermite(numberOfPoints),
66                maxDegree, eps, numUlps);
67      }
68  
69      /**
70       * Returns the collection of parameters to be passed to the constructor of
71       * this class.
72       * Gauss-Hermite quadrature rules of order 1, ..., {@link #MAX_NUM_POINTS}
73       * will be constructed.
74       *
75       * @return the collection of parameters for this parameterized test.
76       */
77      @Parameters
78      public static Collection<Object[]> getParameters() {
79          final ArrayList<Object[]> parameters = new ArrayList<Object[]>();
80          final int [] numUlps = {
81              10,  10,  10,  10,  20,
82              20,  30,  30,  30,  40,
83              40,  60, 150, 150, 150,
84             150, 150, 150, 150, 200,
85             250, 250, 300, 300, 300,
86             300, 300, 300, 350, 350
87         };
88          for (int k = 1; k <= MAX_NUM_POINTS; k++) {
89              parameters.add(new Object[] { k, 2 * k - 1, Math.ulp(1d), numUlps[k - 1] });
90          }
91          return parameters;
92      }
93  
94      @Override
95      public double getExpectedValue(final int n) {
96          if (n % 2 == 1) {
97              return 0;
98          }
99  
100         final int iMax = n / 2;
101         double p = 1;
102         double q = 1;
103         for (int i = 0; i < iMax; i++) {
104             p *= 2 * i + 1;
105             q *= 2;
106         }
107 
108         return p / q * SQRT_PI;
109     }
110 }