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 109 110 111 112 113 114 115 116
|
#! /usr/bin/env python
from __future__ import print_function
from openturns import *
from math import *
TESTPREAMBLE()
RandomGenerator.SetSeed(0)
def printSample(name, sample):
oss = name + "=["
for counter in range(sample.getSize()):
if (counter != 0):
oss += ";"
oss += "["
point = sample[counter]
for coordinate in range(point.getDimension()):
if (coordinate != 0):
oss += ","
oss += "%.6f" % point[coordinate]
oss += "]"
oss += "]"
return oss
try:
# We create a numerical math function
myFunction = NumericalMathFunction(
["x1", "x2"], ["y1"], ["(x1-0.3)*(x1-0.3)-x2*x2"])
dim = myFunction.getInputDimension()
# We create a normal distribution point of dimension 1
mean = NumericalPoint(dim, 0.0)
sigma = NumericalPoint(dim, 1.0)
R = IdentityMatrix(dim)
myDistribution = Normal(mean, sigma, R)
# We create a 'usual' RandomVector from the Distribution
vect = RandomVector(myDistribution)
# We create a composite random vector
output = RandomVector(myFunction, vect)
# We create a StandardEvent from this RandomVector : RandomVector > 0.0
seuil = 10
myStandardEvent = StandardEvent(
output, Greater(), seuil)
# We create the design point
designPoint = NumericalPoint(dim, 0.0)
C = 0.3
designPoint[0] = - sqrt(seuil) + C
# We create the "second" design point
pseudoDesignPoint = NumericalPoint(dim, 0.0)
pseudoDesignPoint[0] = sqrt(seuil) + C
importanceLevel = 0.01
accuracyLevel = 2
confidenceLevel = 0.999999
myTest = StrongMaximumTest(
myStandardEvent, designPoint, importanceLevel, accuracyLevel, confidenceLevel)
print("myTest=", myTest)
myTest.run()
print("Beta = %.6f" % designPoint.norm())
print("Discretised sphere radius = %.6f" % (
designPoint.norm() * (1 + myTest.getAccuracyLevel() * myTest.getDeltaEpsilon())))
print("PointNumber = ", myTest.getPointNumber())
print("DesignPointVicinity Angle (rad)= %.6f" %
acos(myTest.getDesignPointVicinity()))
print("DesignPointVicinity Angle (deg)= %.6f" %
(acos(myTest.getDesignPointVicinity()) * 180 / pi))
print("Near Design Point Verifying Event Points Number = ", (
myTest.getNearDesignPointVerifyingEventPoints()).getSize())
print("Near Design Point Violating Event Points Number = ", (
myTest.getNearDesignPointViolatingEventPoints()).getSize())
print("Far Design Point Verifying Event Points Number = ", (
myTest.getFarDesignPointVerifyingEventPoints()).getSize())
print("Far Design Point Violating Event Points Number = ", (
myTest.getFarDesignPointViolatingEventPoints()).getSize())
print("//////")
# parameters of the test
print("importanceLevel=%.6f" % myTest.getImportanceLevel())
print("accuracyLevel=%.6f" % myTest.getAccuracyLevel())
print("confidenceLevel=%.6f" % myTest.getConfidenceLevel())
# design point coordinates
print("standardSpaceDesignPoint=[%.6f" % myTest.getStandardSpaceDesignPoint()[
0], ",%.6f" % myTest.getStandardSpaceDesignPoint()[1], "]")
# pseudo design point coordinates
print("pseudoStandardSpaceDesignPoint=[%.6f" % pseudoDesignPoint[
0], ",%.6f" % pseudoDesignPoint[1], "]")
# cout of the coordinates of the points of the 4 samples
# NearDesignPointVerifyingEventPoints
print(printSample("NearDesignPointVerifyingEventPointsSample",
myTest.getNearDesignPointVerifyingEventPoints()))
# NearDesignPointViolatingEventPoints
print(printSample("NearDesignPointViolatingEventPoints",
myTest.getNearDesignPointViolatingEventPoints()))
# FarDesignPointVerifyingEventPoints
print(printSample("FarDesignPointVerifyingEventPoints",
myTest.getFarDesignPointVerifyingEventPoints()))
# FarDesignPointViolatingEventPoints
print(printSample("FarDesignPointViolatingEventPoints",
myTest.getFarDesignPointViolatingEventPoints()))
# print "myTest (after run())=" , myTest
except:
import sys
print("t_strongMaxTest_std.py", sys.exc_info()[0], sys.exc_info()[1])
|