Home > data-analysis > stats > cstream > cstream_conditional_p.m

cstream_conditional_p

PURPOSE ^

cstream_conditional_p Calculate the contional probability of cstream.

SYNOPSIS ^

function cp = cstream_conditional_p(cstream_data)

DESCRIPTION ^

 cstream_conditional_p  Calculate the contional probability of cstream.

 cp = cstream_conditional_p(cstream_data);

 cstream_data: input cstream
 cp : conditional probablity matrix, cp(X1,X2) is P(X2|X1), where X1X2 is bigram in
      cstream and X1 appears right before X2.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function cp = cstream_conditional_p(cstream_data)
0002 % cstream_conditional_p  Calculate the contional probability of cstream.
0003 %
0004 % cp = cstream_conditional_p(cstream_data);
0005 %
0006 % cstream_data: input cstream
0007 % cp : conditional probablity matrix, cp(X1,X2) is P(X2|X1), where X1X2 is bigram in
0008 %      cstream and X1 appears right before X2.
0009 %
0010 
0011 data = cstream_data(:,2);
0012 sym_num = max(data);
0013 
0014 cp = zeros(sym_num, sym_num);
0015 %
0016 for i = 2:length(data)
0017     cp(data(i-1), data(i)) = cp(data(i-1), data(i)) + 1;
0018 end
0019 
0020 sums = sum(cp, 2);
0021 
0022 for j = 1:sym_num
0023      cp(j,:) = cp(j,:) / sums(j);
0024 end

Generated on Tue 23-May-2017 20:00:55 by m2html © 2005