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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#! /usr/bin/env python
import openturns as ot
import math as m
ot.TESTPREAMBLE()
sample = ot.Sample(4, 3)
sample[0] = ot.Point((1, 0, 9))
sample[1] = ot.Point((2, 3, 5))
sample[2] = ot.Point((5, 1, 8))
sample[3] = ot.Point((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("Pearson correlation=", repr(sample.computeLinearCorrelation()))
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.computeCentralMoment(i))
print("Marginal 1=", repr(sample.getMarginal(1)))
indices = ot.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)),
)
probs = [0.25, 0.75]
print(
"Quantile per component(",
probs,
")=",
repr(sample.computeQuantilePerComponent(probs)),
)
probs = [0.75, 0.25]
print(
"Quantile per component(",
probs,
")=",
repr(sample.computeQuantilePerComponent(probs)),
)
pointCDF = ot.Point(sample.getDimension(), 0.25)
print("Empirical CDF(", repr(pointCDF), "=", sample.computeEmpiricalCDF(pointCDF))
dim = 3
R = ot.CorrelationMatrix(dim)
for i in range(1, dim):
R[i, i - 1] = 0.25
Rtmp = ot.CorrelationMatrix(dim)
for i in range(dim):
for j in range(i):
Rtmp[i, j] = 6.0 * m.asin(R[i, j] / 2.0) / m.pi
print("Pearson correlation (exact)=", repr(R))
print("Spearman correlation (exact)=", repr(Rtmp))
sample[0] = ot.Point((1, 0, 9))
sample[1] = ot.Point((2, 3, 9))
sample[2] = ot.Point((5, 1, 9))
sample[3] = ot.Point((2, 2, 9))
print("Rank=", repr(sample.rank()))
print("Rank component 0=", repr(sample.rank(0)))
print("Sort =", repr(sample.sort()))
sample2 = ot.Sample(sample)
sample2.sortInPlace()
print("Sort (in place)=", repr(sample2))
print(
"Sort according to component 0 =",
repr(sample.sortAccordingToAComponent(0)),
)
sample2 = ot.Sample(sample)
sample2.sortAccordingToAComponentInPlace(0)
print("Sort according to component 0 (in place)=", repr(sample2))
print("Spearman correlation=", repr(sample.computeSpearmanCorrelation()))
print("Kendall tau=", repr(sample.computeKendallTau()))
size = 10000
normal = ot.Normal(ot.Point(dim, 0.0), ot.Point(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.computeLinearCorrelation()
print("Pearson correlation=", repr(RPearson))
RSpearman = normalSample.computeSpearmanCorrelation()
print("Spearman correlation=", repr(RSpearman))
print("Unique =", repr(sample.sortUnique()))
sample2 = ot.Sample(sample)
sample2.sortUniqueInPlace()
print("Unique (in place)=", repr(sample2))
sample[2] = ot.Point((1, 0, 9))
print("Unique =", repr(sample.sortUnique()))
sample2 = ot.Sample(sample)
sample2.sortUniqueInPlace()
print("Unique (in place)=", repr(sample2))
|