1
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) ????-2008 - INRIA
4//
5// Copyright (C) 2012 - 2016 - Scilab Enterprises
6//
7// This file is hereby licensed under the terms of the GNU GPL v2.0,
8// pursuant to article 5.3.4 of the CeCILL v.2.1.
9// This file was originally licensed under the terms of the CeCILL v2.1,
10// and continues to be available under such terms.
11// For more information, see the COPYING file which you should have received
12// along with this program.
13
14function [perm,rec,tr,indsRec,indsT]=classmarkov(M)
15    //returns a permutation vector perm such that
16    //M(perm,perm) = [M11 0 0 0 0   0]
17    //               [0 M22 0 0     0]
18    //               [0 0 M33       0]
19    //               [      ...      ]
20    //               [0 0       Mrr 0]
21    //               [* *        *  Q]
22    //Each Mii is a Markov matrix of dimension rec(i)  i=1,..,r
23    //Q is sub-Markov matrix of dimension tr
24    //States 1 to sum(rec) are recurrent and states from r+1 to n
25    //are transient.
26    //perm=[indsRec,indsT] where indsRec is a  vector of size sum(rec)
27    //and indsT is a vector of size indsT.
28    if type(M)==1
29        Mb=sparse(M<>0);
30    else Mb=M<>0;
31    end
32    g=mat_2_graph(bool2s(Mb),1,"node-node");
33    [nc,ncomp]=strong_connex(g);
34    indsRec=[];indsT=[];rec=[];tr=0;
35    for i=1:nc
36        inds=find(ncomp==i);
37        nb=size(inds,"*");
38        M1=M(inds,:); M1(:,inds)=[];
39        if sum(M1)==0 then
40            indsRec=[indsRec,inds];
41            rec=[rec,nb];
42        else
43            indsT=[indsT,inds];
44            tr=tr+nb;
45        end
46    end
47    perm=[indsRec,indsT];
48endfunction
49
50