solving transition probabilities

4 ビュー (過去 30 日間)
Sayanta
Sayanta 2012 年 5 月 30 日
Dear All,
I have written a program for computing transition probabilities.
the transitional probability from s1 ->s2
1 compute total no number of successive events going from s1 -> s2 divided by the total number of s1 events. which is describe in following equation
Transitional probability s1 -> s2 = Pr[Xt+1 = s2|Xt = s1].
But I have error in calculating . Couldn't find where is error in my code
error is here :
Error in ==> statv2 at 4
if (x(1) <= 5)
??? Output argument "state_current" (and maybe others) not assigned during call to "C:\Markov
Chain Programs\Matlab CPU program - Copy (2)\statv2.m>statv2".
Error in ==> modelMarkov_v2 at 20
[previousState currentState] = statv2([data(i-1,1) data(i,1)]);
Here is code for calculation transition probabilities
reading = [77;66.9016000000000;67.0833000000000;66.1000000000000;66.3115000000000;66.3934000000000;86.8525000000000;78.7288000000000;66.4918000000000;66.7833000000000;67.3667000000000;66.7541000000000;68.2034000000000;67.5833000000000;65.7869000000000;66.4068000000000;85.3443000000000;90.9667000000000;66.3667000000000;67.9500000000000;69.7833000000000;67.6441000000000;66.9667000000000;66.1167000000000;65.6721000000000;67.4576000000000;69.1167000000000;96.6333000000000;66.4918000000000;66.3443000000000;66.9830000000000;78.5410000000000;67.3729000000000;66.5574000000000;66.5667000000000;66.8644000000000;68.3934000000000;110.610000000000;66.8500000000000;66.9167000000000;70.9508000000000;68.1695000000000;67.2667000000000;];
data = reading ;
transFreq = zeros(22,22);
transCount = zeros(22,22);
% calculating transion count in data
i = 1;
for i = 1:length(data)
if (i < 2)
[previousState currentState] = statv2([data(i,1) data(i,1)]);
transCount(previousState, currentState) = transCount(previousState,currentState) + 1;
end
if (i >= 2)
data(i-1,1);
data(i,1);
[previousState currentState] = statv2([data(i-1,1) data(i,1)]);
transCount(previousState, currentState) = transCount(previousState, currentState) + 1;
end
end
% Calculate Transistion Frequencies
for j = 1:22
transFreq(j,:) = transCount(j,:)/ sum(transCount(j,:));
end
I have a function : statv2 to calculate previous state and current state
function [state_prev,state_current] = statv2(x)
% for previous state
if (x(1) <= 5)
state_prev = 1;
end
if (x(1) > 5 && x(1) <= 10)
state_prev = 2;
end
if (x(1) > 10 && x(1) <= 15)
state_prev = 3;
end
if (x(1) > 15 && x(1) <= 20)
state_prev = 4;
end
if (x(1) > 20 && x(1) <= 25)
state_prev = 5;
end
if (x(1) > 25 && x(1) <= 30)
state_prev = 6;
end
if (x(1) > 30 && x(1) <= 35)
state_prev = 7;
end
if (x(1) > 35 && x(1) <= 40)
state_prev = 8;
end
if (x(1) > 40 && x(1) <= 45)
state_prev = 9;
end
if (x(1) > 45 && x(1) <= 50)
state_prev = 10;
end
if (x(1) > 50 && x(1) <= 55)
state_prev = 11;
end
if (x(1) > 55 && x(1) <= 60)
state_prev = 12;
end
if (x(1) > 60 && x(1) <= 65)
state_prev = 13;
end
if (x(1) > 65 && x(1) <= 70)
state_prev = 14;
end
if (x(1) > 70 && x(1) <= 75)
state_prev = 15;
end
if (x(1) > 75 && x(1) <= 80)
state_prev = 16;
end
if (x(1) > 80 && x(1) <= 85)
state_prev = 17;
end
if (x(1) > 85 && x(1) <= 90)
state_prev = 18;
end
if (x(1) > 90 && x(1) <= 95)
state_prev = 19;
end
if (x(1) > 95 && x(1) <= 100)
state_prev = 20;
end
if (x(1) > 100 && x(1) <= 105)
state_prev = 21;
end
if (x(1) > 105 && x(1) <= 110)
state_prev = 22;
end
% for current state
if (x(2) <= 5)
state_current = 1;
end
if (x(2) > 5 && x(2) <= 10)
state_current = 2;
end
if (x(2) >10 && x(2) <= 15)
state_current = 3;
end
if (x(2) > 15 && x(2) <= 20)
state_current = 4;
end
if (x(2) > 20 && x(2) <= 25)
state_current = 5;
end
if (x(2) > 25 && x(2) <= 30)
state_current = 6;
end
if (x(2) > 30 && x(2) <= 35)
state_current = 7;
end
if (x(2) > 35 && x(2) <= 40)
state_current = 8;
end
if (x(2) > 40 && x(2) <= 45)
state_current = 9;
end
if (x(2) > 45 && x(2) <= 50)
state_current = 10;
end
if (x(2) > 50 && x(2) <= 55)
state_current = 11;
end
if (x(2) > 55 && x(2) <= 60)
state_current = 12;
end
if (x(2) > 60 && x(2) <= 65)
state_current = 13;
end
if (x(2) > 65 && x(2) <= 70)
state_current = 14;
end
if (x(2) > 70 && x(2) <= 75)
state_current = 15;
end
if (x(2) > 75 && x(2) <= 80)
state_current = 16;
end
if (x(2) > 80 && x(2) <= 85)
state_current = 17;
end
if (x(2) > 85 && x(2) <= 90)
state_current = 18;
end
if (x(2) > 90 && x(2) <= 95)
state_current = 19;
end
if (x(2) > 95 && x(2) <= 100)
state_current = 20;
end
if (x(2) > 100 && x(2) <= 105)
state_current = 21;
end
if (x(2) > 105 && x(2) <= 110)
state_current = 22;
end
Could please help me how can I resolve the error
Many Thanks in advance

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 30 日
You have a data point 110.610000000000 which is beyond the limits that you test for, 110, so no state gets assigned in that situation.
Have you considered the health benefits of using histc() ?

カテゴリ

Help Center および File ExchangeSpecialized Power Systems についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by