| 1 | from openturns import * |
|---|
| 2 | from math import * |
|---|
| 3 | |
|---|
| 4 | def getColumn( numericalSample, idColumn ) : |
|---|
| 5 | output=NumericalSample(0,1) |
|---|
| 6 | for i in range( 0, numericalSample.getSize() ) : |
|---|
| 7 | output.add(NumericalPoint(1,numericalSample[i][idColumn])) |
|---|
| 8 | return output |
|---|
| 9 | |
|---|
| 10 | stochasticDimension = 2 |
|---|
| 11 | RandomGenerator().SetSeed(0) |
|---|
| 12 | # Analytical construction : Input |
|---|
| 13 | inputFunction = Description(2) |
|---|
| 14 | inputFunction[0] = "R" |
|---|
| 15 | inputFunction[1] = "S" |
|---|
| 16 | |
|---|
| 17 | # Analytical construction : Output |
|---|
| 18 | outputFunction = Description(1) |
|---|
| 19 | outputFunction[0] = "G" |
|---|
| 20 | |
|---|
| 21 | formulas = Description(outputFunction.getSize()) |
|---|
| 22 | formulas[0] = "R-S" |
|---|
| 23 | |
|---|
| 24 | LimitState = NumericalMathFunction(inputFunction, outputFunction, formulas) |
|---|
| 25 | |
|---|
| 26 | dim = LimitState.getInputNumericalPointDimension() |
|---|
| 27 | |
|---|
| 28 | # Mean |
|---|
| 29 | mean = NumericalPoint(dim, 0.0) |
|---|
| 30 | mean[0] = 3.0 |
|---|
| 31 | mean[1] = 2.0 |
|---|
| 32 | |
|---|
| 33 | # Standard deviation |
|---|
| 34 | sigma = NumericalPoint(dim, 0.0) |
|---|
| 35 | sigma[0] = 0.3 |
|---|
| 36 | sigma[1] = 0.2 |
|---|
| 37 | |
|---|
| 38 | corr = CorrelationMatrix(dim) |
|---|
| 39 | corr[0,0]=1.0 |
|---|
| 40 | corr[1,1]=1.0 |
|---|
| 41 | corr[1,0]=0.3 |
|---|
| 42 | corr[0,1]=0.3 |
|---|
| 43 | |
|---|
| 44 | myDistribution = Normal(mean, sigma, corr) |
|---|
| 45 | |
|---|
| 46 | vect = RandomVector(Distribution(myDistribution)) |
|---|
| 47 | |
|---|
| 48 | G = RandomVector(LimitState, vect) |
|---|
| 49 | |
|---|
| 50 | pointNumber = 1000 |
|---|
| 51 | print " From a stochastic experiment place of size = ", pointNumber |
|---|
| 52 | |
|---|
| 53 | inputSample = vect.getNumericalSample(pointNumber) |
|---|
| 54 | RSample=getColumn( inputSample, 0 ) |
|---|
| 55 | SSample=getColumn( inputSample, 1 ) |
|---|
| 56 | |
|---|
| 57 | stdev_R=sqrt(inputSample.computeVariancePerComponent()[0]) |
|---|
| 58 | stdev_S=sqrt(inputSample.computeVariancePerComponent()[1]) |
|---|
| 59 | mean_RS=inputSample.computeMean() |
|---|
| 60 | stdev_RS=inputSample.computeStandardDeviationPerComponent() |
|---|
| 61 | PearsonCorr=inputSample.computePearsonCorrelation() |
|---|
| 62 | |
|---|
| 63 | PearsonCorrAnalysis=CorrelationAnalysis().PearsonCorrelation(RSample,SSample) |
|---|
| 64 | SpearmanCorrAnalysis=CorrelationAnalysis().SpearmanCorrelation(RSample,SSample) |
|---|
| 65 | RSSCC=CorrelationAnalysis().SCC(RSample,SSample) |
|---|
| 66 | |
|---|
| 67 | outputSample = LimitState(inputSample) |
|---|
| 68 | minValue = outputSample.getMin()[0] |
|---|
| 69 | maxValue = outputSample.getMax()[0] |
|---|
| 70 | mean = outputSample.computeMean()[0] |
|---|
| 71 | stdev_G = sqrt(outputSample.computeCovariance()[0,0]) |
|---|
| 72 | |
|---|
| 73 | print "" |
|---|
| 74 | print "mean R et S = ", mean_RS |
|---|
| 75 | print "st dev R et S = ", stdev_RS |
|---|
| 76 | print "st dev R = ", stdev_R |
|---|
| 77 | print "st dev S = ", stdev_S |
|---|
| 78 | print "Pearson correlation = ", PearsonCorr |
|---|
| 79 | print "" |
|---|
| 80 | print "Pearson correlation analysis = ", PearsonCorrAnalysis |
|---|
| 81 | print "Spearman correlation analysis = ", SpearmanCorrAnalysis |
|---|
| 82 | print "SCC", RSSCC |
|---|
| 83 | print "" |
|---|
| 84 | print "min Value G = ", minValue |
|---|
| 85 | print "max Value G = ", maxValue |
|---|
| 86 | print "mean G = ", mean |
|---|
| 87 | print "st dev G = ", stdev_G |
|---|
| 88 | print "" |
|---|