Package: dfa_identify
dfa-identifyPython library for identifying (learning) minimal DFAs from labeled examples
by reduction to SAT.Table of ContentsInstallationUsageEncodingGoals and related librariesInstallationIf you just need to usedfa, you can just run:$ pip install dfaFor developers, note that this project uses thepoetrypython package/dependency
management tool. Please familarize yourself with it and then
run:$ poetry installUsagedfa_identifyis centered around thefind_dfaandfind_dfasfunction. Both take in
sequences of accepting and rejecting "words", where are word is a
sequence of arbitrary python objects.find_dfasreturns all minimally sized (noDFAs exist of size
smaller) consistent with the given labeled data.find_dfareturns an arbitrary (first) minimally sizedDFA.The returnedDFAobject is from thedfalibrary.fromdfa_identifyimportfind_dfaaccepting=['a','abaa','bb']rejecting=['abb','b']my_dfa=find_dfa(accepting=accepting,rejecting=rejecting)assertall(my_dfa.label(x)forxinaccepting)assertall(notmy_dfa.label(x)forxinrejecting)Because words are sequences of arbitrary python objects, the
identification problem, witha↦ 0 andb↦ 1, is given below:accepting=[[0],[0,'z',0,0],['z','z']]rejecting=[[0,'z','z'],['z']]my_dfa=find_dfa(accepting=accepting,rejecting=rejecting)Active learningThere are also active variants offind_dfaandfind_dfascalledfind_dfa_activeandfind_dfas_activeresp.An example from the unit tests:importdfafromdfa_identifyimportfind_dfa_activedeforacle(word):returnsum(word)%2==0lang=find_dfa_active(alphabet=[0,1],oracle=oracle,n_queries=20)assertlang==dfa.DFA(inputs=[0,1],label=lambdas:s,transition=lambdas,c:s^bool(c),start=True)# Can also send in positive and negative examples:lang=find_dfa_active(alphabet=[0,1],positive=[(0,),(0,0)],negative=[(1,),(1,0)],oracle=oracle,n_queries=20)MinimalityThere are two forms of "minimality" supported bydfa-identify.By default, dfa-identify returns DFAs that have the minimum
number of states required to seperate the accepting and
rejecting set.If theorder_by_stutterflag is set toTrue, then thefind_dfas(lazily) orders the DFAs so that the number of
self loops (stuttering transitions) appearing the DFAs decreases.find_dfathus returns a DFA with the most number of self loops
given the minimal number of states.EncodingThis library currently uses the encodings outlined inHeule, Marijn JH, and Sicco Verwer. "Exact DFA identification using SAT solvers." International Colloquium on Grammatical Inference. Springer, Berlin, Heidelberg, 2010.andUlyantsev, Vladimir, Ilya Zakirzyanov, and Anatoly Shalyto. "Symmetry Breaking Predicates for SAT-based DFA Identification.".The key difference is in the use of the symmetry breaking clauses. Two kinds are exposed.clique (Heule 2010): Partially breaks symmetries by analyzing
conflict graph.bfs (Ulyantsev 2016): Breaks all symmetries so that each model corresponds to a unique DFA.Goals and related librariesThere are many other python libraries that
perform DFA and other automata inference.DFA-Inductor-py- State of the art passive inference via reduction to SAT (as of 2019).z3gi: Uses SMT backed passive learning algorithm.lstar: Active learning algorithm based L* derivative.The primary goal of this library is to loosely track the state of the art in passive SAT based inference while providing a simple implementation and API.