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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Philip Maas
Bipedal Walker Evo
Commits
2fd89306
Commit
2fd89306
authored
3 years ago
by
Tobias Döring
Browse files
Options
Downloads
Patches
Plain Diff
added increasing steps
parent
c3e0f688
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
EvolutionStrategies/main.py
+9
-4
9 additions, 4 deletions
EvolutionStrategies/main.py
EvolutionStrategies/population.py
+1
-1
1 addition, 1 deletion
EvolutionStrategies/population.py
EvolutionStrategies/walker.py
+10
-4
10 additions, 4 deletions
EvolutionStrategies/walker.py
with
20 additions
and
9 deletions
EvolutionStrategies/main.py
+
9
−
4
View file @
2fd89306
...
...
@@ -10,11 +10,11 @@ POP_SIZE = 50
MUTATION_FACTOR
=
0.1
# 0 <= x <= 1
LEARNING_RATE
=
0.03
# 0 <= x <= 1
GENS
=
10000
MAX_STEPS
=
3
00
# after 1600 steps the Environment gives us a done anyway.
MAX_STEPS
=
1
00
# after 1600 steps the Environment gives us a done anyway.
DECAY_ALPHA
=
True
VERSION
=
10
0
TEST_WALKER
=
Tru
e
VERSION
=
10
1
TEST_WALKER
=
Fals
e
LOAD_BRAIN
=
False
RENDER_BEST
=
False
if
TEST_WALKER
:
...
...
@@ -49,14 +49,17 @@ if __name__ == '__main__':
for
gen
in
range
(
GENS
):
# this is our game
start_time
=
time
.
time
()
print
(
f
'
Gen:
{
gen
}
'
)
print
(
f
'
Steps:
{
population
.
max_steps
}
'
)
population
.
mutate
()
population
.
play_episode
()
population
.
evolve
()
print
(
"
Time for Gen:
"
,
time
.
time
()
-
start_time
)
if
gen
%
10
==
0
:
avg_reward
=
population
.
get_walker_stats
()
if
avg_reward
>
best_avg_reward
:
population
.
walker
.
save
()
population
.
walker
.
save_evo
(
gen
)
if
avg_reward
>
best_avg_reward
:
population
.
walker
.
save
(
'
best
'
)
best_avg_reward
=
avg_reward
print
(
"
New best walker found
"
)
avg_rewards
.
append
(
avg_reward
)
...
...
@@ -69,6 +72,8 @@ if __name__ == '__main__':
if
gen
==
5000
and
DECAY_ALPHA
:
population
.
lr
=
0.005
population
.
mutation_factor
=
0.01
# increase the amount of steps the agent can do
population
.
max_steps
+=
2
plot_reward
(
avg_rewards
)
except
KeyboardInterrupt
:
...
...
This diff is collapsed.
Click to expand it.
EvolutionStrategies/population.py
+
1
−
1
View file @
2fd89306
...
...
@@ -38,7 +38,7 @@ class Population:
for
i
in
range
(
self
.
size
):
for
k
in
weights
:
weights_change
=
np
.
dot
(
self
.
mutants
[
i
].
weights
[
k
].
T
,
A
[
i
]).
T
weights
[
k
]
=
weights
[
k
]
+
self
.
lr
/
(
self
.
size
*
self
.
l
r
)
*
weights_change
weights
[
k
]
=
weights
[
k
]
+
self
.
lr
/
(
self
.
size
*
self
.
mutation_facto
r
)
*
weights_change
self
.
walker
.
set_weights
(
weights
)
for
mutant
in
self
.
mutants
:
mutant
.
set_weights
(
weights
)
...
...
This diff is collapsed.
Click to expand it.
EvolutionStrategies/walker.py
+
10
−
4
View file @
2fd89306
...
...
@@ -105,12 +105,18 @@ class Walker:
self
.
env
.
action_space
.
shape
[
0
]],
[
self
.
weights
[
'
W1
'
],
self
.
weights
[
'
W2
'
]])
network
.
draw
(
gen
)
def
save
(
self
):
def
save_evo
(
self
,
gen
):
if
not
os
.
path
.
isdir
(
f
'
./models/weights_evo
{
self
.
version
}
'
):
os
.
mkdir
(
f
'
./models/weights_evo
{
self
.
version
}
'
)
with
open
(
f
'
./models/weights_evo
{
self
.
version
}
/model-pedal
{
gen
}
.p
'
,
'
wb
'
)
as
fp
:
pickle
.
dump
(
self
.
weights
,
fp
)
def
save
(
self
,
name
=
'
current
'
):
if
not
os
.
path
.
isdir
(
'
./models
'
):
os
.
mkdir
(
'
./models
'
)
with
open
(
'
./models/model-pedal
%d.p
'
%
self
.
version
,
'
wb
'
)
as
fp
:
with
open
(
f
'
./models/model-pedal
{
self
.
version
}
-
{
name
}
.p
'
,
'
wb
'
)
as
fp
:
pickle
.
dump
(
self
.
weights
,
fp
)
def
load
(
self
):
with
open
(
'
./models/model-pedal
%d.p
'
%
self
.
version
,
'
rb
'
)
as
fp
:
def
load
(
self
,
name
=
'
current
'
):
with
open
(
f
'
./models/model-pedal
{
self
.
version
}
-
{
name
}
.p
'
,
'
rb
'
)
as
fp
:
self
.
weights
=
pickle
.
load
(
fp
)
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