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
f82ea3df
Commit
f82ea3df
authored
Feb 6, 2022
by
Tobias Döring
Browse files
Options
Downloads
Patches
Plain Diff
added weights to mlp visualisation
parent
238d1bc6
Branches
Branches containing commit
No related tags found
1 merge request
!2
Evo neuro
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.py
+1
-1
1 addition, 1 deletion
main.py
mlp_visualizer.py
+23
-10
23 additions, 10 deletions
mlp_visualizer.py
walker.py
+11
-0
11 additions, 0 deletions
walker.py
with
35 additions
and
11 deletions
main.py
+
1
−
1
View file @
f82ea3df
...
@@ -13,7 +13,7 @@ MAX_STEPS = 1200 # after 1600 steps the Environment gives us a done anyway.
...
@@ -13,7 +13,7 @@ MAX_STEPS = 1200 # after 1600 steps the Environment gives us a done anyway.
VERSION
=
1
VERSION
=
1
TEST_WALKER
=
Fals
e
TEST_WALKER
=
Tru
e
LOAD_BRAIN
=
False
LOAD_BRAIN
=
False
RENDER_BEST
=
False
RENDER_BEST
=
False
if
TEST_WALKER
:
if
TEST_WALKER
:
...
...
This diff is collapsed.
Click to expand it.
mlp_visualizer.py
+
23
−
10
View file @
f82ea3df
from
numpy
import
cos
,
sin
,
arctan
from
numpy
import
cos
,
sin
,
arctan
from
matplotlib
import
pyplot
from
matplotlib
import
pyplot
vertical_distance_between_layers
=
40
horizontal_distance_between_neurons
=
4
neuron_radius
=
1
default_line_width
=
1
class
Neuron
:
class
Neuron
:
def
__init__
(
self
,
x
,
y
):
def
__init__
(
self
,
x
,
y
):
...
@@ -13,10 +17,11 @@ class Neuron:
...
@@ -13,10 +17,11 @@ class Neuron:
class
Layer
:
class
Layer
:
def
__init__
(
self
,
network
,
number_of_neurons
):
def
__init__
(
self
,
network
,
number_of_neurons
,
weights
):
self
.
previous_layer
=
self
.
get_previous_layer
(
network
)
self
.
previous_layer
=
self
.
get_previous_layer
(
network
)
self
.
y
=
self
.
calculate_layer_y_position
()
self
.
y
=
self
.
calculate_layer_y_position
()
self
.
neurons
=
self
.
init_neurons
(
number_of_neurons
)
self
.
neurons
=
self
.
init_neurons
(
number_of_neurons
)
self
.
weights
=
weights
def
init_neurons
(
self
,
number_of_neurons
):
def
init_neurons
(
self
,
number_of_neurons
):
neurons
=
[]
neurons
=
[]
...
@@ -42,27 +47,38 @@ class Layer:
...
@@ -42,27 +47,38 @@ class Layer:
else
:
else
:
return
None
return
None
def
line
(
self
,
neuron1
,
neuron2
):
def
line
(
self
,
neuron1
,
neuron2
,
weight
):
angle
=
arctan
((
neuron2
.
x
-
neuron1
.
x
)
/
float
(
neuron2
.
y
-
neuron1
.
y
))
angle
=
arctan
((
neuron2
.
x
-
neuron1
.
x
)
/
float
(
neuron2
.
y
-
neuron1
.
y
))
x_adjustment
=
neuron_radius
*
sin
(
angle
)
x_adjustment
=
neuron_radius
*
sin
(
angle
)
y_adjustment
=
neuron_radius
*
cos
(
angle
)
y_adjustment
=
neuron_radius
*
cos
(
angle
)
color
=
'
blue
'
if
weight
<
0
:
color
=
'
red
'
line
=
pyplot
.
Line2D
((
neuron1
.
x
-
x_adjustment
,
neuron2
.
x
+
x_adjustment
),
line
=
pyplot
.
Line2D
((
neuron1
.
x
-
x_adjustment
,
neuron2
.
x
+
x_adjustment
),
(
neuron1
.
y
-
y_adjustment
,
neuron2
.
y
+
y_adjustment
),
linewidth
=
1
,
color
=
'
blue
'
)
# HIER
(
neuron1
.
y
-
y_adjustment
,
neuron2
.
y
+
y_adjustment
),
linewidth
=
default_line_width
*
weight
,
color
=
color
)
# HIER
pyplot
.
gca
().
add_line
(
line
)
pyplot
.
gca
().
add_line
(
line
)
def
draw
(
self
):
def
draw
(
self
):
y
=
0
for
neuron
in
self
.
neurons
:
for
neuron
in
self
.
neurons
:
if
self
.
previous_layer
:
if
self
.
previous_layer
:
x
=
0
for
previous_layer_neuron
in
self
.
previous_layer
.
neurons
:
for
previous_layer_neuron
in
self
.
previous_layer
.
neurons
:
self
.
line
(
neuron
,
previous_layer_neuron
)
self
.
line
(
neuron
,
previous_layer_neuron
,
self
.
weights
[
x
][
y
])
x
+=
1
y
+=
1
neuron
.
draw
()
neuron
.
draw
()
class
NeuralNetwork
():
class
NeuralNetwork
():
def
__init__
(
self
,
architecture
):
def
__init__
(
self
,
architecture
,
weights
):
self
.
layers
=
[]
self
.
layers
=
[]
for
layer_size
in
architecture
:
for
i
in
range
(
len
(
architecture
)):
self
.
layers
.
append
(
Layer
(
self
,
layer_size
))
if
i
>
0
:
self
.
layers
.
append
(
Layer
(
self
,
architecture
[
i
],
weights
[
i
-
1
]))
else
:
self
.
layers
.
append
(
Layer
(
self
,
architecture
[
i
],
None
))
def
add_layer
(
self
,
number_of_neurons
):
def
add_layer
(
self
,
number_of_neurons
):
layer
=
Layer
(
self
,
number_of_neurons
)
layer
=
Layer
(
self
,
number_of_neurons
)
...
@@ -77,8 +93,5 @@ class NeuralNetwork():
...
@@ -77,8 +93,5 @@ class NeuralNetwork():
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
vertical_distance_between_layers
=
40
horizontal_distance_between_neurons
=
4
neuron_radius
=
1
network
=
NeuralNetwork
([
24
,
12
,
4
])
network
=
NeuralNetwork
([
24
,
12
,
4
])
network
.
draw
()
network
.
draw
()
This diff is collapsed.
Click to expand it.
walker.py
+
11
−
0
View file @
f82ea3df
...
@@ -4,6 +4,8 @@ import copy
...
@@ -4,6 +4,8 @@ import copy
import
os
import
os
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
mlp_visualizer
np
.
random
.
seed
(
42
)
np
.
random
.
seed
(
42
)
class
Walker
:
class
Walker
:
...
@@ -87,6 +89,15 @@ class Walker:
...
@@ -87,6 +89,15 @@ class Walker:
plt
.
xticks
(
rotation
=
45
,
ha
=
"
right
"
)
plt
.
xticks
(
rotation
=
45
,
ha
=
"
right
"
)
plt
.
show
()
plt
.
show
()
mlp_visualizer
.
vertical_distance_between_layers
=
40
mlp_visualizer
.
horizontal_distance_between_neurons
=
4
mlp_visualizer
.
neuron_radius
=
1
mlp_visualizer
.
default_line_width
=
1
network
=
mlp_visualizer
.
NeuralNetwork
([
24
,
self
.
hidden_layer
,
4
],
[
self
.
weights
[
'
W1
'
],
self
.
weights
[
'
W2
'
]])
network
.
draw
()
def
save
(
self
):
def
save
(
self
):
if
not
os
.
path
.
isdir
(
'
./models
'
):
if
not
os
.
path
.
isdir
(
'
./models
'
):
os
.
mkdir
(
'
./models
'
)
os
.
mkdir
(
'
./models
'
)
...
...
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