1% ImageFromPH(alpha, A, outFileName, prec)
3% Depicts the given 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 phase-type
11% A : matrix, shape (M,M)
12% The transient generator matrix of the phase-type
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 rates less then prec are considered to
21% be zero and are left out from the image. The
22%
default value
is 1e-13.
26% The
'graphviz' software must be installed and available
27% in the path to use
this feature.
29function ImageFromPH(alpha,A,outFileName,prec)
31 if ~exist(
'prec',
'var')
35 global BuToolsCheckInput;
36 if isempty(BuToolsCheckInput)
37 BuToolsCheckInput = true;
40 if BuToolsCheckInput && ~CheckPHRepresentation(alpha,A)
41 error('ImageFromPH: input isn''t a valid PH representation!');
44 if ~exist('outFileName','var') || strcmp(outFileName,'display')
45 outputFile = '.result.png';
48 outputFile = outFileName;
52 inputFile = '.temp.dot';
54 fid = fopen(inputFile,'w');
55 fprintf(fid, 'digraph G {\n
');
56 fprintf(fid, '\trankdir=LR;\n
');
57 fprintf(fid, '\tnode [shape=circle,width=0.3,height=0.3,label=
""];\n
');
61 fprintf(fid, '\tn%d [xlabel=<<i>%g</i>>];\n
', i, alpha(i));
64 % transitions to a non-absorbing state
67 if i~=j && abs(A(i,j))>prec
68 fprintf(fid, '\tn%d -> n%d [label=
"%g"];\n
', i, j, A(i,j));
73 % transitions to the absorbing state
74 fprintf(fid, ['\tab [style=filled];\n
']);
78 fprintf(fid, '\tn%d -> ab [label=
"%g"];\n
', i, a(i));
84 [~,~,ext] = fileparts(outputFile);
85 system(['dot -T
', ext(2:end), ' ', inputFile, ' -o
', outputFile]);
90 RGB = imread(outputFile);
91 figure('toolbar
','none
','units
','pixel
','position
',[0,0,size(RGB,2)+100,size(RGB,1)+100]);