Debian Codegraph @

texmf-dist/tex/latex/tikz-bayesnet/tikzlibrarybayesnet.code.tex

raw
1 % tikzlibrary.code.tex
2 %
3 % Copyright 2010-2011 by Laura Dietz
4 % Copyright 2012 by Jaakko Luttinen
5 %
6 % This file may be distributed and/or modified
7 %
8 % 1. under the LaTeX Project Public License and/or
9 % 2. under the GNU General Public License.
10 %
11 % See the files LICENSE_LPPL and LICENSE_GPL for more details.
12
13 % Load other libraries
14 \usetikzlibrary{shapes}
15 \usetikzlibrary{fit}
16 \usetikzlibrary{chains}
17 \usetikzlibrary{arrows}
18
19 % Latent node
20 \tikzstyle{latent} = [circle,fill=white,draw=black,inner sep=1pt,
21 minimum size=20pt, font=\fontsize{10}{10}\selectfont, node distance=1]
22 % Observed node
23 \tikzstyle{obs} = [latent,fill=gray!25]
24 % Constant node
25 \tikzstyle{const} = [rectangle, inner sep=0pt, node distance=1]
26 % Factor node
27 \tikzstyle{factor} = [rectangle, fill=black,minimum size=5pt, inner
28 sep=0pt, node distance=0.4]
29 % Deterministic node
30 \tikzstyle{det} = [latent, diamond]
31
32 % Plate node
33 \tikzstyle{plate} = [draw, rectangle, rounded corners, fit=#1]
34 % Invisible wrapper node
35 \tikzstyle{wrap} = [inner sep=0pt, fit=#1]
36 % Gate
37 \tikzstyle{gate} = [draw, rectangle, dashed, fit=#1]
38
39 % Caption node
40 \tikzstyle{caption} = [font=\footnotesize, node distance=0] %
41 \tikzstyle{plate caption} = [caption, node distance=0, inner sep=0pt,
42 below left=5pt and 0pt of #1.south east] %
43 \tikzstyle{factor caption} = [caption] %
44 \tikzstyle{every label} += [caption] %
45
46 \tikzset{>={triangle 45}}
47
48 %\pgfdeclarelayer{b}
49 %\pgfdeclarelayer{f}
50 %\pgfsetlayers{b,main,f}
51
52 % \factoredge [options] {inputs} {factors} {outputs}
53 \newcommand{\factoredge}[4][]{ %
54 % Connect all nodes #2 to all nodes #4 via all factors #3.
55 \foreach \f in {#3} { %
56 \foreach \x in {#2} { %
57 \draw[-,#1] (\x) edge[-] (\f) ; %
58 } ;
59 \foreach \y in {#4} { %
60 \draw[->,#1] (\f) -- (\y) ; %
61 } ;
62 } ;
63 }
64
65 % \edge [options] {inputs} {outputs}
66 \newcommand{\edge}[3][]{ %
67 % Connect all nodes #2 to all nodes #3.
68 \foreach \x in {#2} { %
69 \foreach \y in {#3} { %
70 \draw[->,#1] (\x) -- (\y) ;%
71 } ;
72 } ;
73 }
74
75 % \factor [options] {name} {caption} {inputs} {outputs}
76 \newcommand{\factor}[5][]{ %
77 % Draw the factor node. Use alias to allow empty names.
78 \node[factor, label={[name=#2-caption]#3}, name=#2, #1,
79 alias=#2-alias] {} ; %
80 % Connect all inputs to outputs via this factor
81 \factoredge {#4} {#2-alias} {#5} ; %
82 }
83
84 % \plate [options] {name} {fitlist} {caption}
85 \newcommand{\plate}[4][]{ %
86 \node[wrap=#3] (#2-wrap) {}; %
87 \node[plate caption=#2-wrap] (#2-caption) {#4}; %
88 \node[plate=(#2-wrap)(#2-caption), #1] (#2) {}; %
89 }
90
91 % \gate [options] {name} {fitlist} {inputs}
92 \newcommand{\gate}[4][]{ %
93 \node[gate=#3, name=#2, #1, alias=#2-alias] {}; %
94 \foreach \x in {#4} { %
95 \draw [-*,thick] (\x) -- (#2-alias); %
96 } ;%
97 }
98
99 % \vgate {name} {fitlist-left} {caption-left} {fitlist-right}
100 % {caption-right} {inputs}
101 \newcommand{\vgate}[6]{ %
102 % Wrap the left and right parts
103 \node[wrap=#2] (#1-left) {}; %
104 \node[wrap=#4] (#1-right) {}; %
105 % Draw the gate
106 \node[gate=(#1-left)(#1-right)] (#1) {}; %
107 % Add captions
108 \node[caption, below left=of #1.north ] (#1-left-caption)
109 {#3}; %
110 \node[caption, below right=of #1.north ] (#1-right-caption)
111 {#5}; %
112 % Draw middle separation
113 \draw [-, dashed] (#1.north) -- (#1.south); %
114 % Draw inputs
115 \foreach \x in {#6} { %
116 \draw [-*,thick] (\x) -- (#1); %
117 } ;%
118 }
119
120 % \hgate {name} {fitlist-top} {caption-top} {fitlist-bottom}
121 % {caption-bottom} {inputs}
122 \newcommand{\hgate}[6]{ %
123 % Wrap the left and right parts
124 \node[wrap=#2] (#1-top) {}; %
125 \node[wrap=#4] (#1-bottom) {}; %
126 % Draw the gate
127 \node[gate=(#1-top)(#1-bottom)] (#1) {}; %
128 % Add captions
129 \node[caption, above right=of #1.west ] (#1-top-caption)
130 {#3}; %
131 \node[caption, below right=of #1.west ] (#1-bottom-caption)
132 {#5}; %
133 % Draw middle separation
134 \draw [-, dashed] (#1.west) -- (#1.east); %
135 % Draw inputs
136 \foreach \x in {#6} { %
137 \draw [-*,thick] (\x) -- (#1); %
138 } ;%
139 }
140