aalpy.SULs.AutomataSUL
View Source
from aalpy.base import SUL from aalpy.automata import Dfa, MealyMachine, MooreMachine, Onfsm, Mdp, StochasticMealyMachine class DfaSUL(SUL): """ System under learning for DFAs. """ def __init__(self, dfa: Dfa): super().__init__() self.dfa = dfa def pre(self): """ Resets the dfa to the initial state. """ self.dfa.reset_to_initial() def post(self): pass def step(self, letter): """ If the letter is empty/None check is preform to see if the empty string is accepted by the DFA. Args: letter: single input or None representing the empty string Returns: output of the dfa.step method (whether the next state is accepted or not) """ if letter is None: return self.dfa.initial_state.is_accepting return self.dfa.step(letter) class MdpSUL(SUL): def __init__(self, mdp: Mdp): super().__init__() self.mdp = mdp def query(self, word: tuple) -> list: initial_output = self.pre() out = [initial_output] for letter in word: out.append(self.step(letter)) self.post() return out def pre(self): self.mdp.reset_to_initial() return self.mdp.current_state.output def post(self): pass def step(self, letter): return self.mdp.step(letter) class MealySUL(SUL): """ System under learning for Mealy machines. """ def __init__(self, mm: MealyMachine): super().__init__() self.mm = mm def pre(self): """ """ self.mm.reset_to_initial() def post(self): """ """ pass def step(self, letter): """ Args: letter: single non-Null input Returns: output of the mealy.step method (output based on the input and the current state) """ return self.mm.step(letter) class MooreSUL(SUL): """ System under learning for Mealy machines. """ def __init__(self, moore_machine: MooreMachine): super().__init__() self.mm = moore_machine def pre(self): """ """ self.mm.reset_to_initial() def post(self): """ """ pass def step(self, letter): if letter is None: return self.mm.initial_state.output return self.mm.step(letter) class OnfsmSUL(SUL): def __init__(self, mdp: Onfsm): super().__init__() self.onfsm = mdp def pre(self): self.onfsm.reset_to_initial() def post(self): pass def step(self, letter): return self.onfsm.step(letter) class StochasticMealySUL(SUL): def __init__(self, smm: StochasticMealyMachine): super().__init__() self.smm = smm def pre(self): self.smm.reset_to_initial() def post(self): pass def step(self, letter): return self.smm.step(letter)
View Source
class DfaSUL(SUL): """ System under learning for DFAs. """ def __init__(self, dfa: Dfa): super().__init__() self.dfa = dfa def pre(self): """ Resets the dfa to the initial state. """ self.dfa.reset_to_initial() def post(self): pass def step(self, letter): """ If the letter is empty/None check is preform to see if the empty string is accepted by the DFA. Args: letter: single input or None representing the empty string Returns: output of the dfa.step method (whether the next state is accepted or not) """ if letter is None: return self.dfa.initial_state.is_accepting return self.dfa.step(letter)
System under learning for DFAs.
View Source
def __init__(self, dfa: Dfa): super().__init__() self.dfa = dfa
View Source
def pre(self): """ Resets the dfa to the initial state. """ self.dfa.reset_to_initial()
Resets the dfa to the initial state.
View Source
def post(self): pass
Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.
View Source
def step(self, letter): """ If the letter is empty/None check is preform to see if the empty string is accepted by the DFA. Args: letter: single input or None representing the empty string Returns: output of the dfa.step method (whether the next state is accepted or not) """ if letter is None: return self.dfa.initial_state.is_accepting return self.dfa.step(letter)
If the letter is empty/None check is preform to see if the empty string is accepted by the DFA.
Args:
letter: single input or None representing the empty string
Returns:
output of the dfa.step method (whether the next state is accepted or not)
Inherited Members
View Source
class MdpSUL(SUL): def __init__(self, mdp: Mdp): super().__init__() self.mdp = mdp def query(self, word: tuple) -> list: initial_output = self.pre() out = [initial_output] for letter in word: out.append(self.step(letter)) self.post() return out def pre(self): self.mdp.reset_to_initial() return self.mdp.current_state.output def post(self): pass def step(self, letter): return self.mdp.step(letter)
System Under Learning (SUL) abstract class. Defines the interaction between the learning algorithm and the system under learning. All systems under learning have to implement this class, as it is passed to the learning algorithm and the equivalence oracle.
View Source
def __init__(self, mdp: Mdp): super().__init__() self.mdp = mdp
View Source
def query(self, word: tuple) -> list: initial_output = self.pre() out = [initial_output] for letter in word: out.append(self.step(letter)) self.post() return out
Performs a membership query on the SUL. Before the query, pre() method is called and after the query post() method is called. Each letter in the word (input in the input sequence) is executed using the step method.
Args:
word: membership query (word consisting of letters/inputs)
Returns:
list of outputs, where the i-th output corresponds to the output of the system after the i-th input
View Source
def pre(self): self.mdp.reset_to_initial() return self.mdp.current_state.output
Resets the system. Called after post method in the equivalence query.
View Source
def post(self): pass
Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.
View Source
def step(self, letter): return self.mdp.step(letter)
Executes an action on the system under learning and returns its result.
Args:
letter: Single input that is executed on the SUL.
Returns:
Output received after executing the input.
View Source
class MealySUL(SUL): """ System under learning for Mealy machines. """ def __init__(self, mm: MealyMachine): super().__init__() self.mm = mm def pre(self): """ """ self.mm.reset_to_initial() def post(self): """ """ pass def step(self, letter): """ Args: letter: single non-Null input Returns: output of the mealy.step method (output based on the input and the current state) """ return self.mm.step(letter)
System under learning for Mealy machines.
View Source
def __init__(self, mm: MealyMachine): super().__init__() self.mm = mm
View Source
def pre(self): """ """ self.mm.reset_to_initial()
View Source
def post(self): """ """ pass
View Source
def step(self, letter): """ Args: letter: single non-Null input Returns: output of the mealy.step method (output based on the input and the current state) """ return self.mm.step(letter)
Args:
letter: single non-Null input
Returns:
output of the mealy.step method (output based on the input and the current state)
Inherited Members
View Source
class MooreSUL(SUL): """ System under learning for Mealy machines. """ def __init__(self, moore_machine: MooreMachine): super().__init__() self.mm = moore_machine def pre(self): """ """ self.mm.reset_to_initial() def post(self): """ """ pass def step(self, letter): if letter is None: return self.mm.initial_state.output return self.mm.step(letter)
System under learning for Mealy machines.
View Source
def __init__(self, moore_machine: MooreMachine): super().__init__() self.mm = moore_machine
View Source
def pre(self): """ """ self.mm.reset_to_initial()
View Source
def post(self): """ """ pass
View Source
def step(self, letter): if letter is None: return self.mm.initial_state.output return self.mm.step(letter)
Executes an action on the system under learning and returns its result.
Args:
letter: Single input that is executed on the SUL.
Returns:
Output received after executing the input.
Inherited Members
View Source
class OnfsmSUL(SUL): def __init__(self, mdp: Onfsm): super().__init__() self.onfsm = mdp def pre(self): self.onfsm.reset_to_initial() def post(self): pass def step(self, letter): return self.onfsm.step(letter)
System Under Learning (SUL) abstract class. Defines the interaction between the learning algorithm and the system under learning. All systems under learning have to implement this class, as it is passed to the learning algorithm and the equivalence oracle.
View Source
def __init__(self, mdp: Onfsm): super().__init__() self.onfsm = mdp
View Source
def pre(self): self.onfsm.reset_to_initial()
Resets the system. Called after post method in the equivalence query.
View Source
def post(self): pass
Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.
View Source
def step(self, letter): return self.onfsm.step(letter)
Executes an action on the system under learning and returns its result.
Args:
letter: Single input that is executed on the SUL.
Returns:
Output received after executing the input.
Inherited Members
View Source
class StochasticMealySUL(SUL): def __init__(self, smm: StochasticMealyMachine): super().__init__() self.smm = smm def pre(self): self.smm.reset_to_initial() def post(self): pass def step(self, letter): return self.smm.step(letter)
System Under Learning (SUL) abstract class. Defines the interaction between the learning algorithm and the system under learning. All systems under learning have to implement this class, as it is passed to the learning algorithm and the equivalence oracle.
View Source
def __init__(self, smm: StochasticMealyMachine): super().__init__() self.smm = smm
View Source
def pre(self): self.smm.reset_to_initial()
Resets the system. Called after post method in the equivalence query.
View Source
def post(self): pass
Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.
View Source
def step(self, letter): return self.smm.step(letter)
Executes an action on the system under learning and returns its result.
Args:
letter: Single input that is executed on the SUL.
Returns:
Output received after executing the input.