-
Notifications
You must be signed in to change notification settings - Fork 0
/
calcStationaryDist.m
23 lines (19 loc) · 1.03 KB
/
calcStationaryDist.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function stationary_distribution = calcStationaryDist(transition_probabilities)
%Input- Transition Probability (The computation from calcFTProb.m function)
%Output- calcStationaryDist gives steady state behaviour of the future
%based on the eigenvalue computation and analysis.
% Ensure transition_probabilities is square
assert(size(transition_probabilities, 1) == size(transition_probabilities, 2), 'Transition probabilities matrix must be square')
% Compute the stationary distribution
[eigenvectors, eigenvalues] = eig(transition_probabilities');
% The stationary distribution corresponds to the eigenvector with an eigenvalue of 1
for i = 1:size(eigenvalues, 1)
if abs(eigenvalues(i,i) - 1) < 1e-8
stationary_distribution = real(eigenvectors(:, i)');
% Normalize to make it a valid probability distribution
stationary_distribution = stationary_distribution / sum(stationary_distribution);
return
end
end
error('No stationary distribution found')
end