Karhunen Loeve Expansion in Matlab

  • Context: MATLAB 
  • Thread starter Thread starter confused_engineer
  • Start date Start date
  • Tags Tags
    Expansion Matlab
Click For Summary
SUMMARY

The forum discussion centers on generating the Karhunen-Loeve (KL) expansion of a stochastic process using MATLAB. The user employs a Monte Carlo sampling method with two random variables, calculating the autocovariance matrix to extract eigenvalues and eigenvectors. However, discrepancies arise when comparing the mean of the transformed variable Y to the theoretical mean of the original stochastic process S. A suggestion is made to utilize Singular Value Decomposition (SVD) for better stability and accuracy in deriving principal components.

PREREQUISITES
  • Understanding of Karhunen-Loeve expansion
  • Proficiency in MATLAB programming
  • Familiarity with Monte Carlo sampling methods
  • Knowledge of eigenvalue decomposition and autocovariance matrices
NEXT STEPS
  • Learn MATLAB's Singular Value Decomposition (SVD) function
  • Study the implementation of Karhunen-Loeve expansion in MATLAB
  • Explore the statistical properties of autocovariance matrices
  • Review the book "Probability, Statistics, and Random Processes for Electrical Engineering" by Alberto Leon Garcia
USEFUL FOR

Researchers, data scientists, and engineers working with stochastic processes, particularly those utilizing MATLAB for statistical analysis and modeling.

confused_engineer
Messages
34
Reaction score
1
Hello everyone.

I am trying to generate the KL expansion of a stochastic process. I use a Monte Carlo sampling method to generate the process, which involves two random variables and I compare it with it's theoretical mean for 50 values of time and they look quite similar. Then, I calculate the autocovariance matrix, from where I extract the eigenvalues and eigenvectors which are used to calculate the new variable Y which is the stochastic process S in a base where the random variables are not correlated. However, if I calculate the mean of Y it doesn't look like the the mean of S at all.

Can someone please tell me what am I doing wrong?
Thank you very much for reading.

clear
close all
V = unifrnd(1,2,1,10000);
A = betarnd(2,2,1,10000);
t=50;
for i=1:t
S(i,:)=V*i+0.5*A*i^2;
theoreticalmeanS(i)=3/2*i+1/4*i^2;
meanS(i)=mean(S(i));
end
for i=1:t
for j=1:t
AutocorrelationS(i,j)=(S(i,:)*S(j,:)')/10000;
AutocovarianceS(i,j)=(S(i,:)*S(j,:)')/10000-meanS(i)*meanS(j);
end
end

[eigenvectors, eigenvalues]=eig(AutocovarianceS);
eigenvalues_column=eig(AutocovarianceS);
Y=eigenvalues*S;Note: I am following the book of Alberto Leon Garcia (probability statistics and random processes for electrical engineering), pages 324-325.
 
Physics news on Phys.org
Not sure if I can help here (I am extremely familiar with the core of MATLAB, but not with its stats toolbox, which you appear to be using), but let me ask a question: For the data sizes you're dealing with, is there a reason not to use SVD to give you the PCs and their weights directly, instead of going through the covariance intermediate and finding eigenvalues?

My reason for asking is partly just that, in theory and in my experience, SVD is more stable and well-behaved than EVD (and there are deep reasons for that). For instance, with round-off, you might have a complex eigenvalue for the covariance matrix; SVD is simply not capable of that.
 
confused_engineer said:
for i=1:t
S(i,:)=V*i+0.5*A*i^2;
theoreticalmeanS(i)=3/2*i+1/4*i^2;
meanS(i)=mean(S(i));
end

What does ##S(i,k)## represent? The ##k## value of the ##i##th realization of the process? - or the ##i##th value of the ##k##th realization of the process? (If the process takes place in time, which index represents time?)
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K