1% ImageFromDPH(alpha, A, outFileName, prec)
3% Depicts the given discrete phase-type distribution,
4% and either displays it or saves it to file.
8% alpha : matrix, shape (1,M)
9% The initial probability vector of the discrete phase-
11% A : matrix, shape (M,M)
12% The transition probability matrix of the discrete phase-
14% outFileName : string, optional
15% If it
is not provided, or equals to
'display', the
16% image
is displayed on the screen, otherwise it
is
17% written to the file. The file format
is deduced
19% prec : double, optional
20% Transition probabilities less then prec are
21% considered to be zero and are left out from the
22% image. The
default value
is 1e-13.
26% The
'graphviz' software must be installed and available
27% in the path to use
this feature.
29function img = ImageFromPH(alpha,A,outFileName,prec)
31 if ~exist(
'prec',
'var')
35 if ~exist('outFileName','var') || strcmp(outFileName,'display')
36 outputFile = '.result.png';
39 outputFile = outFileName;
43 inputFile = '.temp.dot';
45 fid = fopen(inputFile,'w');
46 fprintf(fid, 'digraph G {\n
');
47 fprintf(fid, '\trankdir=LR;\n
');
48 fprintf(fid, '\tnode [shape=circle,width=0.3,height=0.3,label=
""];\n
');
52 fprintf(fid, '\tn%d [xlabel=<<i>%g</i>>];\n
', i, alpha(i));
55 % transitions to a non-absorbing state
59 fprintf(fid, '\tn%d -> n%d [label=
"%g"];\n
', i, j, A(i,j));
64 % transitions to the absorbing state
65 fprintf(fid, ['\tab [style=filled];\n
']);
69 fprintf(fid, '\tn%d -> ab [label=
"%g"];\n
', i, a(i));
75 [~,~,ext] = fileparts(outputFile);
76 system(['dot -T
', ext(2:end), ' ', inputFile, ' -o
', outputFile]);
81 RGB = imread(outputFile);
82 figure('toolbar
','none
','units
','pixel
','position
',[0,0,size(RGB,2)+100,size(RGB,1)+100]);