Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rick Smetsers
z3gi
Commits
15cd6f47
Commit
15cd6f47
authored
Jul 04, 2017
by
Paul Fiterau Brostean
Browse files
The learning algorithm that should have been added previously.
parent
311098de
Changes
1
Hide whitespace changes
Inline
Side-by-side
z3gi/learn/algorithm.py
0 → 100644
View file @
15cd6f47
from
typing
import
List
,
Tuple
from
typing
import
cast
from
model
import
Automaton
from
learn
import
Learner
from
test
import
TestTemplate
class
Statistics
():
def
__init__
(
self
):
self
.
num_tests
=
0
self
.
num_inputs
=
0
self
.
suite_size
=
0
def
add_inputs
(
self
,
num
):
self
.
num_inputs
+=
num
def
add_tests
(
self
,
num
):
self
.
num_tests
+=
num
def
set_suite_size
(
self
,
num
):
self
.
suite_size
=
num
def
__str__
(
self
):
return
"Total number tests used in learning: {0}
\n
"
\
"Total number inputs used in learning: {1}
\n
"
\
"Test suite size: {2}"
.
format
(
self
.
num_tests
,
self
.
num_inputs
,
self
.
suite_size
)
def
learn
(
learner
:
Learner
,
test_type
:
type
,
traces
:
List
[
object
])
->
Tuple
[
Automaton
,
Statistics
]:
statistics
=
Statistics
()
if
len
(
traces
)
==
0
:
return
(
None
,
statistics
)
else
:
statistics
.
set_suite_size
(
len
(
traces
))
test
=
cast
(
TestTemplate
,
test_type
(
traces
.
pop
(
0
)))
definition
=
None
learner
.
add
(
test
.
trace
)
statistics
.
add_tests
(
1
)
statistics
.
add_inputs
(
test
.
size
())
done
=
False
model
=
None
while
not
done
:
(
model
,
definition
)
=
learner
.
model
(
old_definition
=
definition
)
done
=
True
for
trace
in
traces
:
test
=
cast
(
TestTemplate
,
test_type
(
trace
))
ce
=
test
.
check
(
model
)
if
ce
is
not
None
:
learner
.
add
(
ce
)
statistics
.
add_tests
(
1
)
statistics
.
add_inputs
(
test
.
size
())
done
=
False
break
return
(
model
,
statistics
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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