File: t_PhysicalSpaceCrossEntropyImportanceSampling_std.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 (44 lines) | stat: -rwxr-xr-x 1,560 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python

import openturns as ot
from openturns.testing import assert_almost_equal

ot.RandomGenerator.SetSeed(1)

distributionR = ot.LogNormalMuSigma(300.0, 30.0, 0.0).getDistribution()
distributionF = ot.Normal(75.0e3, 5.0e3)
marginals = [distributionR, distributionF]
distribution = ot.JointDistribution(marginals)

model = ot.SymbolicFunction(["R", "F"], ["R - F / (pi_ * 100.0)"])
vect = ot.RandomVector(distribution)
g = ot.CompositeRandomVector(model, vect)
event = ot.ThresholdEvent(g, ot.Less(), -50.0)

distributionMargin1 = ot.LogNormalMuSigma().getDistribution()
distributionMargin2 = ot.Normal()
auxMarginals = [distributionMargin1, distributionMargin2]
auxDistribution = ot.JointDistribution(auxMarginals)

activeParameters = [0, 1, 2, 3, 4]
bounds = ot.Interval([3, 0.09, 0.0, 50e3, 2e3], [7, 0.5, 0.5, 100e3, 10e3])
initialTheta = [5.70, 0.1, 0.0, 75.0e3, 5.0e3]

algo = ot.PhysicalSpaceCrossEntropyImportanceSampling(
    event, auxDistribution, activeParameters, initialTheta, bounds, 0.3
)

algo.setKeepSample(True)
algo.setOptimizationAlgorithm(ot.TNC())
algo.run()
result = algo.getResult()
print(result)
assert_almost_equal(result.getProbabilityEstimate(), 0.000135442, 5e-2, 0.0)

# check that the event sample is right
stepsNumber = algo.getStepsNumber()
inputEventSample = algo.getInputSample(stepsNumber - 1, algo.EVENT1)
outputEventSample = algo.getOutputSample(stepsNumber - 1, algo.EVENT1)
outputG = model(inputEventSample)
diffSample = outputG - outputEventSample
assert_almost_equal(diffSample.computeMean(), [0.0])