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
1e690422
Commit
1e690422
authored
3 years ago
by
Tobias Döring
Browse files
Options
Downloads
Patches
Plain Diff
Added plotting of rewards
parent
7ef0794a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
MutateActions/main.py
+28
-2
28 additions, 2 deletions
MutateActions/main.py
with
28 additions
and
2 deletions
MutateActions/main.py
+
28
−
2
View file @
1e690422
from
population
import
Population
import
time
import
matplotlib.pyplot
as
plt
import
pickle
INCREASE_BY
=
5
BRAIN_SIZE
=
50
POP_SIZE
=
50
MUTATION_FACTOR
=
0.
1
# 0 <= x <= 1
MUTATION_FACTOR
=
0.
2
# 0 <= x <= 1
GAME_CANCELLED
=
False
LOAD_BRAIN
=
Tru
e
LOAD_BRAIN
=
Fals
e
RENDER_BEST
=
False
TEST_WALKER
=
True
if
TEST_WALKER
:
LOAD_BRAIN
=
True
if
__name__
==
'
__main__
'
:
population
=
Population
(
POP_SIZE
,
BRAIN_SIZE
,
MUTATION_FACTOR
,
LOAD_BRAIN
,
RENDER_BEST
)
rewards
=
[]
if
TEST_WALKER
:
rewards
=
[]
with
open
(
'
rewards.p
'
,
'
rb
'
)
as
fp
:
rewards
=
pickle
.
load
(
fp
)
plt
.
title
(
f
'
{
POP_SIZE
}
,
{
MUTATION_FACTOR
}
'
)
plt
.
xlabel
(
'
Episodes
'
)
plt
.
ylabel
(
'
Rewards
'
)
plt
.
plot
(
rewards
)
plt
.
savefig
(
f
'
./models/
{
POP_SIZE
}
,
{
MUTATION_FACTOR
}
.png
'
)
plt
.
show
()
while
GAME_CANCELLED
is
False
:
# this is our game
if
population
.
all_players_finished
():
# this is our genetic algorithm after one generation of players
population
.
natural_selection
()
population
.
mutate_babies
()
...
...
@@ -24,6 +44,12 @@ if __name__ == '__main__':
print
(
f
'
Best Index:
{
population
.
best_walker_index
}
'
)
print
(
f
'
Best Fitness:
{
population
.
fitnesses
[
population
.
best_walker_index
]
}
'
)
print
(
f
'
Max Steps:
{
population
.
max_steps
}
'
)
rewards
.
append
(
population
.
fitnesses
[
population
.
best_walker_index
])
if
population
.
gen
%
10
==
0
:
with
open
(
"
rewards.p
"
,
'
wb
'
)
as
fp
:
pickle
.
dump
(
rewards
,
fp
)
else
:
population
.
update
()
# time.sleep(0.1)
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