finite-state-machines
Science Score: 39.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (9.7%) to scientific vocabulary
Repository
Basic Info
- Host: GitHub
- Owner: jaypantone
- License: mit
- Language: Python
- Default Branch: main
- Size: 61.5 KB
Statistics
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 5
Metadata Files
README.md
FiniteStateMachines
This package provides three classes for different types of finite state machines.
1. FiniteStateMachine, for classical finite state machines over an alphabet in which all letters are weighted equally;
2. WeightedFiniteStateMachine, for finite state machines over an alphabet in which each transition has a weight that is a polynomial in x;
3. CombinatorialFSM, for finite state machines with no alphabet at all, in which transitions between a pair of states are just recorded with a weight that is an expression in x and possibly other variables.
It can be installed via pip with the command pip install finite_state_machines. Questions, comments, and improvements welcome!
FiniteStateMachine
This is a Python class to perform basic operations on finite state machines, including union, intersection, and minimization.
```python
from finitestatemachines import FiniteStateMachine as FSM
M = FSM.fsmforwords_avoiding("000", alphabet=["0","1"]) M.enumeration(10) [1, 2, 4, 7, 13, 24, 44, 81, 149, 274, 504]
N = FSM.fsmforwords_avoiding("101", alphabet=["0","1"]) N.enumeration(10) [1, 2, 4, 7, 12, 21, 37, 65, 114, 200, 351]
M.intersection(N).words_generated(3) {'001', '010', '011', '100', '110', '111'}
M.intersection(N).enumeration(10) [1, 2, 4, 6, 9, 13, 19, 28, 41, 60, 88]
M.union(N).enumeration(10) [1, 2, 4, 8, 16, 32, 62, 118, 222, 414, 767] ```
WeightedFiniteStateMachine
In a weighted finite state machine, each transition is labeled with a weight that is a polynomial in x. This class has methods to generate words of a certain size ("length" is no longer the correct metric) and to count words of a given size without generating them with a dynamic programming algorithm. Functions are provided to convert back and forth between weighted and non-weighted FSMs. Intersection and union of such machines are not precisely defined and thus not implemented, and there is currently no minimization function.
```python
import sympy x = sympy.Symbol('x') from finitestatemachines import WeightedFiniteStateMachine as WFSM M = WFSM({"a", "b"}, 2, 0, {1}, {(0,"a"):(0,x),(0,"b"):(1,x),(1,"a"):(0,x2),(1,"b"):(1,x2)}) [M.words_generated(i) for i in range(5)] [set(), {'b'}, {'ab'}, {'aab', 'bb'}, {'aaab', 'abb', 'bab'}]
M.enumeration(10) [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55] ```
CombinatorialFSM
A combinatorial finite state machine (CFSM) has no alphabet. There are states (which in this implementation must be hashable), a single start state, a set of accepting states, and transitions between pairs of states that are weighted with sympy expressions that involve a main variable (x be default) and possibly other variables.
Construction of a CFSM is a bit different from the previous two classes. After creating the class, you feed it transitions and weights. The weight is added to any existing weight between these two same states.
The class comes with a minimization function and a function to write the transition matrix and solving routine to a Maple file.
```python
import sympy x, y, C = sympy.symbols('x y C') from finitestatemachines import CombinatorialFSM M = CombinatorialFSM() M.addtransition(0, 1, x*y) M.addtransition(0, 1, x2) M.add_transition(0, 2, x*y2/C) M.addtransition(0, 3, xy*2/C) M.addtransition(1, 0, x(1+y/2)) M.add_transition(2, 1, x2) M.add_transition(3, 1, x2) M.setstart(0) M.setaccepting({0, 1}) M.enumeration(5) [1, y, y2/2 + y + 1, y3/2 + y2 + y/2 + 1 + 2y2/C, y4/4 + y3 + 2*y2 + 2y + y3/C + 2y2/C, y5/4 + y4 + 3*y3/2 + 2y2 + 5y/2 + 1 + 2y4/C + 4y**3/C]
len(M.states) 4
minimized = M.minimize() len(minimized.states) 3
minimized.enumeration(5) [1, y, y2/2 + y + 1, y3/2 + y2 + y/2 + 1 + 2*y2/C, y4/4 + y3 + 2y2 + 2y + y3/C + 2*y2/C, y5/4 + y4 + 3y3/2 + 2y2 + 5y/2 + 1 + 2y4/C + 4y*3/C]
with open('CFSMexample.txt', 'w') as f: minimized.writetomaplefile(f) ```
The produced Maple file is:
start := 1:
accepting := [1, 2]:
M := Matrix(3,3, storage=sparse):
M[1,2] := -x**2 - x*y:
M[1,3] := -2*x*y**2/C:
M[2,1] := x*(-y/2 - 1):
M[3,2] := -x**2:
M[1,1] := 1 + M[1,1]:
M[2,2] := 1 + M[2,2]:
M[3,3] := 1 + M[3,3]:
V := Vector(LinearAlgebra[Dimensions](M)[1]):
for a in accepting do V[a] := 1: od:
infolevel[solve] := 5:
xvec := LinearAlgebra[LinearSolve](M, V):
f := xvec[1]:
If this code is useful to you in your work, please consider citing it.
Bibtex entry:
@misc{FiniteStateMachines,
author = {Jay Pantone},
howpublished = {\url{https://github.com/jaypantone/FiniteStateMachines}},
month = {September},
note = {DOI: \url{https://doi.org/10.5281/zenodo.4592555}},
title = {Finite{S}tate{M}achines},
year = {2021}
}
Biblatex entry:
@software{FiniteStateMachines,
author = {Jay Pantone},
date = {2021},
doi = {10.5281/zenodo.4592555},
month = {9},
title = {FiniteStateMachines},
url = {https://github.com/jaypantone/FiniteStateMachines}
}
Owner
- Login: jaypantone
- Kind: user
- Repositories: 2
- Profile: https://github.com/jaypantone
GitHub Events
Total
- Create event: 1
Last Year
- Create event: 1
Committers
Last synced: over 3 years ago
All Time
- Total Commits: 18
- Total Committers: 1
- Avg Commits per committer: 18.0
- Development Distribution Score (DDS): 0.0
Top Committers
| Name | Commits | |
|---|---|---|
| Jay Pantone | j****e@g****m | 18 |
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 0
- Total pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: 1 minute
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- jaypantone (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 23 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 8
- Total maintainers: 1
pypi.org: finite-state-machines
A library for manipulating finite state machines
- Homepage: https://github.com/jaypantone/FiniteStateMachines
- Documentation: https://finite-state-machines.readthedocs.io/
- License: MIT License
-
Latest release: 1.2.2
published over 4 years ago