By using python, I want to fit Multivariate gaussian function to Multivariate Gaussian Mixture Model. What should I insert instead of places of three $ marks ? Note: There is missing for loop which will generate 3 Multivariate gaussian distributions. ####################################################
##########################
#Request libraries
##########################
import numpy as np
from matplotlib import cm
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from mpl_toolkits.mplot3d import Axes3D
import tensorflow as tf
import tensorflow_probability as tfp
T = 1
samplingFrequency = T/40
t = np.arange(-2.*T, 2.*T, samplingFrequency )
# Our 2-dimensional distribution will be over variables x and y
x,y = t,t
x,y= np.meshgrid(x, y)
# Mean vector and covariance matrix (pulseWidth or sigma)
mu1 = np.array([0., 0.]) #Mean vector for Gaussian pulse only
GPulseWidth = np.array([[ 1. , -0.5], [-0.5, 1.]]) #GPulseWidth just for 2D Gaussian distribution
# Pack x and y into a single 3-dimensional array
pos = np.empty(x.shape + (2,))
pos[:, :, 0] = x
pos[:, :, 1] = y
def Multivariate_gaussian(pos, mu1, GPulseWidth,Io):
n = mu1.shape[0]
pulseWidth_det = np.linalg.det(GPulseWidth)
pulseWidth_inv = np.linalg.inv(GPulseWidth) # linalg.inv(a) Compute the (multiplicative) inverse of a matrix
N = np.sqrt((2*np.pi)**n * pulseWidth_det)/ Io
# This einsum call calculates (x-mu1)T.Sigma-1.(x-mu1) in a vectorized
# way across all the input variables.
fac = np.einsum('...k,kl,...l->...', pos-mu1, pulseWidth_inv, pos-mu1)
return np.exp(-fac / 2) / N
# there is missing for loop whih will generate Multivariate_gaussian distributuins
# Multivariate Gaussian Mixture Model
##########################
tfd = tfp.distributions
mvgmm = tfd.MixtureSameFamily(
mixture_distribution=tfd.Categorical(probs= $ ), # replace $ by what ?
components_distribution=tfd.MultivariateNormalDiag(
loc=$, # replace $ by what ?
scale_diag= $ ) # replace $ by what ?
)data = np.stack((x.flatten(), y.flatten()), axis=1)
prob = mvgmm.prob(data).numpy()
plt.contour(x, y, prob.reshape((160, 160)));
surf=axs[1].plot_surface(xx, yy, prob.reshape((160,160)), label = 'z location ' + str(zStep), cmap='plasma',linewidth=1, antialiased=False,alpha=0.5)