def var_fmpt(P):
P = np.matrix(P)<EOL>A = P ** <NUM_LIT:1000><EOL>n, k = A.shape<EOL>I = np.identity(k)<EOL>Z = la.inv(I - P + A)<EOL>E = np.ones_like(Z)<EOL>D = np.diag(<NUM_LIT:1.> / np.diag(A))<EOL>Zdg = np.diag(np.diag(Z))<EOL>M = (I - Z + E * Zdg) * D<EOL>ZM = Z * M<EOL>ZMdg = np.diag(np.diag(ZM))<EOL>W = M * (<NUM_LIT:2> * Zdg * D - I) + <NUM_LIT:2> * (ZM - E * ZMdg)<EOL>return np.array(W - np.multiply(M, M))<EOL>
Variances of first mean passage times for an ergodic transition
probability matrix.

Parameters
----------
P      : array
         (k, k), an ergodic Markov transition probability matrix.

Returns
-------
       : array
         (k, k), elements are the variances for the number of intervals
         required for a chain starting in state i to first enter state j.

Examples
--------
>>> import numpy as np
>>> from giddy.ergodic import var_fmpt
>>> p=np.array([[.5, .25, .25],[.5,0,.5],[.25,.25,.5]])
>>> vfm=var_fmpt(p)
>>> vfm
array([[ 5.58333333, 12.        ,  6.88888889],
       [ 6.22222222, 12.        ,  6.22222222],
       [ 6.88888889, 12.        ,  5.58333333]])

Notes
-----
Uses formulation (and examples on p. 83) in :cite:`Kemeny1967`.