def kullback(F):
F1 = F == <NUM_LIT:0><EOL>F1 = F + F1<EOL>FLF = F * np.log(F1)<EOL>T1 = <NUM_LIT:2> * FLF.sum()<EOL>FdJK = F.sum(axis=<NUM_LIT:0>)<EOL>FdJK1 = FdJK + (FdJK == <NUM_LIT:0>)<EOL>FdJKLFdJK = FdJK * np.log(FdJK1)<EOL>T2 = <NUM_LIT:2> * FdJKLFdJK.sum()<EOL>FdJd = F.sum(axis=<NUM_LIT:0>).sum(axis=<NUM_LIT:1>)<EOL>FdJd1 = FdJd + (FdJd == <NUM_LIT:0>)<EOL>T3 = <NUM_LIT:2> * (FdJd * np.log(FdJd1)).sum()<EOL>FIJd = F[:, :].sum(axis=<NUM_LIT:1>)<EOL>FIJd1 = FIJd + (FIJd == <NUM_LIT:0>)<EOL>T4 = <NUM_LIT:2> * (FIJd * np.log(FIJd1)).sum()<EOL>T6 = F.sum()<EOL>T6 = <NUM_LIT:2> * T6 * np.log(T6)<EOL>s, r, r1 = F.shape<EOL>chom = T1 - T4 - T2 + T3<EOL>cdof = r * (s - <NUM_LIT:1>) * (r - <NUM_LIT:1>)<EOL>results = {}<EOL>results['<STR_LIT>'] = chom<EOL>results['<STR_LIT>'] = cdof<EOL>results['<STR_LIT>'] = <NUM_LIT:1> - stats.chi2.cdf(chom, cdof)<EOL>return results<EOL>
Kullback information based test of Markov Homogeneity.

Parameters
----------
F : array
    (s, r, r), values are transitions (not probabilities) for
    s strata, r initial states, r terminal states.

Returns
-------
Results : dictionary
          (key - value)

          Conditional homogeneity - (float) test statistic for homogeneity
          of transition probabilities across strata.

          Conditional homogeneity pvalue - (float) p-value for test
          statistic.

          Conditional homogeneity dof - (int) degrees of freedom =
          r(s-1)(r-1).

Notes
-----
Based on :cite:`Kullback1962`.
Example below is taken from Table 9.2 .

Examples
--------
>>> import numpy as np
>>> from giddy.markov import kullback
>>> s1 = np.array([
...         [ 22, 11, 24,  2,  2,  7],
...         [ 5, 23, 15,  3, 42,  6],
...         [ 4, 21, 190, 25, 20, 34],
...         [0, 2, 14, 56, 14, 28],
...         [32, 15, 20, 10, 56, 14],
...         [5, 22, 31, 18, 13, 134]
...     ])
>>> s2 = np.array([
...     [3, 6, 9, 3, 0, 8],
...     [1, 9, 3, 12, 27, 5],
...     [2, 9, 208, 32, 5, 18],
...     [0, 14, 32, 108, 40, 40],
...     [22, 14, 9, 26, 224, 14],
...     [1, 5, 13, 53, 13, 116]
...     ])
>>>
>>> F = np.array([s1, s2])
>>> res = kullback(F)
>>> "%8.3f"%res['Conditional homogeneity']
' 160.961'
>>> "%d"%res['Conditional homogeneity dof']
'30'
>>> "%3.1f"%res['Conditional homogeneity pvalue']
'0.0'