Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Bipedal Walker Evo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philip Maas
Bipedal Walker Evo
Commits
b91b0072
Commit
b91b0072
authored
Feb 2, 2022
by
Philip Maas
Browse files
Options
Downloads
Patches
Plain Diff
Added a prototype for an mlp visualizer
parent
46616c15
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!2
Evo neuro
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
mlp.png
+0
-0
0 additions, 0 deletions
mlp.png
mlp_visualizer.py
+84
-0
84 additions, 0 deletions
mlp_visualizer.py
with
84 additions
and
0 deletions
mlp.png
0 → 100644
+
0
−
0
View file @
b91b0072
346 KiB
This diff is collapsed.
Click to expand it.
mlp_visualizer.py
0 → 100644
+
84
−
0
View file @
b91b0072
from
numpy
import
cos
,
sin
,
arctan
from
matplotlib
import
pyplot
class
Neuron
:
def
__init__
(
self
,
x
,
y
):
self
.
x
=
x
self
.
y
=
y
def
draw
(
self
):
circle
=
pyplot
.
Circle
((
self
.
x
,
self
.
y
),
radius
=
neuron_radius
,
fill
=
False
)
pyplot
.
gca
().
add_patch
(
circle
)
class
Layer
:
def
__init__
(
self
,
network
,
number_of_neurons
):
self
.
previous_layer
=
self
.
get_previous_layer
(
network
)
self
.
y
=
self
.
calculate_layer_y_position
()
self
.
neurons
=
self
.
init_neurons
(
number_of_neurons
)
def
init_neurons
(
self
,
number_of_neurons
):
neurons
=
[]
x
=
self
.
calc_left_margin
(
number_of_neurons
)
for
iteration
in
range
(
number_of_neurons
):
neuron
=
Neuron
(
x
,
self
.
y
)
neurons
.
append
(
neuron
)
x
+=
horizontal_distance_between_neurons
return
neurons
def
calc_left_margin
(
self
,
number_of_neurons
):
# so it's centered
return
-
horizontal_distance_between_neurons
*
number_of_neurons
/
2
def
calculate_layer_y_position
(
self
):
if
self
.
previous_layer
:
return
self
.
previous_layer
.
y
+
vertical_distance_between_layers
else
:
return
0
def
get_previous_layer
(
self
,
network
):
if
len
(
network
.
layers
)
>
0
:
return
network
.
layers
[
-
1
]
else
:
return
None
def
line
(
self
,
neuron1
,
neuron2
):
angle
=
arctan
((
neuron2
.
x
-
neuron1
.
x
)
/
float
(
neuron2
.
y
-
neuron1
.
y
))
x_adjustment
=
neuron_radius
*
sin
(
angle
)
y_adjustment
=
neuron_radius
*
cos
(
angle
)
line
=
pyplot
.
Line2D
((
neuron1
.
x
-
x_adjustment
,
neuron2
.
x
+
x_adjustment
),
(
neuron1
.
y
-
y_adjustment
,
neuron2
.
y
+
y_adjustment
),
linewidth
=
1
,
color
=
'
blue
'
)
# HIER
pyplot
.
gca
().
add_line
(
line
)
def
draw
(
self
):
for
neuron
in
self
.
neurons
:
if
self
.
previous_layer
:
for
previous_layer_neuron
in
self
.
previous_layer
.
neurons
:
self
.
line
(
neuron
,
previous_layer_neuron
)
neuron
.
draw
()
class
NeuralNetwork
():
def
__init__
(
self
,
architecture
):
self
.
layers
=
[]
for
layer_size
in
architecture
:
self
.
layers
.
append
(
Layer
(
self
,
layer_size
))
def
add_layer
(
self
,
number_of_neurons
):
layer
=
Layer
(
self
,
number_of_neurons
)
self
.
layers
.
append
(
layer
)
def
draw
(
self
):
for
layer
in
self
.
layers
:
layer
.
draw
()
pyplot
.
axis
(
'
scaled
'
)
pyplot
.
savefig
(
'
mlp.png
'
,
dpi
=
300
)
pyplot
.
show
()
if
__name__
==
"
__main__
"
:
vertical_distance_between_layers
=
40
horizontal_distance_between_neurons
=
4
neuron_radius
=
1
network
=
NeuralNetwork
([
24
,
12
,
4
])
network
.
draw
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment