-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeural_Network.ps
105 lines (86 loc) · 2.81 KB
/
Neural_Network.ps
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
95
96
97
98
99
100
101
102
103
104
105
% >>> TAIR YERNIYAZOV, Cracow, 04.2023
% ====================================== Variables ========================================
/initialLineWidth 0.1 def
/boldLineWidth 0.8 def
/OX 50 def
/OY 350 def
OX OY translate
/nodes [3 4 6 12 9 4 1] def % Array containing the number of corresponding neurons
/numberOfLayers 7 def
/layer 0 def
/nodeIndex 0 def
/verPos 0 def
/horPos 0 def
/horShift 80 def
% ====================================== Procedures =======================================
% =========== Drawing a neuron ===========
/draw_neuron {
/y exch def
/x exch def
0.6 0.8 1 setrgbcolor
x y 10 0 360 arc fill
0 0 0 setrgbcolor
/tempOY OY def
layer numberOfLayers 1 sub lt {
/tempOY tempOY nodeIndex 30 mul sub def
nodes layer 1 add get {
x y moveto
% ======== The last weight layer =========
layer numberOfLayers 2 sub eq {
boldLineWidth setlinewidth
0.2 0.6 0.4 setrgbcolor
horShift tempOY rlineto stroke
} if
% ======== The first weight layer ========
layer 0 eq {
boldLineWidth setlinewidth
1 0 0 setrgbcolor
horShift tempOY rlineto stroke
} if
% ========= Other weight layers ==========
layer numberOfLayers 2 sub ne layer 0 ne and {
initialLineWidth setlinewidth
horShift tempOY rlineto stroke
} if
newpath
/tempOY tempOY 30 add def
} repeat
} if
} def
% ======= Preparing the next layer position shift ========
/prepareNextLayerPosition {
layer numberOfLayers 1 sub lt {
/OY nodes layer get nodes layer 1 add get sub abs 2 div 1 add 20 mul def
nodes layer 1 add get nodes layer get le {
/OY OY def
} {
/OY OY neg def
} ifelse
/OX OX 40 add def
} if
} def
% ==================== Main running part ===============
initialLineWidth setlinewidth
% ============ Drawing the neural network ==============
numberOfLayers {
prepareNextLayerPosition
nodes layer get {
horPos verPos draw_neuron
/verPos verPos 30 add def
/nodeIndex nodeIndex 1 add def
} repeat
/nodeIndex 0 def
/verPos 0 def
/horPos horPos horShift add def
0 OY translate
/layer layer 1 add def
} repeat
% ============ Drawing the headline ====================
initmatrix
/Courier-Bold findfont 50 scalefont setfont
90 700 moveto
(Neural Network) show
/Courier findfont 25 scalefont setfont
190 660 moveto
(Visualisation) show
showpage