Borrar filtros
Borrar filtros

How to programme to calculate transition probability matrix?

2 visualizaciones (últimos 30 días)
Ramesh Kasotiya
Ramesh Kasotiya el 7 de Jul. de 2020
Respondida: emami.m el 23 de En. de 2021
Suppose I have a sequence of states like 1,3,3,1,2,1,4,2,3,1,4,2,4,4,4,3,1,2,5,1. Transition probability matrix calculated by following equation probability=(number of pairs x(t) followed by x(t+1))/(number of pairs x(t) followed by any state). transition probability matrix calculated by manually by me as follows
1 3 2 4 5
1 0 1/5 2/5 2/5 0
3 3/4 1/4 0 0 0
2 1/4 1/4 0 1/4 1/4
4 0 1/5 2/5 2/5 0
5 1 0 0 0 0
The following code (by James Tursa) gives the answer
%%%%%
m = max(x);
n = numel(x);
y = zeros(m,1);
p = zeros(m,m);
for k=1:n-1
y(x(k)) = y(x(k)) + 1;
p(x(k),x(k+1)) = p(x(k),x(k+1)) + 1;
end
p = bsxfun(@rdivide,p,y); p(isnan(p)) = 0;
%%%%
How to programme for transition probability matrix if x have 2D vectors or 3D vectors or N dimensional vectors. For example take 2D vectors matrix
x=[0 0;
1 0;
2 1;
2 1;
2 1;
1 1;
1 1;
1 1;
1 1;
1 0;
2 1;
2 1;
2 1;
3 2;
2 2;
2 2;
2 2;
3 2;
3 2;
4 2;
4 2;
4 2;
3 2;
3 2;
3 2]

Respuestas (1)

emami.m
emami.m el 23 de En. de 2021
I guess you should define unique combinations as states so you can map each pair of x to a state, then adopt your code to the new set of states.
[Categories,freq,new_seq] = unique(string(num2str(x)));
Now you can use new_seq as x in your code.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by