File: t_DistFunc_student.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (79 lines) | stat: -rwxr-xr-x 1,755 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()

# pStudent
nuMin = 0.2
nuMax = 5.0
n1 = 5
xMin = 0.1
xMax = 0.9
nX = 10
grid = [0.0] * nX
for i1 in range(n1):
    nu = nuMin + (nuMax - nuMin) * i1 / (n1 - 1)
    for iX in range(nX):
        x = xMin + (xMax - xMin) * iX / (nX - 1)
        grid[iX] = x
        print(
            "pStudent(",
            nu,
            ",  %.12g" % x,
            ")=%.6g" % ot.DistFunc.pStudent(nu, x),
            ", complementary=%.6g" % ot.DistFunc.pStudent(nu, x, True),
        )
    print("pStudent(", grid, ")=", ot.DistFunc.pStudent(nu, grid))

# check for nans
for x in [
    -1e300,
    -1e200,
    -1e100,
    1e10,
    -10.0,
    -0.1,
    0.0,
    0.1,
    10.0,
    1e10,
    1e100,
    1e200,
    1e300,
]:
    for nu in [2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0, 7.5]:
        for tail in [False, True]:
            p = ot.DistFunc.pStudent(nu, x, tail)
            assert ot.SpecFunc.IsNormal(p), "pStudent returns nan"

# qStudent
nuMin = 0.2
nuMax = 5.0
n1 = 5
qMin = 0.1
qMax = 0.9
nQ = 10
grid = [0.0] * nQ
for i1 in range(n1):
    nu = nuMin + (nuMax - nuMin) * i1 / (n1 - 1)
    for iQ in range(nQ):
        q = qMin + (qMax - qMin) * iQ / (nQ - 1)
        grid[iQ] = q
        print(
            "qStudent(",
            nu,
            ",  %.12g" % q,
            ")=%.6g" % ot.DistFunc.qStudent(nu, q),
            ", complementary=%.6g" % ot.DistFunc.qStudent(nu, q, True),
        )
print("qStudent(", grid, ")=", ot.DistFunc.qStudent(nu, grid))
# rStudent
nuMin = 0.2
nuMax = 5.0
n1 = 5
nR = 10
for i1 in range(n1):
    nu = nuMin + (nuMax - nuMin) * i1 / (n1 - 1)
    for iR in range(nR):
        print("rStudent(", nu, ")=%.6g" % ot.DistFunc.rStudent(nu))