Posts by author A. Yameogo EDF

Trapezoidal distribution using truncature and mixture

# this is a script to create a trapezoid like distribution
# ========================================================
# version OT 0.12.3


from openturns import *
from openturns_viewer import *
from math import *


# The four next lines are the only one the user has to fill in. (change the values)
# warning : the values must respect the following ordre : a<b<c<d

a=1.0 # lower bound
b=2.0 # lower bound of the uniform distribution 
c=5.0 # upper bound of the uniform distribution 
d=7.0 # upper bound

######################################################
####      Trapezoid shape distribution       #########
######################################################

#Creation of the distributions:
triang=Triangular(a,(a+d)/2,d) # regular triangular distribution
myTruncatedTriang1 = TruncatedDistribution(Distribution(triang),b,TruncatedDistribution.UPPER) # truncated dist. on the right
myTruncatedTriang2=TruncatedDistribution(Distribution(triang),c,TruncatedDistribution.LOWER) # truncated dist. on the left
unif=Uniform(b,c) # uniform distribution

aCollection=DistributionCollection(3)  # mixture of these distribution : see UseCasesGuide manual from OT documentation

aCollection[0]=Distribution(myTruncatedTriang1)
aCollection[1]=Distribution(unif)
aCollection[2]=Distribution(myTruncatedTriang2)


aCollection[0].setWeight((b-a)/2) # weight of each distribution in order to have a continuous final distribution
aCollection[1].setWeight(c-b)
aCollection[2].setWeight((d-c)/2)

myTrapezoid=Mixture(aCollection) #final distribution

OneHundredrealisations=myTrapezoid.getNumericalSample(1000000) # graph of the obtained distribution
sampleHistOpt=VisualTest.DrawHistogram(OneHundredrealisations)
sampleHistOpt.draw("sampleHistOpt")
Show(sampleHistOpt)
ViewImage(sampleHistOpt.getBitmap())