e4 = e1.join(e2) #print('e4=', e4) proba_e4 = e4.getSample(10000).computeMean()[0] print("proba_e4 = %.3g" % proba_e4) ott.assert_almost_equal(proba_e4, 0.75, 1e-2, 1e-2) e5 = ot.IntersectionEvent([e1, e2]) #print('e5=', e5) proba_e5 = e5.getSample(10000).computeMean()[0] print("proba_e5 = %.3g" % proba_e5) ott.assert_almost_equal(proba_e5, 0.25, 1e-2, 1e-2) e6 = ot.UnionEvent([e1, e2]) #print('e6=', e6) proba_e6 = e6.getSample(10000).computeMean()[0] print("proba_e6 = %.3g" % proba_e6) ott.assert_almost_equal(proba_e6, 0.75, 1e-2, 1e-2) # intersection of intersection e7 = ot.IntersectionEvent([e1, ot.IntersectionEvent([e1, e2])]) ott.assert_almost_equal(e7.getSample(10000).computeMean()[0], 0.25, 1e-2, 1e-2) e8 = ot.IntersectionEvent([ot.IntersectionEvent([e1, e2]), e1]) ott.assert_almost_equal(e8.getSample(10000).computeMean()[0], 0.25, 1e-2, 1e-2) # union of union e9 = ot.UnionEvent([e1, ot.UnionEvent([e1, e2])])
myPolygon = ot.Polygon(data) myPolygon.setColor('grey') myPolygon.setEdgeColor('black') myGraph.add(myPolygon) view = otv.View(myGraph) axes = view.getAxes() _ = axes[0].set_xlim(-4.0, 4.0) _ = axes[0].set_ylim(-4.0, 4.0) # %% # The probability of that event is :math:`P_{E_4} = 1/4`. A basic estimator is: print("Probability of e4 : %.4f" % e4.getSample(10000).computeMean()[0]) # %% # We define the union :math:`E_5 = E1 \bigcup E_2`. It is the whole plan without the lower right quadrant. e5 = ot.UnionEvent([e1, e2]) # %% # The restriction of the domain :math:`E_5` to :math:`[-4,4] \times [-4, 4]` is the grey area. myGraph = ot.Graph(r'Representation of the event $E_5 = E_1 \bigcup E_2$', r'$x_1$', r'$x_2$', True, '') data = [[-4, -4], [0, -4], [0, 0], [4, 0], [4, 4], [-4, 4]] myPolygon = ot.Polygon(data) myPolygon.setColor('grey') myPolygon.setEdgeColor('black') myGraph.add(myPolygon) view = otv.View(myGraph) axes = view.getAxes() _ = axes[0].set_xlim(-4.0, 4.0) _ = axes[0].set_ylim(-4.0, 4.0)
solver.setMaximumIterationNumber(1000) solver.setMaximumAbsoluteError(1.0e-3) solver.setMaximumRelativeError(1.0e-3) solver.setMaximumResidualError(1.0e-3) solver.setMaximumConstraintError(1.0e-3) for event in [e0, e3, e4, e5, e1, e2]: algo = ot.FORM(solver, event, mean) algo.run() result = algo.getResult() print('beta = %.6g' % result.getGeneralisedReliabilityIndex()) # system event in DNF form (union of intersections) event = ot.UnionEvent([ ot.IntersectionEvent([e0, e3, e4, e5]), ot.IntersectionEvent([e1, e3, e4, e5]), ot.IntersectionEvent([e2, e3, e4, e5]) ]) # sampling test pf_sim = event.getSample(100000).computeMean()[0] print('pf_sim = %.6g' % pf_sim) ott.assert_almost_equal(pf_sim, 0.00384, 1e-4, 1e-4) # system FORM algo = ot.SystemFORM(solver, event, mean) algo.run() result = algo.getResult() pf_sysform = result.getEventProbability() print('pf_sysform = %.6g' % pf_sysform) ott.assert_almost_equal(pf_sysform, 0.00418394, 1e-4, 1e-4)