The NumPy Rayleigh Distribution is a probability distribution that is used to model the magnitude of a vector in two or three dimensions. It is named after Lord Rayleigh, who first described it in the context of the scattering of light.
The Rayleigh Distribution is a continuous probability distribution with a single parameter, sigma. The probability density function (PDF) of the Rayleigh Distribution is given by:
f(x; sigma) = (x / sigma^2) * exp(-x^2 / (2 * sigma^2))
where x is the magnitude of the vector and sigma is the scale parameter.
The cumulative distribution function (CDF) of the Rayleigh Distribution is given by:
F(x; sigma) = 1 - exp(-x^2 / (2 * sigma^2))
The Rayleigh Distribution is commonly used in signal processing, where it is used to model the amplitude of noise in a signal. It is also used in physics, where it is used to model the distribution of particle velocities in a gas.
Here are some code examples that demonstrate how to use the NumPy Rayleigh Distribution:
To generate random numbers from the Rayleigh Distribution, you can use the numpy.random.rayleigh()
function. The following code generates 1000 random numbers from a Rayleigh Distribution with a scale parameter of 2:
<pre><code>import numpy as np
# Generate 1000 random numbers from a Rayleigh Distribution with a scale parameter of 2
x = np.random.rayleigh(scale=2, size=1000)
print(x)</code></pre>
To calculate the probability density function (PDF) of the Rayleigh Distribution, you can use the numpy.random.rayleigh()
function in combination with the numpy.histogram()
function. The following code calculates the PDF of a Rayleigh Distribution with a scale parameter of 2:
<pre><code>import numpy as np
import matplotlib.pyplot as plt
# Generate 1000 random numbers from a Rayleigh Distribution with a scale parameter of 2
x = np.random.rayleigh(scale=2, size=1000)
# Calculate the PDF of the Rayleigh Distribution
hist, bins = np.histogram(x, bins=50, density=True)
bin_centers = (bins[1:] + bins[:-1]) / 2
pdf = bin_centers / 4 * np.exp(-bin_centers**2 / 8)
# Plot the PDF of the Rayleigh Distribution
plt.plot(bin_centers, pdf, label='PDF')
plt.hist(x, bins=50, density=True, alpha=0.5, label='Histogram')
plt.legend()
plt.show()</code></pre>
To calculate the cumulative distribution function (CDF) of the Rayleigh Distribution, you can use the numpy.cumsum()
function. The following code calculates the CDF of a Rayleigh Distribution with a scale parameter of 2:
<pre><code>import numpy as np
import matplotlib.pyplot as plt
# Generate 1000 random numbers from a Rayleigh Distribution with a scale parameter of 2
x = np.random.rayleigh(scale=2, size=1000)
# Calculate the CDF of the Rayleigh Distribution
hist, bins = np.histogram(x, bins=50, density=True)
cdf = np.cumsum(hist * np.diff(bins))
# Plot the CDF of the Rayleigh Distribution
plt.plot(bins[:-1], cdf, label='CDF')
plt.legend()
plt.show()</code></pre>