Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zengeler, Nico
OpenAI Gym Tron
Commits
751991b3
Commit
751991b3
authored
Sep 06, 2021
by
max
Browse files
feat: release 06-09-2021
parent
1194e2aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
generational/generation.py
View file @
751991b3
...
...
@@ -174,7 +174,7 @@ class GenerationalEnvironment:
self
.
infos_list
=
checkpoint
[
"infos_list"
]
pass
def
visualize_graphs
(
self
):
def
visualize_graphs
(
self
,
version
:
int
,
files
:
str
=
'files'
):
turns_list_length
=
[]
i
=
0
for
item
in
self
.
turns_list
:
...
...
@@ -185,20 +185,72 @@ class GenerationalEnvironment:
plt
.
title
(
"turns_taken_per_epoch"
)
plt
.
show
()
for
agent_id
in
self
.
game_networks
:
agent_rewards_epoch
=
[]
for
item
in
self
.
epoch_rewards_list
:
agent_rewards_epoch
.
append
(
item
[
agent_id
])
agent_losses_epoch
=
[]
for
item
in
self
.
epoch_loss_list
:
agent_losses_epoch
.
append
(
item
[
agent_id
])
plt
.
plot
(
agent_rewards_epoch
)
plt
.
title
(
agent_id
+
"_epoch_rewards"
)
plt
.
show
()
plt
.
plot
(
agent_losses_epoch
)
plt
.
title
(
agent_id
+
"_epoch_loss"
)
plt
.
show
()
agents_medium_rewards_list
=
[]
agents_medium_loss_list
=
[]
agent_rewards_epoch
=
{
agent
:
[]
for
agent
in
self
.
game_networks
}
for
item
in
self
.
epoch_rewards_list
:
for
agent_id
in
self
.
game_networks
:
agent_rewards_epoch
[
agent_id
].
append
(
item
[
agent_id
])
median
=
0
for
value
in
item
.
values
():
median
+=
value
median
=
median
/
self
.
game_networks
.
__len__
()
agents_medium_rewards_list
.
append
(
median
)
agent_losses_epoch
=
{
agent
:
[]
for
agent
in
self
.
game_networks
}
for
item
in
self
.
epoch_loss_list
:
for
agent_id
in
self
.
game_networks
:
agent_losses_epoch
[
agent_id
].
append
(
item
[
agent_id
])
median
=
0
for
value
in
item
.
values
():
median
+=
value
median
=
median
/
self
.
game_networks
.
__len__
()
agents_medium_loss_list
.
append
(
median
)
# plt.title(agent_id + "_epoch_rewards")
# plt.show()
# plt.plot(agent_losses_epoch)
# plt.title(agent_id + "_epoch_loss")
# plt.show()
fig
,
axs
=
plt
.
subplots
(
3
,
2
,
sharey
=
True
)
axs
[
0
,
0
].
plot
(
agent_rewards_epoch
[
'agent_1'
],
'g-'
)
axs
[
0
,
0
].
set_title
(
'Agent 1'
)
axs
[
0
,
1
].
plot
(
agent_rewards_epoch
[
'agent_2'
],
'c-'
)
axs
[
0
,
1
].
set_title
(
'Agent 2'
)
axs
[
1
,
0
].
plot
(
agent_rewards_epoch
[
'agent_3'
],
'm-'
)
axs
[
1
,
0
].
set_title
(
'Agent 3'
)
axs
[
1
,
1
].
plot
(
agent_rewards_epoch
[
'agent_4'
],
'y-'
)
axs
[
1
,
1
].
set_title
(
'Agent 4'
)
axm
=
plt
.
subplot2grid
((
3
,
3
),
(
2
,
0
),
colspan
=
3
)
axm
.
plot
(
agents_medium_rewards_list
,
'r-'
)
axm
.
set_title
(
'Median'
)
plt
.
title
(
"epoch_rewards"
)
plt
.
gcf
().
set_size_inches
((
15
,
15
))
plt
.
savefig
(
fname
=
"{file}/{version}/rewards.pdf"
.
format
(
file
=
files
,
version
=
str
(
version
)))
# plt.show()
plt
.
close
()
fig
,
axs
=
plt
.
subplots
(
3
,
2
,
sharey
=
True
)
axs
[
0
,
0
].
plot
(
agent_losses_epoch
[
'agent_1'
],
'g-'
)
axs
[
0
,
0
].
set_title
(
'Agent 1'
)
axs
[
0
,
1
].
plot
(
agent_losses_epoch
[
'agent_2'
],
'c-'
)
axs
[
0
,
1
].
set_title
(
'Agent 2'
)
axs
[
1
,
0
].
plot
(
agent_losses_epoch
[
'agent_3'
],
'm-'
)
axs
[
1
,
0
].
set_title
(
'Agent 3'
)
axs
[
1
,
1
].
plot
(
agent_losses_epoch
[
'agent_4'
],
'y-'
)
axs
[
1
,
1
].
set_title
(
'Agent 4'
)
axm
=
plt
.
subplot2grid
((
3
,
3
),
(
2
,
0
),
colspan
=
3
)
axm
.
plot
(
agents_medium_loss_list
,
'r-'
)
axm
.
set_title
(
'Median'
)
plt
.
title
(
"epoch_loss"
)
plt
.
gcf
().
set_size_inches
((
15
,
15
))
plt
.
savefig
(
fname
=
"{file}/{version}/loss.pdf"
.
format
(
file
=
files
,
version
=
str
(
version
)))
# plt.show()
# agent_losses = []
# for item in self.loss_list:
...
...
main.py
View file @
751991b3
...
...
@@ -72,21 +72,20 @@ class sticky_actions_vcustom(StepAltWrapper):
super
().
step
(
action
)
def
show_progress
(
version
:
int
):
file
=
"files"
def
show_progress
(
version
:
int
,
file
:
str
=
"files"
):
tron
=
GenerationalTronEnvironment
(
env
=
env_creator
(),
device
=
device
,
render
=
True
,
training
=
False
)
tron
.
load_agents
(
"{}/{version}/"
.
format
(
file
,
version
=
str
(
version
)))
tron
.
load_agents
(
"{
file
}/{version}/"
.
format
(
file
=
file
,
version
=
str
(
version
)))
tron
.
visualize_graphs
()
rewards_list
,
loss_list
,
turns_list
,
infos_list
=
tron
.
play_loop
(
1
)
infos
=
infos_list
[
-
1
]
for
agent
,
info
in
infos
.
items
():
if
agent
==
"__iteration__"
:
continue
plt
.
imshow
(
info
,
cmap
=
'hot'
,
interpolation
=
'nearest'
)
plt
.
savefig
(
fname
=
"{}/{version}/{agent}_iteration_{iteration}.png"
.
format
(
file
,
version
=
str
(
version
),
agent
=
agent
,
iteration
=
str
(
infos
[
"__iteration__"
])))
pass
tron
.
visualize_graphs
(
version
=
version
)
#
rewards_list, loss_list, turns_list, infos_list = tron.play_loop(1)
#
infos = infos_list[-1]
#
for agent, info in infos.items():
#
if agent == "__iteration__":
#
continue
#
plt.imshow(info, cmap='hot', interpolation='nearest')
#
plt.savefig(fname="{}/{version}/{agent}_iteration_{iteration}.png".format(file, version=str(version), agent=agent, iteration=str(infos["__iteration__"])))
#
pass
def
create_params
(
competitive
:
bool
=
True
,
cooperative
:
bool
=
False
,
death_punish
:
bool
=
True
):
...
...
@@ -528,11 +527,11 @@ if __name__ == '__main__':
# parallel_test_env(num_cycles=2500000, env=atari_pong_no_config(False))
# parallel_test_env(env=atari_pong({}), num_cycles=100000)
#
show_progress(47)
show_progress
(
47
)
# train()
# train2p()
# train_tron_v2(cooperative=False, competitive=True, death_punish=True)
vis_graphic_tron
(
"files"
,
48
,
2
)
#
vis_graphic_tron("files", 48,
3
)
# AutoROM.main(True, "D:/Programmieren/Python/Rom/")
...
...
myplot.png
0 → 100644
View file @
751991b3
109 KB
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment