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

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