Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
Alnos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Michele Volpato
Alnos
Commits
ac77db53
Commit
ac77db53
authored
Nov 13, 2015
by
Michele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added placeholder for ALL OUTPUTS in table
parent
c30fa82c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
53 additions
and
14 deletions
+53
-14
examples/tictactoe/learn.py
examples/tictactoe/learn.py
+13
-8
examples/tictactoe/tictacoracle.py
examples/tictactoe/tictacoracle.py
+27
-2
examples/tictactoe/tictacpurpose.py
examples/tictactoe/tictacpurpose.py
+8
-3
examples/tictactoe/tictactoe.py
examples/tictactoe/tictactoe.py
+1
-1
learning/learning.py
learning/learning.py
+2
-0
testing/randomtesting.py
testing/randomtesting.py
+2
-0
No files found.
examples/tictactoe/learn.py
View file @
ac77db53
...
@@ -34,10 +34,11 @@ import itertools
...
@@ -34,10 +34,11 @@ import itertools
from
tictacteacher
import
TicTacToeTeacher
from
tictacteacher
import
TicTacToeTeacher
from
tictacoracle
import
TicTacToeOracle
from
tictacoracle
import
TicTacToeOracle
from
tictacpurpose
import
InputPurpose
,
OutputPurpose
from
tictacpurpose
import
TicTacToeInputPurpose
,
TicTacToe
OutputPurpose
from
learning.learning
import
LearningAlgorithm
from
learning.learning
import
LearningAlgorithm
from
testing.randomtesting
import
RandomTester
from
testing.randomtesting
import
RandomTester
from
completetesting
import
CompleteTicTacToeTester
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -45,17 +46,21 @@ logger = logging.getLogger(__name__)
...
@@ -45,17 +46,21 @@ logger = logging.getLogger(__name__)
HOST
=
'localhost'
HOST
=
'localhost'
PORT
=
29000
# Arbitrary non-privileged port
PORT
=
29000
# Arbitrary non-privileged port
outputExpert
=
TicTacToeOutputPurpose
()
inputExpert
=
TicTacToeInputPurpose
()
inputs
=
set
([
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
])
inputs
=
set
([
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
])
outputs
=
set
(
itertools
.
product
(
'XO_'
,
repeat
=
9
))
# Use a placeholder for outputs
quiescence
=
'delta'
outputs
=
outputExpert
.
allOutputs
()
#outputs = set(itertools.product('XO_', repeat=9))
outputExpert
=
OutputPurpose
()
quiescence
=
'delta'
inputExpert
=
InputPurpose
()
T1
=
TicTacToeTeacher
(
HOST
,
PORT
)
T1
=
TicTacToeTeacher
(
HOST
,
PORT
)
O1
=
TicTacToeOracle
()
O1
=
TicTacToeOracle
(
inputs
,
quiescence
)
tester
=
RandomTester
(
T1
,
100
,
10
)
#tester = RandomTester(T1, 50000, 100)
tester
=
CompleteTicTacToeTester
(
T1
)
currentdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
currentdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
inspect
.
getfile
(
inspect
.
currentframe
())))
inspect
.
getfile
(
inspect
.
currentframe
())))
...
@@ -67,7 +72,7 @@ print("Starting learning...")
...
@@ -67,7 +72,7 @@ print("Starting learning...")
#print(T1.oneOutput(('1')))
#print(T1.oneOutput(('1')))
L
=
LearningAlgorithm
(
T1
,
O1
,
printPath
=
path
,
maxLoops
=
4
,
L
=
LearningAlgorithm
(
T1
,
O1
,
printPath
=
path
,
maxLoops
=
4
,
tablePreciseness
=
10000
,
logger
=
logger
,
tester
=
tester
,
outputPurpose
=
outputExpert
,
tablePreciseness
=
10000
0
,
logger
=
logger
,
tester
=
tester
,
outputPurpose
=
outputExpert
,
inputPurpose
=
inputExpert
)
inputPurpose
=
inputExpert
)
minus
,
plus
=
L
.
run
()
minus
,
plus
=
L
.
run
()
...
...
examples/tictactoe/tictacoracle.py
View file @
ac77db53
...
@@ -31,13 +31,38 @@ import random
...
@@ -31,13 +31,38 @@ import random
# TODO for the moment we keep SUL deterministic, simple oracle.
# TODO for the moment we keep SUL deterministic, simple oracle.
class
TicTacToeOracle
(
AbstractOracle
):
class
TicTacToeOracle
(
AbstractOracle
):
def
__init__
(
self
):
def
__init__
(
self
,
inputs
,
quiescence
):
pass
self
.
_inputs
=
inputs
.
copy
()
self
.
_quiescence
=
quiescence
# Reply to an observation query
# Reply to an observation query
# trace is a list of inputs and or outputs
# trace is a list of inputs and or outputs
# outputs is the set of outputs observed so far (after trace)
# outputs is the set of outputs observed so far (after trace)
def
observation
(
self
,
trace
,
outputs
):
def
observation
(
self
,
trace
,
outputs
):
# If we already observed some outputs, then return True (determinism)
if
len
(
outputs
)
>
0
:
if
len
(
outputs
)
>
0
:
return
True
return
True
else
:
# Check trace, if it has more outputs or more imputs in a row,
# then return True
if
trace
==
():
return
False
# 0 = input, 1 = output
latest
=
1
if
trace
[
0
]
in
self
.
_inputs
:
latest
=
0
for
i
in
range
(
1
,
len
(
trace
)):
if
trace
[
i
]
==
self
.
_quiescence
:
continue
if
trace
[
i
]
in
self
.
_inputs
:
if
latest
==
0
:
return
True
else
:
latest
=
0
else
:
if
latest
==
1
:
return
True
else
:
latest
=
1
return
False
return
False
examples/tictactoe/tictacpurpose.py
View file @
ac77db53
...
@@ -28,7 +28,7 @@ sys.path.append(currentdir)
...
@@ -28,7 +28,7 @@ sys.path.append(currentdir)
from
systems.basepurpose
import
Purpose
from
systems.basepurpose
import
Purpose
import
itertools
import
itertools
class
InputPurpose
(
Purpose
):
class
TicTacToe
InputPurpose
(
Purpose
):
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
@@ -45,7 +45,7 @@ class InputPurpose(Purpose):
...
@@ -45,7 +45,7 @@ class InputPurpose(Purpose):
else
:
else
:
return
inputs
return
inputs
class
OutputPurpose
(
Purpose
):
class
TicTacToe
OutputPurpose
(
Purpose
):
def
__init__
(
self
):
def
__init__
(
self
):
pass
pass
...
@@ -61,4 +61,9 @@ class OutputPurpose(Purpose):
...
@@ -61,4 +61,9 @@ class OutputPurpose(Purpose):
if
(
outputs
!=
None
and
len
(
outputs
)
>
0
):
if
(
outputs
!=
None
and
len
(
outputs
)
>
0
):
return
outputs
return
outputs
else
:
else
:
return
set
(
itertools
.
product
(
'XO_'
,
repeat
=
9
))
# In this SUL we have many outputs (>4000)
# for this reason we use a placeholder
return
1
def
allOutputs
(
self
):
return
set
(
itertools
.
product
(
'XO_'
,
repeat
=
9
))
examples/tictactoe/tictactoe.py
View file @
ac77db53
...
@@ -422,7 +422,7 @@ if __name__ == "__main__":
...
@@ -422,7 +422,7 @@ if __name__ == "__main__":
board
=
in_line_board
()
board
=
in_line_board
()
if
winner
!=
0
:
if
winner
!=
0
:
logger
.
debug
(
"
Sending: END
"
)
logger
.
debug
(
"
We have a winner!
"
)
board
=
board
+
" END"
board
=
board
+
" END"
conn
.
sendall
(
bytes
(
board
,
'UTF-8'
))
conn
.
sendall
(
bytes
(
board
,
'UTF-8'
))
newGame
()
newGame
()
...
...
learning/learning.py
View file @
ac77db53
...
@@ -39,6 +39,8 @@ class LearningAlgorithm:
...
@@ -39,6 +39,8 @@ class LearningAlgorithm:
self
.
_inputPurpose
=
inputPurpose
self
.
_inputPurpose
=
inputPurpose
self
.
_outputPurpose
=
outputPurpose
self
.
_outputPurpose
=
outputPurpose
# If input (output) purpose is not defined, then add one that
# returns always all inputs (outputs)
if
self
.
_inputPurpose
==
None
:
if
self
.
_inputPurpose
==
None
:
self
.
_inputPurpose
=
InputPurpose
(
teacher
.
getInputAlphabet
().
copy
())
self
.
_inputPurpose
=
InputPurpose
(
teacher
.
getInputAlphabet
().
copy
())
if
self
.
_outputPurpose
==
None
:
if
self
.
_outputPurpose
==
None
:
...
...
testing/randomtesting.py
View file @
ac77db53
...
@@ -95,6 +95,8 @@ class RandomTester(AbstractTester):
...
@@ -95,6 +95,8 @@ class RandomTester(AbstractTester):
model
.
reset
()
model
.
reset
()
# return counterexample trace and output obtained by
# return counterexample trace and output obtained by
# testing
# testing
self
.
_logger
.
info
(
ce
)
self
.
_logger
.
info
(
output
)
return
ce
,
output
return
ce
,
output
# reset
# reset
self
.
_teacher
.
reset
()
self
.
_teacher
.
reset
()
...
...
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