how to automatically calculate probalities of a long binary sequence ?

조회 수: 7 (최근 30일)
Lina Hadjar Ferhat
Lina Hadjar Ferhat 2018년 4월 24일
답변: TARUN 2025년 6월 10일
hello ,
i have a matlab data (2678400 values (seconds)) , converted to a binary sequence of 744 values of 0s and 1s . i need to calculate 4 probabilities (markov chain 4 states ) Pr(11),Pr(10),Pr(01),Pr(00) is there a code that can do that ?
thanks

답변 (1개)

TARUN
TARUN 2025년 6월 10일
If you have a binary sequence (e.g., converted from a large dataset like 2,678,400 values down to 744 binary values), and you'd like to compute Markov chain transition probabilities—specifically Pr(00), Pr(01), Pr(10), and Pr(11)—you can use the following MATLAB script:
% Initialization
count_00 = 0;
count_01 = 0;
count_10 = 0;
count_11 = 0;
% for loop to count the transitions
for i = 1:length(binary_seq) - 1
current = binary_seq(i);
next = binary_seq(i + 1);
if current == 0 && next == 0
count_00 = count_00 + 1;
elseif current == 0 && next == 1
count_01 = count_01 + 1;
elseif current == 1 && next == 0
count_10 = count_10 + 1;
elseif current == 1 && next == 1
count_11 = count_11 + 1;
end
end
% count the total transitions
total_transitions = count_00 + count_01 + count_10 + count_11;
% Compute probabilities
Pr_00 = count_00 / total_transitions;
Pr_01 = count_01 / total_transitions;
Pr_10 = count_10 / total_transitions;
Pr_11 = count_11 / total_transitions;
% display the results
disp(['Pr(00) = ' num2str(Pr_00)]);
disp(['Pr(01) = ' num2str(Pr_01)]);
disp(['Pr(10) = ' num2str(Pr_10)]);
disp(['Pr(11) = ' num2str(Pr_11)]);
The above script helps you compute the first-order Markov transition probabilities by analysing every pair of consecutive bits in your binary sequence.

카테고리

Help CenterFile Exchange에서 Markov Chain Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by