annotate toolboxes/FullBNT-1.0.7/GraphViz/draw_dbn.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function [x, y, h] = draw_dbn(adj, inter, flip_intra, K, labels, node_t, x, y)
wolffd@0 2 % DRAW_LAYOUT_DBN Draws a layout for a Dynamical Belief Network
wolffd@0 3 %
wolffd@0 4 % [<X1, Y1, X2, Y2>] = DRAW_LAYOUT_DBN(INTRA, INTER, <FLIP_FLAG, K, LABELS, ISBOX, X1, Y1>)
wolffd@0 5 %
wolffd@0 6 % Inputs :
wolffd@0 7 % INTRA, INTER : Adjacency matrices
wolffd@0 8 % FLIP_FLAG : Transposes the DAG layout obtained from INTRA connections
wolffd@0 9 % If X1, Y1 are specified, FLIP_FLAG has no effect.
wolffd@0 10 % K : Unfold K times <Default = 2>
wolffd@0 11 % LABELS - if -1, we use 1:N*K
wolffd@0 12 % Rest : See DRAW_LAYOUT
wolffd@0 13 %
wolffd@0 14 % Outputs :
wolffd@0 15 % Xi, Yi : Coordinates of nodes (for i'th timeslice) on the unit square
wolffd@0 16 % H : Object Handles
wolffd@0 17 %
wolffd@0 18 % Usage Example : draw_layout_dbn(intra, inter, 1);
wolffd@0 19 % draw_layout_dbn(intra, inter);
wolffd@0 20 %
wolffd@0 21 % Note :
wolffd@0 22 % See also DRAW_GRAPH
wolffd@0 23
wolffd@0 24 % Uses : DRAW_GRAPH
wolffd@0 25
wolffd@0 26 % Change History :
wolffd@0 27 % Date Time Prog Note
wolffd@0 28 % 17-Apr-2000 1:02 PM ATC Created under MATLAB 5.3.1.29215a (R11.1)
wolffd@0 29
wolffd@0 30 % ATC = Ali Taylan Cemgil,
wolffd@0 31 % SNN - University of Nijmegen, Department of Medical Physics and Biophysics
wolffd@0 32 % e-mail : cemgil@mbfys.kun.nl
wolffd@0 33
wolffd@0 34 N = size(adj,1);
wolffd@0 35 if nargin<3,
wolffd@0 36 flip_intra = 0;
wolffd@0 37 end;
wolffd@0 38
wolffd@0 39 if nargin<4,
wolffd@0 40 K = 2;
wolffd@0 41 end;
wolffd@0 42
wolffd@0 43 if K<2 | K>7, error('2<=K<=7 must hold..'); end;
wolffd@0 44
wolffd@0 45
wolffd@0 46 if nargin<5
wolffd@0 47 % labels = cellstr(char(zeros(N,1)+double('+')));
wolffd@0 48 % labels = cellstr(int2str((1:N)'));
wolffd@0 49 labels = cellstr(char((0:N-1)'+double('a')));
wolffd@0 50 end;
wolffd@0 51
wolffd@0 52 if nargin<6,
wolffd@0 53 node_t = zeros(N,1);
wolffd@0 54 % node_t = rand(N,1) > 0.5;
wolffd@0 55 end;
wolffd@0 56
wolffd@0 57 if nargin<7,
wolffd@0 58 [x1 y1] = make_layout(adj);
wolffd@0 59 if flip_intra, tmp = x1; x1 = y1; y1 = tmp; end;
wolffd@0 60 end;
wolffd@0 61
wolffd@0 62 mid = round(K/2);
wolffd@0 63
wolffd@0 64
wolffd@0 65 xi = x1(:)-1;
wolffd@0 66 x = [];
wolffd@0 67 y = repmat(y1(:), [K 1]);
wolffd@0 68 node_t2 = repmat(node_t(:), [K 1]);
wolffd@0 69
wolffd@0 70 if isa(labels,'double') & labels==-1 % KPM
wolffd@0 71 lb = num2strcell(1:N*K);
wolffd@0 72 else
wolffd@0 73 lb = {};
wolffd@0 74 for i=1:K,
wolffd@0 75 labels1 = labels(:);
wolffd@0 76 if i==mid, str = ''; else str = sprintf('%+d',i-mid); end;
wolffd@0 77 for i=1:N,
wolffd@0 78 labels1{i} = [labels1{i} '(t' str ')'];
wolffd@0 79 end;
wolffd@0 80 lb = [lb; labels1(:)];
wolffd@0 81 end;
wolffd@0 82 end
wolffd@0 83
wolffd@0 84 dag = zeros(N*K);
wolffd@0 85
wolffd@0 86 for i=1:K,
wolffd@0 87 xi = xi+1;
wolffd@0 88 x = [x; xi];
wolffd@0 89
wolffd@0 90 idx = ((i-1)*N+1):i*N;
wolffd@0 91 dag(idx,idx) = adj;
wolffd@0 92 if i<K,
wolffd@0 93 dag(idx,idx+N) = inter;
wolffd@0 94 end;
wolffd@0 95 end;
wolffd@0 96
wolffd@0 97 [x, y, h] = draw_graph(dag, lb, node_t2, x/K, y);
wolffd@0 98
wolffd@0 99