Question about the PCA function

  • Thread starter confused_engineer
  • Start date
  • Tags
    Function Pca
In summary, the PCA (Principal Component Analysis) function is used for dimensionality reduction, data compression, and identifying patterns and relationships between variables. It works by identifying the directions of maximum variance in a dataset and projecting the data onto these directions. The benefits of using the PCA function include reducing the number of variables, simplifying complex data, and improving the performance of machine learning algorithms. However, the PCA function assumes that the data is linearly related, normally distributed, standardized, and has no multicollinearity. It is most useful in situations with a large number of variables and complex data, for data exploration, visualization, and improving machine learning models.
  • #1
confused_engineer
39
2
TL;DR Summary
The results obtained from appying the pca command dont' match with the theoretical results. The obtained random variables should be standard gaussian. However, I don't obtain that.
Greetings everyone.

I have generated a gaussian random process composed of 500 realizations and 501 observations. The used random variables are gaussian normal.
I have then applied the pca analysis to that process (Mathwork's help). However, if I plot the histograms of the coeffs I don't find gaussian random variables, the variables are gaussian but not standard as specified in page 10 of the Followed article, just before section 6.

Is there something wrong with my code (see below) am I misunderstanding the article or the pca function from MATLAB?

I need help since I can't see a solution to this problem.
Thanks.

Problem:
close all
clear
clc

 
[X,Y] = meshgrid(0:0.002:1,0:0.002:1);
Z=exp((-1)*abs(X-Y));

tam=size(X, 1);

number_realizations=500;realizacion_mat=zeros(tam, number_realizations);
cov_mat=cov(Z);
[evec_mal, evalM_mal]=eig(cov_mat);
eval_mal=eig(evalM_mal);
num_eval=size(eval_mal,1);

for i=1:num_eval
    eval(i)=eval_mal(num_eval-i+1);
    evec(:,i)=evec_mal(:,num_eval-i+1);
end
figure
hold on
for j=1:number_realizations
  
    realizacion=zeros(tam, 1);
    for i=1:tam
        v_a = normrnd(0,1);
        realizacion=realizacion+sqrt(eval(i))*evec(:,i)*v_a;
    end
    realizacion_mat(:,j)=realizacion;
    plot(realizacion)
    clear('realizacion')
end

[coeff,score,latent,tsquared,explained,mu] = pca(realizacion_mat,'Centered',false);

realizaciones=size (realizacion_mat, 2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
number_figures=6;
number_bins=10;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%for i=1:number_figures
    a= num2str(i);
    figure
    histogram(coeff(i,:), number_bins)
    xlabel(['\omega'])
    ylabel(['\xi_' ,num2str(i), '(\omega)'])
end
 
Physics news on Phys.org
  • #2


Thank you for sharing your work and seeking help with your problem. I am a scientist with experience in PCA analysis and I would be happy to provide some insights and suggestions.

Firstly, I would like to commend you for your thorough approach and the clear presentation of your code. This makes it easier for others to understand and help with your problem.

From your description, it seems that you have correctly applied the PCA analysis to your gaussian random process. However, the issue you are facing is with the resulting histograms of the coefficients not being gaussian. Based on the information you have provided, I believe there could be a few reasons for this.

1. The number of realizations may not be enough to accurately represent the process:

In your code, you have generated 500 realizations of the process, which may not be enough to accurately represent the underlying distribution. The number of realizations required for accurate representation may depend on the complexity of your process and the number of observations. I would suggest trying with a larger number of realizations and see if there is any improvement in the gaussianity of the coefficients.

2. The underlying process may not be purely gaussian:

It is possible that the underlying process itself is not purely gaussian, which could result in non-gaussian coefficients. In such cases, the PCA analysis may not be the best approach. I would suggest checking the distribution of your initial data and if it is not purely gaussian, you may need to explore other statistical methods that are better suited for non-gaussian data.

3. The use of the "Centered" parameter in the PCA function:

In your code, you have specified the 'Centered' parameter as false, which means that the data is not being centered before performing the PCA analysis. This could also affect the resulting coefficients and histograms. I would suggest trying with the 'Centered' parameter set to true and see if there is any improvement in the gaussianity of the coefficients.

Overall, I would suggest exploring these possibilities and making appropriate changes to your code to see if there is any improvement in the results. I hope this helps and wish you all the best in finding a solution to your problem.
 

1. What is the PCA function used for?

The PCA (Principal Component Analysis) function is a statistical technique used for dimensionality reduction, which is the process of reducing the number of variables in a dataset while retaining the most important information. It is commonly used in data analysis and machine learning to simplify complex data and make it more manageable for further analysis.

2. How does the PCA function work?

The PCA function works by identifying patterns and relationships among variables in a dataset and then transforming the data into a new coordinate system that highlights these patterns. It does this by finding the principal components, which are new variables that are a combination of the original variables, and ordering them by their importance. The first principal component explains the most variation in the data, followed by the second, and so on.

3. What are the benefits of using the PCA function?

The PCA function has several benefits, including reducing the dimensionality of complex data, improving the performance of machine learning algorithms by removing noise and redundant information, and visualizing high-dimensional data in a lower-dimensional space. It also helps with data interpretation and identifying the most important features in a dataset.

4. Are there any limitations to using the PCA function?

While the PCA function is a useful tool, it does have some limitations. It assumes that the data is linear, which may not always be the case. It can also be affected by outliers, and the interpretation of the principal components may not always be straightforward. Additionally, the results of PCA may vary depending on the scale and type of data used.

5. How do I choose the number of principal components to use?

The number of principal components to use can be chosen based on the amount of variance explained by each component. Typically, a threshold of 70-80% is used, meaning that the chosen components should explain at least 70-80% of the total variance in the data. Other methods, such as the Kaiser criterion and scree plot, can also be used to determine the appropriate number of components.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
859
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
954
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
885
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
0
Views
506
  • Introductory Physics Homework Help
Replies
2
Views
869
Back
Top