-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnn.sty
94 lines (78 loc) · 3.17 KB
/
nn.sty
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
%!TEX TS-program = xelatex
% vim: set fenc=utf-8
% -*- coding: UTF-8; -*-
%!TEX encoding = UTF-8 Unicode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FileName: nn.sty
%% Author: Timozer
%% E-mail: [email protected]
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{nn}[2018/02/03 v0.6 TikZ Neural Network Graphics]
\RequirePackage{tikz}
\def\@layersep{1.5cm}
\newcommand{\fnn}[1]{%
\begin{tikzpicture}[
shorten >=1pt,->,
draw=black,
node distance=\@layersep,
every pin edge/.style={<-,shorten <=1pt},
neuron/.style={circle,fill=black!25,minimum size=17pt,inner sep=0pt},
input neuron/.style={neuron, fill=green!50},
output neuron/.style={neuron, fill=red!50},
hidden neuron/.style={neuron, fill=blue!50},
annot/.style={text width=4em, text centered}
]
% Draw the input layer nodes
\foreach \name / \y in {1,...,4}
% This is the same as writing \foreach \name / \y in {1/1,2/2,3/3,4/4}
\node[input neuron, pin=left:Input \#\y] (I-\name) at (0,-\y) {$x_{\y}$};
% Draw the hidden layer nodes
\foreach \N in {1,...,#1} {
\foreach \y in {1,...,5} {
\path[yshift=0.5cm]
node[hidden neuron] (H\N-\y) at (\N*\@layersep,-\y cm) {};
}
\node[annot,above of=H\N-1, node distance=1cm] (hl\N) {Hidden layer \N};
}
% Draw the output layer node
\node[output neuron,pin={[pin edge={->}]right:Output}, right of=H#1-3] (O) {};
% Connect every node in the input layer with every node in the
% hidden layer.
\foreach \source in {1,...,4}
\foreach \dest in {1,...,5}
\path (I-\source) edge (H1-\dest);
% connect all hidden stuff
\foreach [remember=\N as \lastN (initially 1)] \N in {2,...,#1}
\foreach \source in {1,...,5}
\foreach \dest in {1,...,5}
\path (H\lastN-\source) edge (H\N-\dest);
% Connect every node in the hidden layer with the output layer
\foreach \source in {1,...,5}
\path (H#1-\source) edge (O);
% Annotate the layers
\node[annot,left of=hl1] {Input layer};
\node[annot,right of=hl#1] {Output layer};
\end{tikzpicture}
}
\newcommand{\phyview}{%
\begin{tikzpicture}[
every node/.style={circle, minimum size=25pt, inner sep=0pt},
every edge/.style={draw=black, ->, shorten >=2pt, semithick, >=stealth' },
every edge quotes/.style={auto=left, font=\footnotesize}
]
\node[draw=gray!50, fill=gray!20] (C)at (0, 1) {$C$};
\node[draw=red!50, fill=red!20] (O)at (0, -1) {$O$};
\node[draw=green!50, fill=green!20] (CO2) at (2, 1.5) {$CO_{2}$};
\node[draw=blue!50, fill=blue!20] (O3) at (2, 0) {$O_{3}$};
\node[draw=purple!50, fill=purple!20] (CO) at (2, -1.5) {$CO$};
\path (C.east) edge (CO2);
\path (C.east) edge (O3);
\path (C.east) edge (CO);
\path (O.east) edge (CO2);
\path (O.east) edge (O3);
\path (O.east) edge (CO);
\end{tikzpicture}
}
\endinput