dbn_to_dot.m

来自「麻省理工学院的人工智能工具箱,很珍贵,希望对大家有用!」· M 代码 · 共 93 行

M
93
字号
function dbn_to_dot(intra, inter, varargin)% DBN_TO_DOT Make a file representing the DBN in dotty format.% dbn_to_dot(intra, inter, ...)%% Optional arguments should be passed as name/value pairs [default]%% 'filename' - if omitted, we write to 'tmp.dot', convert this to 'tmp.ps',%              and then call ghostview automatically % T           - number of slices to create [2]% 'arc_label' - arc_label{i,j} is a string attached to the i->j arc. [""]% 'node_label' - node_label{i} is a string attached to node i. ["i(t)"]% 'width'      - width in inches [10]% 'height'     - height in inches [10]%% For details on dotty, See http://www.research.att.com/sw/tools/graphviz% set default argsfilename = [];node_label = [];arc_label = [];width = 10;height = 10;T = 2;% get optional argsargs = varargin;for i=1:2:length(args)  switch args{i}   case 'filename', filename = args{i+1};   case 'node_label', node_label = args{i+1};   case 'arc_label', arc_label = args{i+1};   case 'width', width = args{i+1};   case 'height', height = args{i+1};   case 'T', T = args{i+1};  endendss = size(intra, 1);G = unroll_dbn_topology(intra, inter, T);if isempty(filename)  make_file(G, T, ss, 'tmp.dot', node_label, arc_label, width, height);  !dot -Tps tmp.dot -o tmp.ps  !ghostview tmp.ps &else  make_file(G, T, ss. filename, node_label, arc_label, width, height);end%%%%%%function make_file(G, T, ss, filename, node_label, arc_label, width, height)n = length(G);fid = fopen(filename, 'w');fprintf(fid, 'digraph G {\n');fprintf(fid, 'center = 1;\n');fprintf(fid, 'rankdir = LR;\n'); % left to rightfprintf(fid, 'size=\"%d,%d\";\n', width, height);if isempty(node_label)  node_label = cell(1,ss*T);  for t=1:T    for j=1:ss      i = j+(t-1)*ss;      node_label{i} = sprintf('%d(%d)', j, t);    end  endendfor i=1:n  fprintf(fid, '%d [ label = "%s" ];\n', i, node_label{i});endfor t=1:T  fprintf(fid, '{rank = same; ');  for i=1:ss    fprintf(fid, '%d; ', i+(t-1)*ss);  end  fprintf(fid, '};\n');endfor i=1:n  cs = children(G,i);  for j=1:length(cs)    c = cs(j);    if isempty(arc_label)      fprintf(fid, '%d -> %d;\n', i, c);    else      fprintf(fid, '%d -> %d [label="%s"];\n', i, c, arc_label{i,c});    end  endendfprintf(fid, '\n}');fclose(fid);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?