File: t_NumericalSample_computation.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (86 lines) | stat: -rwxr-xr-x 3,567 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
80
81
82
83
84
85
86
#! /usr/bin/env python

from __future__ import print_function
from openturns import *
from math import *

TESTPREAMBLE()
RandomGenerator.SetSeed(0)

try:
    sample = NumericalSample(4, 3)
    sample[0] = NumericalPoint((1, 0, 9))
    sample[1] = NumericalPoint((2, 3, 5))
    sample[2] = NumericalPoint((5, 1, 8))
    sample[3] = NumericalPoint((6, 7, 2))

    print("sample=", repr(sample))
    print("min=", repr(sample.getMin()))
    print("max=", repr(sample.getMax()))
    print("mean=", repr(sample.computeMean()))
    print("covariance=", repr(sample.computeCovariance()))
    print("standard deviation=", repr(sample.computeStandardDeviation()))
    print("standard deviation per component=", repr(
        sample.computeStandardDeviationPerComponent()))
    print("Pearson correlation=", repr(sample.computePearsonCorrelation()))
    print("Spearman correlation=", repr(sample.computeSpearmanCorrelation()))
    print("Kendall tau=", repr(sample.computeKendallTau()))
    print("range per component=", repr(sample.computeRange()))
    print("median per component=", repr(sample.computeMedian()))
    print("Variance=", repr(sample.computeVariance()))
    print("Skewness=", repr(sample.computeSkewness()))
    print("Kurtosis=", repr(sample.computeKurtosis()))
    for i in range(10):
        print("Centered moment of order ", i, "=",
              sample.computeCenteredMoment(i))
    print("Marginal 1=", repr(sample.getMarginal(1)))
    indices = Indices(2)
    indices[0] = 2
    indices[1] = 0
    print("Marginal [2, 0]=", repr(sample.getMarginal(indices)))
    print("Rank=", repr(sample.rank()))
    print("Sort=", repr(sample.sort()))
    print("Sort according to component 0=", repr(
        sample.sortAccordingToAComponent(0)))
    prob = 0.25
    print("Quantile per component(", prob, ")=", repr(
        sample.computeQuantilePerComponent(prob)))
    pointCDF = NumericalPoint(sample.getDimension(), 0.25)
    print(
        "Empirical CDF(", repr(pointCDF), "=", sample.computeEmpiricalCDF(pointCDF))
    dim = 3
    R = CorrelationMatrix(dim)
    for i in range(1, dim):
        R[i, i - 1] = 0.25
    Rtmp = CorrelationMatrix(dim)
    for i in range(dim):
        for j in range(i):
            Rtmp[i, j] = 6.0 * asin(R[i, j] / 2.0) / pi
    print("Pearson correlation (exact)=", repr(R))
    print("Spearman correlation (exact)=", repr(Rtmp))
    sample[0] = NumericalPoint((1, 0, 9))
    sample[1] = NumericalPoint((2, 3, 9))
    sample[2] = NumericalPoint((5, 1, 9))
    sample[3] = NumericalPoint((2, 2, 9))
    print("Rank=", repr(sample.rank()))
    print("Rank component 0=", repr(sample.rank(0)))
    print("Sort=", repr(sample.sort()))
    print("Sort according to component 0=", repr(
        sample.sortAccordingToAComponent(0)))
    print("Spearman correlation=", repr(sample.computeSpearmanCorrelation()))
    print("Kendall tau=", repr(sample.computeKendallTau()))
    size = 10000
    normal = Normal(NumericalPoint(dim, 0.0), NumericalPoint(dim, 1.0), R)
    print("Normal=", repr(normal))
    print("covariance=", repr(normal.getCovariance()))
    normalSample = normal.getSample(size)
    print("Empirical covariance=", repr(normalSample.computeCovariance()))
    RPearson = normalSample.computePearsonCorrelation()
    print("Pearson correlation=", repr(RPearson))
    RSpearman = normalSample.computeSpearmanCorrelation()
    print("Spearman correlation=", repr(RSpearman))
# except TestFailed, ex :
except:
    import sys
    print("t_NumericalSample_computation.py",
          sys.exc_info()[0], sys.exc_info()[1])