Python: how to randomly sample from nonstandard Cauchy distribution, hence with different parameters?
Asked Answered
L

2

7

I was looking here: numpy

And I can see you can use the command np.random.standard_cauchy() specifying an array, to sample from a standard Cauchy.

I need to sample from a Cauchy which might have x_0 != 0 and gamma != 1, i.e. might not be located at the origin, nor have scale equal to 1.

How can I do this?

Lacilacie answered 17/7, 2017 at 8:51 Comment(0)
K
6

If you have scipy, you can use scipy.stats.cauchy, which takes a location (x0) and a scale (gamma) parameter. It exposes the rvs method to draw random samples:

x = stats.cauchy.rvs(loc=100, scale=2.5, size=1000)  # draw 1000 samples
Knucklehead answered 17/7, 2017 at 9:42 Comment(0)
T
6

You may avoid the dependency on SciPy, since the Cauchy distribution is part of the location-scale family. That means, if you draw a sample x from Cauchy(0, 1), just shift it by x_0 and multiply with gamma and x' = x_0 + gamma * x will be distributed according to Cauchy(x_0, gamma).

Tearful answered 5/11, 2021 at 8:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.