The Rayleigh distribution is a probability distribution used to model the magnitudes of random vectors whose components follow independent Gaussian (normal) distributions. It’s relevant in various fields like signal processing, physics, and oceanography. NumPy provides the np.random.rayleigh
function to generate random samples from this distribution.
Here’s a detailed breakdown of the Rayleigh distribution and its usage in NumPy:
Key Characteristics:
- Magnitude of Gaussian Vectors: The Rayleigh distribution applies to the magnitude (or norm) of a two-dimensional vector where the x and y components are independent Gaussian random variables with zero mean.
- Probability Density Function (PDF): The PDF of the Rayleigh distribution is defined as:
f(x) = (x / ฯ^2) * exp(-x^2 / (2 * ฯ^2))
for x โฅ 0- Here, ฯ (sigma) is the scale parameter, which relates to the standard deviation (SD) of the underlying Gaussian distribution by ฯ = SD * sqrt(2). A larger ฯ indicates a wider spread of magnitudes.
Applications:
- Signal Processing: Modeling the envelope of fluctuating signals (e.g., radio waves).
- Physics: Analyzing the distribution of wind speeds or the magnitude of vibrations.
- Oceanography: Studying wave heights or the strength of ocean currents.
Generating Random Samples with np.random.rayleigh
:
import numpy as np
# Generate 10 random samples with scale parameter 2.0 (sigma=sqrt(2))
samples = np.random.rayleigh(scale=2.0, size=10)
print(samples)
Parameters:
scale
(float or array-like of floats): The scale parameter (default: 1.0) controls the spread of the distribution. A larger scale corresponds to a wider distribution of magnitudes.size
(int or tuple of ints, optional): The desired output shape. If left as None (default), it returns a single value ifscale
is a scalar, otherwise an array with the same shape asscale
.
In essence, the np.random.rayleigh
function in NumPy is a convenient tool to generate random samples representing the magnitudes of two-dimensional Gaussian vectors. This distribution is useful in various scientific and engineering domains where analyzing such magnitudes is crucial.
Leave a Reply