Graphviz (Graph Visualization Software) 是 AT&T 用來自動產生圖形的程式,它包含數個執行檔,其中較常用的為 dot 這支程式,dot 可以處理有向圖 (Directed Graph)跟無向圖 (Undirected Graph)。Graphviz 有趣的地方在於整個圖形的排版是由程式自動決定的,只要輸入符合語法的程式碼,經過 dot 處理後即能產生對應的圖檔。以下是今天試用的幾個結果以及其程式碼。

程式碼用一般文書編輯器處理完後,存成 abc.dot 檔,然後輸入下列指令讓它產生 PNG 格式的圖檔。
> dot -Tpng -o abc.png abc.dot
或是在 vi (vim) 的命令列模式輸入
:! dot -Tpng -o abc.png abc.dot

HMM
digraph HMM{
  node [fixedsize=true, width=0.6];
  "s(t-1)" [shape=rect];
  "s(t)" [shape=rect];
  "s(t+1)" [shape=rect];

  "v(t-1)" [shape=circle, style=filled, fillcolor=grey];
  "v(t)" [shape=circle, style=filled, fillcolor=grey];
  "v(t+1)" [shape=circle, style=filled, fillcolor=grey];
 
  "s(t-1)" -> "s(t)" -> "s(t+1)";

  "s(t-1)" -> "v(t-1)";
  "s(t)"->"v(t)";
  "s(t+1)"->"v(t+1)";

  { rank=same; "s(t-1)" "s(t)" "s(t+1)" }
  { rank=same; "v(t-1)" "v(t)" "v(t+1)" }
}



CRF

graph CRF{
  node [fixedsize=true, width=0.6];
  "s(t-1)" [shape=rect];
  "s(t)" [shape=rect];
  "s(t+1)" [shape=rect];

  "v(t-1)" [shape=circle, style=filled, fillcolor=grey];
  "v(t)" [shape=circle, style=filled, fillcolor=grey];
  "v(t+1)" [shape=circle, style=filled, fillcolor=grey];
 
  "s(t-1)"--"s(t)"--"s(t+1)";

  "s(t-1)" -- "v(t-1)";
  "s(t)"--"v(t)";
  "s(t+1)"--"v(t+1)";

  { rank=same; "s(t-1)" "s(t)" "s(t+1)" }
  { rank=same; "v(t-1)" "v(t)" "v(t+1)" }
}



SLDS

digraph ALDS{
  node [fixedsize=true, width=0.6];
  "s(t-1)" [shape=rect];
  "s(t)" [shape=rect];
  "s(t+1)" [shape=rect];
 
  "h(t-1)" [shape=circle];
  "h(t)" [shape=circle];
  "h(t+1)" [shape=circle];

  "v(t-1)" [shape=circle, style=filled, fillcolor=grey];
  "v(t)" [shape=circle, style=filled, fillcolor=grey];
  "v(t+1)" [shape=circle, style=filled, fillcolor=grey];
 
  "s(t-1)" -> "s(t)" -> "s(t+1)";
  "h(t-1)" -> "h(t)" -> "h(t+1)";

  "s(t-1)" -> "h(t-1)" -> "v(t-1)";
  "s(t)"-> "h(t)" -> "v(t)";
  "s(t+1)"-> "h(t+1)" -> "v(t+1)";

  { rank=same; "s(t-1)" "s(t)" "s(t+1)" }
  { rank=same; "v(t-1)" "v(t)" "v(t+1)" }
  { rank=same; "h(t-1)" "h(t)" "h(t+1)" }
}



以上例子的輸出結果尚令人滿意,但有些圖形是失敗的,因為我只會基本功能,所以不知該如何調整失敗的圖形,例如下圖 v(t-1) 到 v(t+1) 的箭頭應該要畫在下方,雖然結果不影響變數之間的正確性,但視覺美感也是該納入考量的。除了這種不預期的圖形輸出之外,我到現在還是不清楚該如何輸入上標及下標。

banco 發表在 痞客邦 PIXNET 留言(0) 人氣()