Fit a multivariate Gaussian distribution

9 visualizzazioni (ultimi 30 giorni)
Sumera Zem
Sumera Zem il 1 Mar 2023
Modificato: Sumera Zem il 1 Mar 2023
I have a A that I am analyzing using Principal Component Analysis (PCA) to reduce the dimensionality. Once I have reduced the dimensionality, I am attempting to fit a multivariate Gaussian distribution probability density function. Here is the code I used.
A = rand(32, 10); % generate a matrix
[m,n] = size(A);
[U, ~, ~] = svd(1/m * (A)' * A); % singular value decomposition
k = 2; % choose number of principal components
A_p = (U(:,1:k)' * A')';
% Fit Gaussian density function to data
Mu = mean(A_p , 2); % mean
Sigma = cov(A_p'); % covariance
P = @(z) 1/((2*pi)^(n/2)*det(Sigma)^0.5)*exp(-0.5*(z-Mu)'*pinv(Sigma)*(z-Mu));
A_val = rand(32, 1); % new data for evaluation
delta = linspace(min(P(A_val)), max(P(A_val)), 1000);
Unfortunately, I have encountered three problems with my code that I am struggling to resolve. Firstly, I believe that P(A_val) should be a vector, but the code is not generating a vector. Secondly, the determinant of Sigma is becoming zero, resulting in an infinite delta value. Thirdly, I am using the formulation A_p = U(:,1:k)' * A for PCA, but I am encountering an error due to a size mismatch in the matrices. For this reason, change it to A_p = (U(:,1:k)' * A')'.

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by