Package: probabilistic-automata
Probabilistic AutomataPython library for manipulating Probabilistic Automata. This library
builds upon thedfapackage.Table of ContentsProbabilistic AutomataInstallationUsageDict <-> PDFADFA to PDFACompositionInstallationIf you just need to useprobabilistic_automata, you can just run:$ pip install probabilistic_automataFor developers, note that this project uses thepoetrypython package/dependency
management tool. Please familarize yourself with it and then
run:$ poetry installUsageTheprobabilistic_automatalibrary centers around thePDFAobject
which models a finite probabilistic transition system, e.g., a Markov
Decision Process, as aDFAor Moore Machine over a product alphabet
over the system's actions and the environment's stochastic action.importprobabilistic_automataasPAdeftransition(state,composite_action):sys_action,env_action=composite_actionreturn(state+sys_action+env_action)%2defenv_dist(state,sys_action):"""Based on state and the system action, what are the probabilitiesof the environment's action."""return{0:1/2,1:1/2}# Always a coin flip.noisy_parity=PA.pdfa(start=0,label=bool,inputs={0,1},env_inputs={0,1},outputs={0,1},transition=transition,env_dist=env_dist,# Equivalently, PA.uniform({0, 1}).)The support and transition probabilities can easily calculated:assertnoisy_parity.support(0,0)=={0,1}assertnoisy_parity.transition_probs(0,0)=={0:1/2,1:1/2}assertnoisy_parity.prob(start=0,action=0,end=0)==1/2Dict <-> PDFANote thatpdfaprovides helper functions for going from a dictionary
based representation of a probabilistic transition system to aPDFAobject and back.importprobabilistic_automataasPAmapping={"s1":(True,{'a':{'s1':0.5,'s2':0.5},}),"s2":(False,{'a':{'s1':1},}),}start="s1"pdfa=PA.dict2pdfa(mapping=mapping,start=start)assertpdfa.inputs=={'a'}mapping2,start2=PA.pdfa2dict(pdfa)assertstart==start2assertmapping2==mappingDFA to PDFATheprobabilistic_automatalibrary has two convenience methods for
transforming a Deterministic Finite Automaton (dfa.DFA) into aPDFA.Theliftfunction simply creates aPDFAwhose transitions are
deterministic and match the originaldfa.DFA.importprobabilistic_automataasPAfromdfaimportDFAparity=DFA(start=0,inputs={0,1},label=bool,transition=lambdas,c:(s+c)&1,)parity_pdfa=lift(parity)assertpdfa.inputs==parity.inputsassertpdfa.env_inputs=={None}Therandomizefunction takes aDFAand returns aPDFAmodeling
the actions of theDFAbeing selected uniformly at random.noisy_parity = PA.randomize(parity)

assert noisy_parity.inputs == {None}
assert noisy_parity.env_inputs == noisy_parity.inputsCompositionLike their deterministic variantsPDFAobjects can be combined in
two ways:(Synchronous) Cascading Composition: Feed outputs of onePDFAinto another.machine=noisy_parity>>noisy_parityassertmachine.inputs==noisy_parity.inputsassertmachine.outputs==noisy_parity.outputsassertmachine.start==(0,0)assertmachine.support((0,0),0)=={(0,0),(0,1),(1,0),(1,1)}(Synchronous) Parallel Composition: Run twoPDFAs in parallel.machine=noisy_parity|noisy_parityassertmachine.inputs.left==noisy_parity.inputsassertmachine.inputs.right==noisy_parity.inputsassertmachine.outputs.left==noisy_parity.outputsassertmachine.outputs.right==noisy_parity.outputsassertmachine.env_inputs.left==noisy_parity.env_inputsassertmachine.env_inputs.right==noisy_parity.env_inputsassertmachine.start==(0,0)assertmachine.support((0,0),(0,0))=={(0,0),(0,1),(1,0),(1,1)}NoteParallel composition results in aPDFAwithdfa.ProductAlphabetinput and output alphabets.