Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Loading, Saving, Syntax and Visualization of Automata

Edi Muškardin edited this pageDec 3, 2024 ·2 revisions

Syntax

Automata are encoded in the .dot format.Deterministic automata (DFA, Mealy, Moore) follow the following syntax:

ONFSM follows the Mealy machine syntax, where each possible input/output transition is encoded individually.

digraph g {  __start0 [label="" shape="none"];  q0 [shape="circle" margin=0 label="q0"];  q2 [shape="circle" margin=0 label="q2"];  q1 [shape="circle" margin=0 label="q1"];  q0 -> q2 [label="b/1"];  q0 -> q0 [label="a/0"];  q0 -> q0 [label="b/2"];  q0 -> q2 [label="a/1"];  q2 -> q1 [label="b/0"];  q2 -> q0 [label="a/2"];  q1 -> q1 [label="a/2"];  q1 -> q2 [label="b/0"];  __start0 -> q1;}

Markov Decision Processes follow the following syntax:

  • each state is encoded as: <state_id> [shape="circle" label=<state_output>];
  • each transition is encoded as: <origin_state_id> -> <destination_state_id>[label="<input_action>:<transition_probability>"];
digraph g {  __start0 [label="" shape="none"];  28 [shape="circle" label=mud];  17 [shape="circle" label=grass];  ...  28 -> 27 [label="East:1.00"];  28 -> 26 [label="North:1.00"];  28 -> 29 [label="South:0.80"];  28 -> 21 [label="South:0.20"];  ...}

Stochastic Transducer(Mealy machine) syntax is similar to the Mealy machine one, just with added transition probability.

  • each state is encoded as: <state_id> [shape="circle"];
  • each transition is encoded as: <origin_state_id> -> <destination_state_id>[label="<input_action>/:<transition_probability>"];
digraph g {  __start0 [label="" shape="none"];  28 <optional label>  17 <optional label>  ...  28 -> 27 [label="East/concrete:1.00"];  28 -> 26 [label="North/grass:1.00"];  28 -> 29 [label="South/wall:0.80"];  28 -> 21 [label="South/grass:0.20"];  ...}

For examples, check outfollowing models.

Loading, saving, and visualization of automata

The following code snippet shows how to load automata from the file.When loading automaton form file, specify itsautomaton_type to one of['dfa', 'mealy', 'moore', 'mdp', 'smm', 'onfsm'].

fromaalpy.utilsimportsave_automaton_to_file,load_automaton_from_file,visualize_automaton# loading automaton from filedfa=load_automaton_from_file(path='path_to_the_file',automaton_type='dfa')# if compute prefixes is set to true, prefix/shortest path to each state will be computedmealy=load_automaton_from_file(path='path_to_mealy',automaton_type='mealy',compute_prefixes=True)mdp=load_automaton_from_file(path='path_to_the_file',automaton_type='mdp')# newer version of aalpy also supportmdp.save()# write dot representation of the automaton to filesave_automaton_to_file(mdp,path='new_mdp.dot')# visualize automaton# supported formats are 'png', 'svg', 'pdf'dfa.visualize()# orvisualize_automaton(dfa,file_type='pdf')# print dot representation of the automaton to standard outputprint(dfa)
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp