lstar

Python implementation of lstar automata learning algorithm.

https://github.com/mvcisback/lstar

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.5%) to scientific vocabulary

Keywords

active-learning automata learning python
Last synced: 6 months ago · JSON representation ·

Repository

Python implementation of lstar automata learning algorithm.

Basic Info
  • Host: GitHub
  • Owner: mvcisback
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 93.8 KB
Statistics
  • Stars: 9
  • Watchers: 1
  • Forks: 1
  • Open Issues: 0
  • Releases: 0
Topics
active-learning automata learning python
Created almost 7 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

L*

Build Status codecov PyPI version License: MIT

Implementation of the discriminant tree L* algorithm DFA learning algorithm provided in [^1].

Table of Contents

Installation

If you just need to use lstar, you can just run:

$ pip install lstar

For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:

$ poetry install

Usage

The main entry point for using this library is the learn_dfa function.

python from lstar import learn_dfa

This function requires the arguments: ```python dfa = learn_dfa( inputs= .. , # Inputs over which the target concept is over. # Note: Sequence of Hashables.

label=..,  #  Function answering whether a given word is in the target
                #  language.
                #
                #  Tuple[Alphabet] -> bool

find_counter_example=..,  #  Function which takes a hypothesis DFA
                          #  and either returns None or a counter example,
                          #  i.e., an element misclassified by hypothesis
                          #  DFA.
                          #
                          #  DFA -> Union[Tuple[Alphabet], None]

) ```

Below is an example of learning following language over {0, 1}:

The number of 1's in the word is a multiple of 4.

Label Queries

We start by defining the label query function.

Note that this implementation of lstar assumes that this function is either cheap (O(1)-ish) to call or is memoized.

```python from functools import lru_cache

@lrucache(maxsize=None) # Memoize member queries def ismult_4(word): """Want to learn 4 state counter""" return (sum(word) % 4) == 0 ```

Equivalence Queries

Next you need to define a function which given a candidate DFA returns either a counter example that this DFA mislabels or None.

Note that the DFA type used comes from the dfa package (link).

lstar provides two functions to make writing counterexample oracles easier.

  1. validate_ce: Takes a counterexample oracle and retries if returned "counterexample" is not actually a counterexample. Useful if using heuristic solver or asking a human.

    ```python from lstar import validate_ce

    @validatece(ismult4, retry=True) def askhuman(dfa): ... ```

  2. iterative_deeping_ce: This function performs an iterative deepening traversal of the candidate dfa and see's if it matches the labeler on all tested words.

```python from lstar import iterativedeepingce

findce = iterativedeepingce(ismult_4, depth=10) ```

All together

```python dfa = learndfa( inputs={0, 1}, # Possible inputs. label=ismult4, # Does this sequence belong in the language. findcounterexample=iterativedeepingce(ismult_4, depth=10) )

assert not dfa.label(()) assert not dfa.label((1,)) assert not dfa.label((1, 1, )) assert dfa.label((1, 1, 1)) assert dfa.label((1, 1, 0, 1)) ```

Learning Moore Machines and DFA-labelers

By default, learn_dfa learns as Deterministic Finite Acceptor; however, by specifying the outputs parameter and adjusting the label function, one can learn a Deterministic Finite Labeler (which is isomorphic to a Moore Machine).

For example, the 4 state counter from before can be modified to output the current count rather than whether or not the word sums to a multiple of 4.

```python def summod4(state): return sum(state) % 4

dfl = learndfa( inputs={0, 1}, label=summod4, findcounterexample=askhuman, outputs={0, 1, 2, 3}, ) # Returns a Deterministic Finite Labeler.

assert dfl.label(()) == 0 assert dfl.label((1,)) == 1 assert dfl.label((1, 1, )) == 2 assert dfl.label((1, 1, 1)) == 3 assert dfl.label((1, 1, 0, 1)) == 3 assert dfl.label((1, 1, 1, 1)) == 0 ```

The deterministic labeler can be interpreted as a moore machine by using the transduce method rather than label.

python assert dfl.transduce(()) == () assert dfl.transduce((1,)) == (0,) assert dfl.transduce((1, 1, )) == (0, 1) assert dfl.transduce((1, 1, 1)) == (0, 1, 2) assert dfl.transduce((1, 1, 0, 1)) == (0, 1, 2, 2) assert dfl.transduce((1, 1, 1, 1, 1)) == (0, 1, 2, 3, 0)

Testing

This project uses pytest. Simply run

$ poetry run pytest

in the root of the repository.

Similar Libraries

Python Based

1. https://github.com/steynvl/inferrer : DFA learning
   library supporting active and passive dfa learning. Active
   learning is based on L* with an observation table. Also
   supports learning NFAs.
  1. https://gitlab.lis-lab.fr/dev/scikit-splearn/ : Library for learning weighted automata via the spectral method.

  2. https://pypi.org/project/pylstar/ : Another L* based DFA learning library.

Java Based

  1. https://learnlib.de/ : State of the art automata learning toolbox. Supports passive and active learning algorithms for DFAs, Mealy Machines, and Visibly Push Down Automata.
  2. https://github.com/lorisdanto/symbolicautomata : Library for symbolic automata and symbolic visibly pushdown automata.

Footnotes

[^1]: Kearns, Michael J., Umesh Virkumar Vazirani, and Umesh Vazirani. An introduction to computational learning theory. MIT press, 1994.

Owner

  • Name: Marcell Vazquez-Chanlatte
  • Login: mvcisback
  • Kind: user

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Vazquez-Chanlatte"
  given-names: "Marcell"
  orcid: "https://orcid.org/0000-0002-1248-0000"
title: "lstar"
version: 1
date-released: 2021-08-02
url: "https://github.com/mvcisback/lstar"

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Dependencies

poetry.lock pypi
  • coverage 6.3.2 develop
  • flake8 4.0.1 develop
  • hypothesis 6.43.1 develop
  • mccabe 0.6.1 develop
  • pycodestyle 2.8.0 develop
  • pyflakes 2.4.0 develop
  • pytest-cov 3.0.0 develop
  • pytest-flake8 1.1.0 develop
  • pytest-sugar 0.9.4 develop
  • sortedcontainers 2.4.0 develop
  • termcolor 1.1.0 develop
  • tomli 2.0.1 develop
  • atomicwrites 1.4.0
  • attrs 21.4.0
  • bidict 0.21.4
  • bitarray 2.4.1
  • colorama 0.4.4
  • dfa 4.4.0
  • execnet 1.9.0
  • funcy 1.17
  • iniconfig 1.1.1
  • lazytree 0.3.3
  • packaging 21.3
  • pluggy 1.0.0
  • py 1.11.0
  • pyparsing 3.0.8
  • pytest 6.2.5
  • pytest-forked 1.4.0
  • pytest-xdist 2.5.0
  • toml 0.10.2
pyproject.toml pypi
  • hypothesis ^6 develop
  • pytest ^6.0.0 develop
  • pytest-cov ^3 develop
  • pytest-flake8 ^1 develop
  • pytest-sugar ^0.9.2 develop
  • pytest-xdist ^2.0.0 develop
  • attrs ^21.0.0
  • dfa ^4
  • funcy ^1.12
  • lazytree ^0.3.2
  • python ^3.9