help needed to make transition probability matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Mahesh
am 27 Jul. 2015
Kommentiert: Mahesh
am 27 Jul. 2015
Dear all, I am brainstorming how to make transition probability matrix and had a code below. It does not work. It could be great to check my code and have a idea so that sum of all values in the matrix shall be one. My mind blocked after thinking a lot.
A = idxMA;
nmax = max(A);
nseries = numel(A);
states = zeros(nseries, nmax);
for i = 1:nmax
states(:,i) = A==i;
end
jumpprob = zeros(nmax);
jmps = 1:nmax;
for i = 1:nmax
X = jmps(i);
for j = 1:njumps
Y = jmps(j);
P = jumps(A, X, Y);
jumpprob(i,j) = P/nseries;
end
end
function [ P ] = jumps(data, X, Y )
%UNTITLED5 Summary of this function goes here
% Detailed explanation goes here
ndata = length(data);
nstates = 0;
for i = 1:ndata-1
if data(i) > X && data(i+1) <= Y
nstates = nstates + 1;
end
end
P = nstates;
end
0 Kommentare
Akzeptierte Antwort
John D'Errico
am 27 Jul. 2015
Um, no. A transition matrix does NOT have the sum of ALL values in the matrix as 1.
It must have the sum of every ROW of the matrix 1. There is a big difference. So as written below, T would be a valid transition matrix.
n = 6;
T = rand(n,n);
T = bsxfun(@times,T,1./sum(T,2))
T =
0.19273 0.06588 0.22642 0.1874 0.16056 0.16702
0.24566 0.14832 0.13164 0.26023 0.20551 0.0086335
0.035665 0.26892 0.22476 0.18417 0.20871 0.077775
0.36619 0.38684 0.056885 0.014318 0.15725 0.018511
0.22476 0.056021 0.14991 0.30181 0.23298 0.034524
0.02493 0.24807 0.23405 0.23872 0.043754 0.21047
The sum of the probabilities to move from any given state to one of the other states must be 1. So the sum of each row is 1, as I said it must be.
sum(T,2)
ans =
1
1
1
1
1
1
2 Kommentare
Weitere Antworten (0)
Siehe auch
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!