Author: David Salac https://github.com/david-salac/
Generator of the random samples following the Multivariate Double Exponential (Laplace) Distribution.
Implementation is the extension of the SciPy and follows the same logic as the generator following the multivariate normal distribution.
To generate the samples matrix, you need to have a vector of mean values and the
covariance matrix. Samples are generated by the function rvs
that accepts as
parameters mean values vector, covariance matrix and size of generated samples.
A probability distribution can be computed using pdf
function.
Example:
import numpy as np
from multivariate_laplace import multivariate_laplace
x, y = np.mgrid[-1:1:0.01, -1:1:0.01]
pos = np.empty(x.shape + (2,))
pos[:, :, 0] = x
pos[:, :, 1] = y
mean_values_vector = [0.5, -0.2]
covariance_matrix = [[2.0, 0.3], [0.3, 0.5]]
generator = multivariate_laplace(mean_values_vector, covariance_matrix)
# Get the probability distribution
probability_distribution = generator.pdf(pos)
# Get the random samples
number_of_samples = len(x) # Redefine to what is needed
samples = multivariate_laplace.rvs(mean=mean_values_vector,
cov=covariance_matrix,
size=number_of_samples)
Samples are stored in the variable sample_matrix.
If you want to run the demo script, you need to satisfy the requirements that
are enumerated in the file requirements_demo.txt
. You can install them
directly using PIP:
pip install -r requirements_demo.txt
Sufficient requirements for running the multivariate Laplace distribution
script is in the file requirements.txt
and can be installed via PIP:
pip install -r requirements.txt