Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dogopher
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gabriel Santamaria
Dogopher
Commits
19ec737b
Unverified
Commit
19ec737b
authored
9 months ago
by
Gabriel Santamaria
Browse files
Options
Downloads
Patches
Plain Diff
Updated statistics
parent
f9e27def
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compute.py
+16
-13
16 additions, 13 deletions
compute.py
with
16 additions
and
13 deletions
compute.py
+
16
−
13
View file @
19ec737b
...
...
@@ -52,9 +52,10 @@ def index(ply: Player):
# that will make MCTS win most of the time.
ucb
=
[
UCB
.
ucb
,
UCB
.
ucb_tuned
]
weights
=
np
.
arange
(
0
,
10
,
1
)
levels
=
np
.
arange
(
3
,
10
,
1
)
def
game
(
ce
,
fucb
,
i
):
def
game
(
ce
,
fucb
,
level
,
i
):
"""
Run a single game with the given parameters
"""
...
...
@@ -64,11 +65,11 @@ def game(ce, fucb, i):
if
i
%
2
==
1
:
player_one
=
StrategyAlphaBeta
(
grid
,
rules
,
1
,
depth
=
20
)
player_two
=
MCTSStrategy
(
grid
,
rules
,
2
,
minimax_level
=
10
,
exploration_weight
=
ce
,
ucb
=
fucb
grid
,
rules
,
2
,
minimax_level
=
level
,
exploration_weight
=
ce
,
ucb
=
fucb
)
else
:
player_one
=
MCTSStrategy
(
grid
,
rules
,
1
,
minimax_level
=
10
,
exploration_weight
=
ce
,
ucb
=
fucb
grid
,
rules
,
1
,
minimax_level
=
level
,
exploration_weight
=
ce
,
ucb
=
fucb
)
player_two
=
StrategyAlphaBeta
(
grid
,
rules
,
2
,
depth
=
20
)
...
...
@@ -107,7 +108,7 @@ def game(ce, fucb, i):
return
int
(
rules
.
has_won
(
grid
,
ply_mcts
)),
ttime
,
niter
def
run
(
ce
,
fucb
,
n
=
50
,
pbar
=
None
):
def
run
(
ce
,
fucb
,
level
,
n
=
NITER_PER_GAME
,
pbar
=
None
):
"""
Runs n games with the given parameters and returns the
number of wins for each player and the total time spent
...
...
@@ -119,7 +120,7 @@ def run(ce, fucb, n=50, pbar=None):
results
=
[]
for
i
in
range
(
n
):
results
.
append
(
game
(
ce
,
fucb
,
i
))
results
.
append
(
game
(
ce
,
fucb
,
level
,
i
))
if
pbar
:
pbar
.
update
(
1
)
...
...
@@ -136,16 +137,17 @@ def iterate():
Gently iterate over the parameters space and gets
the data from the run function
"""
wins
=
np
.
zeros
((
len
(
ucb
),
len
(
weights
)),
dtype
=
np
.
float64
)
times
=
np
.
zeros
((
len
(
ucb
),
len
(
weights
)),
dtype
=
np
.
float64
)
wins
=
np
.
zeros
((
len
(
ucb
),
len
(
weights
)
,
len
(
levels
)
),
dtype
=
np
.
float64
)
times
=
np
.
zeros
((
len
(
ucb
),
len
(
weights
)
,
len
(
levels
)
),
dtype
=
np
.
float64
)
niter
=
len
(
ucb
)
*
len
(
weights
)
niter
=
len
(
ucb
)
*
len
(
weights
)
*
len
(
levels
)
with
tqdm
(
total
=
niter
*
NITER_PER_GAME
,
desc
=
"
Computing statistics...
"
)
as
pbar
:
for
i
,
u
in
enumerate
(
ucb
):
for
j
,
w
in
enumerate
(
weights
):
nwins
,
t
,
n
,
niters
=
run
(
w
,
u
,
pbar
=
pbar
)
wins
[
i
,
j
]
=
nwins
/
n
*
100
times
[
i
,
j
]
=
t
/
niters
for
k
,
l
in
enumerate
(
levels
):
nwins
,
t
,
n
,
niters
=
run
(
w
,
u
,
l
,
pbar
=
pbar
)
wins
[
i
,
j
,
k
]
=
nwins
/
n
*
100
times
[
i
,
j
,
k
]
=
t
/
niters
return
wins
,
times
...
...
@@ -155,11 +157,12 @@ def write_csv(wins, times):
Write the results to a CSV file
"""
with
open
(
"
stats.csv
"
,
"
w
"
,
encoding
=
"
utf-8
"
)
as
f
:
f
.
write
(
"
UCB,Weight,Wins,Time
\n
"
)
f
.
write
(
"
UCB,Weight,
Minimax Level,
Wins,Time
\n
"
)
for
i
,
_
in
enumerate
(
ucb
):
for
j
,
_
in
enumerate
(
weights
):
f
.
write
(
f
"
{
i
}
,
{
j
}
,
{
wins
[
i
,
j
]
}
,
{
times
[
i
,
j
]
}
\n
"
)
for
k
,
_
in
enumerate
(
levels
):
f
.
write
(
f
"
{
i
}
,
{
j
}
,
{
k
}
,
{
wins
[
i
,
j
,
k
]
}
,
{
times
[
i
,
j
,
k
]
}
\n
"
)
data_wins
,
data_times
=
iterate
()
...
...
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