Hi!
I would like to perform a Monte-Carlo simulation which fails to converge. To create it, I selected the Cauchy distribution https://en.wikipedia.org/wiki/Cauchy_distribution.
However, I could not find it in the library: did I miss something?
Best regards,
Michaël
PS
As a workaround, I created it based on the PythonDistribution
class:
class Cauchy(ot.PythonDistribution):
def __init__(self, location=0.0, scale=1.0):
super(Cauchy, self).__init__(1)
self.location = location
self.scale = scale
def computeCDF(self, x):
u = x[0]
xi = (u - self.location) / self.scale
p = np.arctan(xi) / np.pi + 0.5
return p
def computePDF(self, x):
u = x[0]
xi = (u - self.location) / self.scale
y = 1.0 / (np.pi * self.scale * (1.0 + xi ** 2))
return y
def getRange(self):
epsilon = ot.ResourceMap.GetAsScalar("Distribution-DefaultCDFEpsilon")
z_min = np.tan(np.pi * (epsilon - 0.5))
x_min = self.location + self.scale * z_min
z_max = np.tan(np.pi * (0.5 - epsilon))
x_max = self.location + self.scale * z_max
return ot.Interval(x_min, x_max)
def computeQuantile(self, prob, tail=False):
if tail:
z = np.tan(np.pi * (0.5 - prob))
else:
z = np.tan(np.pi * (prob - 0.5))
x = self.location + self.scale * z
return [x]
However, the getSample
method is quite slow … until the computeQuantile
method is implemented!