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
082cdd45
Commit
082cdd45
authored
Nov 27, 2015
by
Michele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
working on nondet tic tac toe
parent
42d3bb3a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
learning/learning.py
learning/learning.py
+23
-4
learning/observationtable.py
learning/observationtable.py
+2
-1
No files found.
learning/learning.py
View file @
082cdd45
...
...
@@ -80,6 +80,7 @@ class LearningAlgorithm:
# this update uses a realistic teacher. If I need an output to happen I
# cannot force it to happen.
def
updateTable
(
self
):
#print("Updating table")
# First, try to avoid impossible traces: ask observation query
for
trace
in
self
.
_table
.
getObservableTraces
():
observedOutputs
=
self
.
_table
.
getOutputs
(
trace
)
...
...
@@ -89,17 +90,19 @@ class LearningAlgorithm:
# For all traces for which we did not observed all possible outputs
oTraces
=
self
.
_table
.
getObservableTraces
()
#print("observable traces: "+ str(len(oTraces)))
trie
=
th
.
make_trie
(
oTraces
)
#
trie = th.make_trie(oTraces)
# Until we tried K times with no results, where K is the number of
# observable traces times the number of outputs (including quiescence)
K
=
len
(
oTraces
)
*
3
5
# (len(self._teacher.getOutputAlphabet()) + 1) # TODO comment from *
K
=
len
(
oTraces
)
*
3
0
# (len(self._teacher.getOutputAlphabet()) + 1) # TODO comment from *
found
=
0
tries
=
0
while
tries
<
K
:
tries
+=
1
oTraces
=
self
.
_table
.
getObservableTraces
()
#print("observable traces: "+ str(len(oTraces)))
trie
=
th
.
make_trie
(
oTraces
)
subtrie
=
trie
...
...
@@ -116,8 +119,14 @@ class LearningAlgorithm:
# 1 - observe an output that makes the trace not a prefix
# 2 - there is no continuation of that trace in prefixes
# We stop when we observed at least an output for each observable
count
=
0
while
len
(
oTraces
)
>
len
(
observations
.
keys
()):
# TODO: I gave a limit to this inner loop.
# reason on this and find a good estimation for count.
# also, this is NOT GOOD for deterministic systems. It is easier to learn them without this check
count
+=
1
#if count > (len(oTraces) * 2):
# break
# check if trie contains no traces (but still has a child)
children
=
trie
.
keys
()
hasTrace
=
False
...
...
@@ -248,6 +257,7 @@ class LearningAlgorithm:
observation
=
self
.
_oracle
.
observation
(
trace
,
observedOutputs
)
if
observation
:
self
.
_table
.
updateEntry
(
trace
,
observation
=
observation
)
#print("Table updated")
def
_processInputs
(
self
,
consecutiveInputs
):
if
consecutiveInputs
!=
():
...
...
@@ -261,6 +271,7 @@ class LearningAlgorithm:
def
stabilizeTable
(
self
):
#print("Stabilizing table")
# While nothing changes, keep closing and making the table consistent
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
...
...
@@ -270,6 +281,7 @@ class LearningAlgorithm:
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
while
closingRows
:
#print("Closing table")
self
.
_logger
.
debug
(
"Table is not closed"
)
self
.
_logger
.
debug
(
closingRows
)
self
.
_table
.
promote
(
closingRows
)
...
...
@@ -283,10 +295,13 @@ class LearningAlgorithm:
if
not
closingRows
:
if
self
.
_makeConsistent
():
#print("Consistencing table")
self
.
updateTable
()
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
#print("Done stabilizing")
def
_makeConsistent
(
self
):
#print("Checking consistency")
consistentCheck
=
self
.
_table
.
isNotGloballyConsistent
()
# Table is closed, check for consistency
if
consistentCheck
:
...
...
@@ -423,10 +438,13 @@ class LearningAlgorithm:
self
.
_currentLoop
=
self
.
_currentLoop
+
1
self
.
_logger
.
info
(
"Learning loop number "
+
str
(
self
.
_currentLoop
))
# Fill the table and make it closed and consistent
#print("Pre update in run")
self
.
updateTable
()
#print("Pre stabilize in run")
self
.
stabilizeTable
()
# Is the table quiescence reducible? If not make it so and
# then fill it again, make it closed and consitent
#print("Pre quiescence check in run")
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
while
(
newSuffixes
or
not
self
.
_table
.
isStable
()):
if
newSuffixes
:
...
...
@@ -436,6 +454,7 @@ class LearningAlgorithm:
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_Q_"
)
self
.
updateTable
()
#print("Pre stabilize in loop in run")
self
.
stabilizeTable
()
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
self
.
_hMinus
=
self
.
getHypothesis
()
...
...
learning/observationtable.py
View file @
082cdd45
...
...
@@ -441,8 +441,9 @@ class Table:
#row2 is in the equivalence class defined by row1
# get all possible (enabled) labels of row1
inputs
=
self
.
_possibleInputs
(
row1
)
outputs
=
self
.
getOutputs
(
row1
)
inputs
=
self
.
_possibleInputs
(
row1
,
outputs
)
labels
=
inputs
.
union
(
outputs
)
for
label
in
labels
:
...
...
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