Azzera filtri
Azzera filtri

help needed to make transition probability matrix

2 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

John D'Errico
John D'Errico il 27 Lug 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 Commenti
Mahesh
Mahesh il 27 Lug 2015
Well thanks for the clue. But I am having problem with calculating matrix T. For that I have data
A = [2 2 2 2 2 2 7 7 7 7 7 7 7 7 7 4 4 4 4 4 4 10 10 10 10 1 1 1 1 1 6 6 5 5 5 9 9 9 9 9 9 9 9 3 3 3 3 9 3 3 8 8 8 8 8]
I hope it works for you to make me clear
Mahesh
Mahesh il 27 Lug 2015
Moreover I got the matrix with all elements of last row is zeros. I tested with other set same thing happens.
jumpprob = [
12 18 21 22 31 36 45 49
7 13 16 17 25 30 39 43
3 9 12 13 21 25 33 37
3 4 7 8 16 20 28 31
3 4 5 6 14 18 25 28
3 4 4 4 12 16 23 26
3 3 3 3 3 7 14 17
3 3 3 3 3 3 10 13
1 1 1 1 1 1 1 4
0 0 0 0 0 0 0 0]
I hope you may get the mistake thanks

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by