-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_usage.py
More file actions
49 lines (40 loc) · 1.15 KB
/
Copy pathbasic_usage.py
File metadata and controls
49 lines (40 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Basic usage example for the pdfa-learning package.
This script demonstrates how to construct a prefix tree acceptor from
observed sequences, learn a deterministic finite automaton
using ALERGIA, and convert the learned transition-count matrix into a
probability transition matrix.
"""
import pdfa_learning as pl
sequences = [
"0", "0", "0", "0", "0", "0", "0", "0",
"01", "01", "01", "01", "01", "01", "01",
"10", "10", "10", "10", "10",
"11", "11", "11", "11", "11",
"12", "12",
"1", "1", "1"
]
alphabet = pl.get_alphabet(sequences)
states = pl.get_initial_states(sequences)
pathway_matrix = pl.get_transition_matrix(
sequences,
alphabet,
)
learned_matrix, learned_states, tracking = pl.alergia(
pathway_matrix,
states,
alphabet,
alpha=0.2,
method="carrasco",
)
probability_matrix = pl.probability_transition_matrix(
learned_matrix,
learned_states,
alphabet,
)
print("Alphabet:", alphabet)
print("Initial states:", states)
print("Learned states:", learned_states)
print("Tracking:", tracking)
print("Probability matrix shape:", probability_matrix.shape)
print("PDFA:", probability_matrix)