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
Hide 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:
...
@@ -80,6 +80,7 @@ class LearningAlgorithm:
# this update uses a realistic teacher. If I need an output to happen I
# this update uses a realistic teacher. If I need an output to happen I
# cannot force it to happen.
# cannot force it to happen.
def
updateTable
(
self
):
def
updateTable
(
self
):
#print("Updating table")
# First, try to avoid impossible traces: ask observation query
# First, try to avoid impossible traces: ask observation query
for
trace
in
self
.
_table
.
getObservableTraces
():
for
trace
in
self
.
_table
.
getObservableTraces
():
observedOutputs
=
self
.
_table
.
getOutputs
(
trace
)
observedOutputs
=
self
.
_table
.
getOutputs
(
trace
)
...
@@ -89,17 +90,19 @@ class LearningAlgorithm:
...
@@ -89,17 +90,19 @@ class LearningAlgorithm:
# For all traces for which we did not observed all possible outputs
# For all traces for which we did not observed all possible outputs
oTraces
=
self
.
_table
.
getObservableTraces
()
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
# Until we tried K times with no results, where K is the number of
# observable traces times the number of outputs (including quiescence)
# 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
found
=
0
tries
=
0
tries
=
0
while
tries
<
K
:
while
tries
<
K
:
tries
+=
1
tries
+=
1
oTraces
=
self
.
_table
.
getObservableTraces
()
oTraces
=
self
.
_table
.
getObservableTraces
()
#print("observable traces: "+ str(len(oTraces)))
trie
=
th
.
make_trie
(
oTraces
)
trie
=
th
.
make_trie
(
oTraces
)
subtrie
=
trie
subtrie
=
trie
...
@@ -116,8 +119,14 @@ class LearningAlgorithm:
...
@@ -116,8 +119,14 @@ class LearningAlgorithm:
# 1 - observe an output that makes the trace not a prefix
# 1 - observe an output that makes the trace not a prefix
# 2 - there is no continuation of that trace in prefixes
# 2 - there is no continuation of that trace in prefixes
# We stop when we observed at least an output for each observable
# We stop when we observed at least an output for each observable
count
=
0
while
len
(
oTraces
)
>
len
(
observations
.
keys
()):
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)
# check if trie contains no traces (but still has a child)
children
=
trie
.
keys
()
children
=
trie
.
keys
()
hasTrace
=
False
hasTrace
=
False
...
@@ -248,6 +257,7 @@ class LearningAlgorithm:
...
@@ -248,6 +257,7 @@ class LearningAlgorithm:
observation
=
self
.
_oracle
.
observation
(
trace
,
observedOutputs
)
observation
=
self
.
_oracle
.
observation
(
trace
,
observedOutputs
)
if
observation
:
if
observation
:
self
.
_table
.
updateEntry
(
trace
,
observation
=
observation
)
self
.
_table
.
updateEntry
(
trace
,
observation
=
observation
)
#print("Table updated")
def
_processInputs
(
self
,
consecutiveInputs
):
def
_processInputs
(
self
,
consecutiveInputs
):
if
consecutiveInputs
!=
():
if
consecutiveInputs
!=
():
...
@@ -261,6 +271,7 @@ class LearningAlgorithm:
...
@@ -261,6 +271,7 @@ class LearningAlgorithm:
def
stabilizeTable
(
self
):
def
stabilizeTable
(
self
):
#print("Stabilizing table")
# While nothing changes, keep closing and making the table consistent
# While nothing changes, keep closing and making the table consistent
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
...
@@ -270,6 +281,7 @@ class LearningAlgorithm:
...
@@ -270,6 +281,7 @@ class LearningAlgorithm:
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
while
closingRows
:
while
closingRows
:
#print("Closing table")
self
.
_logger
.
debug
(
"Table is not closed"
)
self
.
_logger
.
debug
(
"Table is not closed"
)
self
.
_logger
.
debug
(
closingRows
)
self
.
_logger
.
debug
(
closingRows
)
self
.
_table
.
promote
(
closingRows
)
self
.
_table
.
promote
(
closingRows
)
...
@@ -283,10 +295,13 @@ class LearningAlgorithm:
...
@@ -283,10 +295,13 @@ class LearningAlgorithm:
if
not
closingRows
:
if
not
closingRows
:
if
self
.
_makeConsistent
():
if
self
.
_makeConsistent
():
#print("Consistencing table")
self
.
updateTable
()
self
.
updateTable
()
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
closingRows
=
self
.
_table
.
isNotGloballyClosed
()
#print("Done stabilizing")
def
_makeConsistent
(
self
):
def
_makeConsistent
(
self
):
#print("Checking consistency")
consistentCheck
=
self
.
_table
.
isNotGloballyConsistent
()
consistentCheck
=
self
.
_table
.
isNotGloballyConsistent
()
# Table is closed, check for consistency
# Table is closed, check for consistency
if
consistentCheck
:
if
consistentCheck
:
...
@@ -361,7 +376,7 @@ class LearningAlgorithm:
...
@@ -361,7 +376,7 @@ class LearningAlgorithm:
if
label
in
self
.
_teacher
.
getInputAlphabet
():
if
label
in
self
.
_teacher
.
getInputAlphabet
():
hyp
.
addTransition
(
assignments
[
row
],
label
,
hyp
.
addTransition
(
assignments
[
row
],
label
,
hyp
.
getChaosDelta
())
hyp
.
getChaosDelta
())
elif
label
in
self
.
_table
.
getPossibleOutputs
(
row
):
elif
label
in
self
.
_table
.
getPossibleOutputs
(
row
):
hyp
.
addTransition
(
assignments
[
row
],
label
,
hyp
.
addTransition
(
assignments
[
row
],
label
,
hyp
.
getChaos
())
hyp
.
getChaos
())
...
@@ -423,10 +438,13 @@ class LearningAlgorithm:
...
@@ -423,10 +438,13 @@ class LearningAlgorithm:
self
.
_currentLoop
=
self
.
_currentLoop
+
1
self
.
_currentLoop
=
self
.
_currentLoop
+
1
self
.
_logger
.
info
(
"Learning loop number "
+
str
(
self
.
_currentLoop
))
self
.
_logger
.
info
(
"Learning loop number "
+
str
(
self
.
_currentLoop
))
# Fill the table and make it closed and consistent
# Fill the table and make it closed and consistent
#print("Pre update in run")
self
.
updateTable
()
self
.
updateTable
()
#print("Pre stabilize in run")
self
.
stabilizeTable
()
self
.
stabilizeTable
()
# Is the table quiescence reducible? If not make it so and
# Is the table quiescence reducible? If not make it so and
# then fill it again, make it closed and consitent
# then fill it again, make it closed and consitent
#print("Pre quiescence check in run")
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
while
(
newSuffixes
or
not
self
.
_table
.
isStable
()):
while
(
newSuffixes
or
not
self
.
_table
.
isStable
()):
if
newSuffixes
:
if
newSuffixes
:
...
@@ -436,6 +454,7 @@ class LearningAlgorithm:
...
@@ -436,6 +454,7 @@ class LearningAlgorithm:
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
if
self
.
_logger
.
isEnabledFor
(
logging
.
DEBUG
):
self
.
_table
.
printTable
(
prefix
=
"_Q_"
)
self
.
_table
.
printTable
(
prefix
=
"_Q_"
)
self
.
updateTable
()
self
.
updateTable
()
#print("Pre stabilize in loop in run")
self
.
stabilizeTable
()
self
.
stabilizeTable
()
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
newSuffixes
=
self
.
_table
.
isNotQuiescenceReducible
()
self
.
_hMinus
=
self
.
getHypothesis
()
self
.
_hMinus
=
self
.
getHypothesis
()
...
...
learning/observationtable.py
View file @
082cdd45
...
@@ -441,8 +441,9 @@ class Table:
...
@@ -441,8 +441,9 @@ class Table:
#row2 is in the equivalence class defined by row1
#row2 is in the equivalence class defined by row1
# get all possible (enabled) labels of row1
# get all possible (enabled) labels of row1
inputs
=
self
.
_possibleInputs
(
row1
)
outputs
=
self
.
getOutputs
(
row1
)
outputs
=
self
.
getOutputs
(
row1
)
inputs
=
self
.
_possibleInputs
(
row1
,
outputs
)
labels
=
inputs
.
union
(
outputs
)
labels
=
inputs
.
union
(
outputs
)
for
label
in
labels
:
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