Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Michele Volpato
Alnos
Commits
b965fd52
Commit
b965fd52
authored
Nov 13, 2015
by
Michele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added complete tester, still need to be run with more than 5 loops of learning
parent
ac77db53
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
3 deletions
+78
-3
examples/tictactoe/completetesting.py
examples/tictactoe/completetesting.py
+75
-0
examples/tictactoe/learn.py
examples/tictactoe/learn.py
+1
-1
examples/tictactoe/tictacteacher.py
examples/tictactoe/tictacteacher.py
+1
-1
systems/implementations.py
systems/implementations.py
+1
-1
No files found.
examples/tictactoe/completetesting.py
0 → 100644
View file @
b965fd52
# Copyright (c) 2015 Michele Volpato
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
from
testing.basetesting
import
AbstractTester
import
logging
import
itertools
# Complete tester.
class
CompleteTicTacToeTester
(
AbstractTester
):
def
__init__
(
self
,
teacher
,
logger
=
None
):
# The tester will run test using the teacher
self
.
_teacher
=
teacher
# upper bound: 9! (possible plays, also invalid ones)
# according to wikipedia
self
.
_all_games
=
set
(
itertools
.
permutations
([
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
]))
self
.
_logger
=
logger
or
logging
.
getLogger
(
__name__
)
# Search a counterexample to teacher ioco model
def
findCounterexample
(
self
,
model
):
self
.
_teacher
.
reset
()
model
.
reset
()
ce
=
()
i
=
0
for
i
in
self
.
_all_games
:
ce
=
()
# Next game
self
.
_teacher
.
reset
()
model
.
reset
()
# play this game, if we receive END, then go to next game.
for
action
in
i
:
ce
=
ce
+
(
action
,)
output
=
self
.
_processInputs
((
action
,))
model
.
move
(
action
)
if
output
not
in
model
.
outputs
():
self
.
_logger
.
info
(
"Found a counterexample: "
+
str
(
ce
)
+
" output: "
+
str
(
output
))
self
.
_teacher
.
reset
()
model
.
reset
()
# return counterexample trace and output obtained by
# testing
return
ce
,
output
elif
'END'
in
output
:
continue
else
:
model
.
move
(
output
)
ce
=
ce
+
(
output
,)
return
None
,
None
def
_processInputs
(
self
,
consecutiveInputs
):
if
consecutiveInputs
!=
():
output
=
self
.
_teacher
.
oneOutput
(
consecutiveInputs
)
if
output
==
None
:
return
None
return
output
return
self
.
_teacher
.
output
()
examples/tictactoe/learn.py
View file @
b965fd52
...
...
@@ -71,7 +71,7 @@ print("Starting learning...")
#print(T1.oneOutput(('1')))
L
=
LearningAlgorithm
(
T1
,
O1
,
printPath
=
path
,
maxLoops
=
4
,
L
=
LearningAlgorithm
(
T1
,
O1
,
printPath
=
path
,
maxLoops
=
10
,
tablePreciseness
=
100000
,
logger
=
logger
,
tester
=
tester
,
outputPurpose
=
outputExpert
,
inputPurpose
=
inputExpert
)
minus
,
plus
=
L
.
run
()
...
...
examples/tictactoe/tictacteacher.py
View file @
b965fd52
...
...
@@ -69,7 +69,7 @@ class TicTacToeTeacher(AbstractTeacher):
# Provide output from current state
def
output
(
self
):
ready
=
select
.
select
([
self
.
_socket
],
[],
[],
1
)
#
1
second timeout, for quiescence
ready
=
select
.
select
([
self
.
_socket
],
[],
[],
0.3
)
# second timeout, for quiescence
output
=
'delta'
if
ready
[
0
]:
output
=
self
.
_socket
.
recv
(
1024
).
decode
(
"utf-8"
)
...
...
systems/implementations.py
View file @
b965fd52
...
...
@@ -105,7 +105,7 @@ class InputOutputLTS(AbstractIOLTS):
keys
=
self
.
_transitions
.
keys
()
possibleOutputs
=
set
()
for
state
,
label
in
keys
:
if
state
!=
givenState
or
label
not
in
self
.
_
out
puts
:
if
state
!=
givenState
or
label
in
self
.
_
in
puts
:
continue
possibleOutputs
.
add
(
label
)
if
len
(
possibleOutputs
)
==
0
:
...
...
Write
Preview
Markdown
is supported
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