To generate data from the intersection of two multi-dimensional Gaussian distributions, you can use the following Python code. This code uses the NumPy library to generate random numbers from the specified Gaussian distributions and then filters them to keep only the points that lie within the intersection of the two distributions.
python
import numpy as np
def multivariate_normal(x, mu, covariance):
return np.random.multivariate_normal(mu, covariance, x)
# Define the two Gaussian distributions
mu1 = np.array([0, 0])
covariance1 = np.array([[1, 0.5], [0.5, 1]])
mu2 = np.array([2, 2])
covariance2 = np.array([[1.5, 1], [1, 1.5]])
n_samples = 1000
# Generate data from the first Gaussian distribution
data1 = multivariate_normal(n_samples, mu1, covariance1)
# Generate data from the second Gaussian distribution
data2 = multivariate_normal(n_samples, mu2, covariance2)
# Find the intersection of the two Gaussian distributions
intersection_indices = []
for i in range(n_samples):
distance1 = np.linalg.norm(data1[i] - mu1)
distance2 = np.linalg.norm(data2[i] - mu2)
if distance1 <= 1 and distance2 <= 1:
intersection_indices.append(i)
intersection_data = np.concatenate((data1[intersection_indices], data2[intersection_indices]))
# Print the generated data
print("Intersection of the two Gaussian distributions:")
print(intersection_data)
This code snippet first defines two multi-dimensional Gaussian distributions with different means and covariance matrices. It then generates random samples from each distribution and computes the distance between each sample and the means of the two distributions. Samples with distances less than or equal to 1 (the standard deviations) are considered to be part of the intersection of the two distributions and are saved in the intersection_indices list. Finally, the code concatenates the filtered samples from both distributions into the intersection_data array and prints the result.