Question: ( 2 0 pts ) One nice property for Gaussian distributions is that if we marginalize over any subset of dimensions of a multivariate Gaussian,

(20 pts) One nice property for Gaussian distributions is that if we marginalize over any subset
of dimensions of a multivariate Gaussian, the resulting distribution is also Gaussian. To marginalize a
multivariate random variable means to find the distribution of only the marginalized random variables and
eliminate from the distribution the other random variables. This is achieved by adding or integrating the
distribution function with respect to all other random variables, e.g. for a continuous multivariate random
variable (,) with PDF ,(,) we can marginalize on x by doing ()=,(,)
+\infty
\infty . This means
the distribution of a marginalized multivariate Gaussian distribution looks like the familiar bell shape
characteristic of a univariate Gaussian distribution.
a) Use the below code to generate the PDF for a bivariate Gaussian. Then, in a separate figure, plot the
PDF when you marginalize (integrate with respect to ), and overlay a plot of the PDF when you
marginalize (integrate with respect to ), both on the same plot using legends.
b) Using your knowledge of the Gaussian PDF, estimate the mean of each marginal distribution and display
these means on your plot.
Show your plot and code.
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import multivariate_normal
# Define mean (mu) and covariance matrix (sigma)
mu = np.array([0,3])
sigma = np.array([[5,-2],[-2,2]])
# Create a grid of x1 and x2 values
x1= np.arange(-10,10.1,0.1)
x2= np.arange(-10,10.1,0.1)
X1, X2= np.meshgrid(x1, x2)
# Create a multivariate normal distribution
mvn = multivariate_normal(mean=mu, cov=sigma)
# Calculate the PDF values for each point in the grid
pdf_values = mvn.pdf(np.column_stack((X1.ravel(), X2.ravel())))
# Reshape the PDF values to match the grid shape
F = pdf_values.reshape(X1.shape)
# Create a contour plot
plt.contour(x1, x2, F)
# Set plot attributes
plt.grid(True)
plt.axis('square')
plt.title('Your Name CMPE 677, Hwk 1, Problem 10', fontsize=12)
# Save the plot as a PNG file
plt.savefig('cmpe677_hwk1_10.png', format='png')
# Show the plot
plt.show()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!