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.distribution.continuous;
23  
24  import org.hipparchus.util.Precision;
25  import org.junit.jupiter.api.Test;
26  
27  import static org.junit.jupiter.api.Assertions.assertEquals;
28  import static org.junit.jupiter.api.Assertions.assertTrue;
29  
30  public class LevyDistributionTest extends RealDistributionAbstractTest {
31  
32      @Test
33      void testParameters() {
34          LevyDistribution d = makeDistribution();
35          assertEquals(1.2, d.getLocation(), Precision.EPSILON);
36          assertEquals(0.4,   d.getScale(),  Precision.EPSILON);
37      }
38  
39      @Test
40      void testSupport() {
41          LevyDistribution d = makeDistribution();
42          assertEquals(d.getLocation(), d.getSupportLowerBound(), Precision.EPSILON);
43          assertTrue(Double.isInfinite(d.getSupportUpperBound()));
44          assertTrue(d.isSupportConnected());
45      }
46  
47      @Override
48      public LevyDistribution makeDistribution() {
49          return new LevyDistribution(1.2, 0.4);
50      }
51  
52      @Override
53      public double[] makeCumulativeTestPoints() {
54          return new double[] {
55              1.2001, 1.21, 1.225, 1.25, 1.3, 1.9, 3.4, 5.6
56          };
57      }
58  
59      @Override
60      public double[] makeCumulativeTestValues() {
61          // values computed with R and function plevy from rmutil package
62          return new double[] {
63              0, 2.53962850749e-10, 6.33424836662e-05, 0.00467773498105,
64              0.0455002638964, 0.449691797969, 0.669815357599, 0.763024600553
65          };
66      }
67  
68      @Override
69      public double[] makeDensityTestValues() {
70          // values computed with R and function dlevy from rmutil package
71          return new double[] {
72              0, 5.20056373765e-07, 0.0214128361224, 0.413339707082, 1.07981933026,
73              0.323749319161, 0.0706032550094, 0.026122839884
74          };
75      }
76  
77      /**
78       * Creates the default logarithmic probability density test expected values.
79       * Reference values are from R, version 2.14.1.
80       */
81      @Override
82      public double[] makeLogDensityTestValues() {
83          return new double[] {
84              -1987.561573341398d, -14.469328620160d, -3.843764717971d,
85              -0.883485488811d, 0.076793740349d, -1.127785768948d,
86              -2.650679030597d, -3.644945255983d};
87      }
88  }