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
c30fa82c
Commit
c30fa82c
authored
Nov 13, 2015
by
Michele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed input enabledness assumption of modelin RandomTester
parent
d2eb3621
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
55 deletions
+30
-55
examples/tictactoe/learn.py
examples/tictactoe/learn.py
+2
-1
examples/tictactoe/tictacteacher.py
examples/tictactoe/tictacteacher.py
+0
-26
examples/tictactoe/tictactoe.py
examples/tictactoe/tictactoe.py
+1
-1
learning/learning.py
learning/learning.py
+6
-11
teachers/baseteacher.py
teachers/baseteacher.py
+5
-4
testing/randomtesting.py
testing/randomtesting.py
+8
-4
tests/read_table_test.py
tests/read_table_test.py
+8
-8
No files found.
examples/tictactoe/learn.py
View file @
c30fa82c
...
...
@@ -37,6 +37,7 @@ from tictacoracle import TicTacToeOracle
from
tictacpurpose
import
InputPurpose
,
OutputPurpose
from
learning.learning
import
LearningAlgorithm
from
testing.randomtesting
import
RandomTester
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -54,7 +55,7 @@ inputExpert = InputPurpose()
T1
=
TicTacToeTeacher
(
HOST
,
PORT
)
O1
=
TicTacToeOracle
()
tester
=
None
tester
=
RandomTester
(
T1
,
100
,
10
)
currentdir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
inspect
.
getfile
(
inspect
.
currentframe
())))
...
...
examples/tictactoe/tictacteacher.py
View file @
c30fa82c
...
...
@@ -57,30 +57,6 @@ class TicTacToeTeacher(AbstractTeacher):
logger
=
logging
.
getLogger
(
__name__
)
# Reply to a membership/output query
# trace is a list of inputs and or outputs
@
d
.
deprecated
def
process
(
self
,
trace
):
pass
# reset SUL
# reset = self.reset()
# if not reset:
# logger.error("Cannot reset.")
# return False
#
# output = None
# if len(trace) == 0:
# # Get output for the empty trace
# ready = select.select([self._socket], [], [], 1) # 1 second timeout, for quiescence
# output = 'delta'
# if ready[0]:
# output = self._socket.recv(1024).decode("utf-8")
# for action in trace:
# # TODO finish here, maybe not needed
# print(ddd)
# return None
# return output
# Provide a sequence of inputs (possibly one or even zero) end get an output
# Tic Tac Toe is a mealy machine like game, there is alternation of input and
# output. This must be defined in inputExpert
...
...
@@ -89,8 +65,6 @@ class TicTacToeTeacher(AbstractTeacher):
self
.
_socket
.
sendall
(
bytes
(
str
(
actions
[
i
]),
'UTF-8'
))
output
=
self
.
output
()
print
(
actions
)
print
(
output
)
return
output
# Provide output from current state
...
...
examples/tictactoe/tictactoe.py
View file @
c30fa82c
...
...
@@ -366,7 +366,7 @@ if __name__ == "__main__":
HOST
=
'localhost'
PORT
=
29000
# Arbitrary non-privileged port
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logger
=
logging
.
getLogger
(
__name__
)
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
...
...
learning/learning.py
View file @
c30fa82c
...
...
@@ -301,13 +301,12 @@ class LearningAlgorithm:
consistentCheck
=
self
.
_table
.
isNotGloballyConsistent
()
while
closingRows
or
consistentCheck
:
while
closingRows
:
self
.
_logger
.
info
(
"
Closing table
"
)
self
.
_logger
.
info
(
"
Table is not closed
"
)
self
.
_logger
.
debug
(
closingRows
)
self
.
_table
.
promote
(
closingRows
)
# After promoting one should check if some one letter
# extensions should also be added
if
self
.
_table
.
addOneLetterExtensions
(
closingRows
):
self
.
_logger
.
info
(
"something changed"
)
self
.
_table
.
addOneLetterExtensions
(
closingRows
)
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_c_"
)
self
.
updateTable
()
...
...
@@ -315,10 +314,9 @@ class LearningAlgorithm:
consistentCheck
=
self
.
_table
.
isNotGloballyConsistent
()
# Table is closed, check for consistency
if
consistentCheck
:
self
.
_logger
.
info
(
"
Consistency check
"
)
self
.
_logger
.
info
(
"
Table is not consistent
"
)
self
.
_logger
.
debug
(
consistentCheck
)
if
self
.
_table
.
addColumn
(
consistentCheck
,
force
=
True
):
self
.
_logger
.
info
(
"something changed"
)
self
.
_table
.
addColumn
(
consistentCheck
,
force
=
True
)
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_i_"
)
# TODO: is an update needed here? in theory, when I encounter
...
...
@@ -452,14 +450,11 @@ class LearningAlgorithm:
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
while
(
newSuffixes
or
not
self
.
_table
.
isStable
()):
if
newSuffixes
:
self
.
_logger
.
info
(
"
Q
uiescence reducible"
)
self
.
_logger
.
info
(
"
Table is not q
uiescence reducible"
)
self
.
_logger
.
debug
(
newSuffixes
)
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_Q_"
)
if
self
.
_table
.
addColumn
(
newSuffixes
,
force
=
True
):
self
.
_logger
.
info
(
"somethig changed"
)
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_Q
after
_"
)
self
.
_table
.
printTable
(
prefix
=
"_Q_"
)
self
.
updateTable
()
self
.
stabilizeTable
()
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
...
...
teachers/baseteacher.py
View file @
c30fa82c
...
...
@@ -23,10 +23,11 @@ from abc import ABCMeta, abstractmethod
class
AbstractTeacher
(
metaclass
=
ABCMeta
):
# Reply to a membership/output query
@
abstractmethod
def
process
(
self
,
trace
):
pass
# Deprecated
# # Reply to a membership/output query
# @abstractmethod
# def process(self, trace):
# pass
# Provide a sequence of inputs (possibly one or even zero) end get an output
@
abstractmethod
...
...
testing/randomtesting.py
View file @
c30fa82c
...
...
@@ -50,15 +50,19 @@ class RandomTester(AbstractTester):
if
reset
!=
0
:
# do not Reset
typeAction
=
random
.
sample
(
set
([
'input'
,
'output'
]),
1
)[
0
]
# there might be no inputs, but we assume the model is
# non-blocking, thus there is always an output (or quiescence)
if
len
(
model
.
inputs
())
==
0
:
typeAction
=
'output'
if
typeAction
==
'input'
:
# provide an input
# do not assume input enabledness
input
=
random
.
sample
(
model
.
inputs
(),
1
)[
0
]
ce
=
ce
+
(
input
,)
model
.
move
(
input
)
# should be deterministic
my_
input
=
random
.
sample
(
model
.
inputs
(),
1
)[
0
]
ce
=
ce
+
(
my_
input
,)
model
.
move
(
my_
input
)
# should be deterministic
# add input to consecutiveInputs
consecutiveInputs
=
consecutiveInputs
+
(
input
,)
consecutiveInputs
=
consecutiveInputs
+
(
my_
input
,)
# and continue with next step
# providing input costs an action
i
+=
1
...
...
tests/read_table_test.py
View file @
c30fa82c
...
...
@@ -79,14 +79,14 @@ class TestTableReader:
outputPurpose
=
outputExpert
,
inputPurpose
=
inputExpert
)
table
.
_loadTable
(
path
)
#
table._loadTable(path)
path
=
os
.
path
.
join
(
parentdir
,
"learning"
)
table
.
printTable
(
path
=
path
,
prefix
=
'TEST'
)
#
path = os.path.join(parentdir, "learning")
#
table.printTable(path=path, prefix='TEST')
moreSpecific
=
lambda
x
:
lambda
y
:
table
.
_moreSpecificRow
(
y
,
x
,
False
)
listOfRows
=
list
(
filter
(
moreSpecific
((
'a'
,
'x'
,
'y'
,
'a'
,
'delta'
)
+
(
'a'
,)),
table
.
_rowsInS
))
#
moreSpecific = lambda x: lambda y: table._moreSpecificRow(y, x, False)
#
listOfRows = list(filter(moreSpecific(('a', 'x', 'y', 'a', 'delta') + ('a',)), table._rowsInS))
print
(
listOfRows
)
print
(
table
.
isNotGloballyClosed
())
assert_equal
(
listOfRows
==
[],
False
)
#
print(listOfRows)
#
print(table.isNotGloballyClosed())
#
assert_equal(listOfRows == [], False)
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