aalpy.SULs.AutomataSUL

View Source
from aalpy.base import SUL
from aalpy.automata import Dfa, MealyMachine, MooreMachine, Onfsm, Mdp, StochasticMealyMachine, MarkovChain


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)

        """
        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 McSUL(SUL):
    def __init__(self, mdp: MarkovChain):
        super().__init__()
        self.mc = 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.mc.reset_to_initial()
        return self.mc.current_state.output

    def post(self):
        pass

    def step(self, letter=None):
        return self.mc.step()


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):
        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)
#   class DfaSUL(aalpy.base.SUL.SUL):
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)

        """
        return self.dfa.step(letter)

System under learning for DFAs.

View Source
    def __init__(self, dfa: Dfa):
        super().__init__()
        self.dfa = dfa
#   def pre(self):
View Source
    def pre(self):
        """
        Resets the dfa to the initial state.
        """
        self.dfa.reset_to_initial()

Resets the dfa to the initial state.

#   def post(self):
View Source
    def post(self):
        pass

Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.

#   def step(self, letter):
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)

        """
        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
aalpy.base.SUL.SUL
query
#   class MdpSUL(aalpy.base.SUL.SUL):
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
#   def query(self, word: tuple) -> list:
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
#   def pre(self):
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.

#   def post(self):
View Source
    def post(self):
        pass

Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.

#   def step(self, letter):
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.
#   class McSUL(aalpy.base.SUL.SUL):
View Source
class McSUL(SUL):
    def __init__(self, mdp: MarkovChain):
        super().__init__()
        self.mc = 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.mc.reset_to_initial()
        return self.mc.current_state.output

    def post(self):
        pass

    def step(self, letter=None):
        return self.mc.step()

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: MarkovChain):
        super().__init__()
        self.mc = mdp
#   def query(self, word: tuple) -> list:
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
#   def pre(self):
View Source
    def pre(self):
        self.mc.reset_to_initial()
        return self.mc.current_state.output

Resets the system. Called after post method in the equivalence query.

#   def post(self):
View Source
    def post(self):
        pass

Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.

#   def step(self, letter=None):
View Source
    def step(self, letter=None):
        return self.mc.step()

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.
#   class MealySUL(aalpy.base.SUL.SUL):
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
#   def pre(self):
View Source
    def pre(self):
        """ """
        self.mm.reset_to_initial()
#   def post(self):
View Source
    def post(self):
        """ """
        pass
#   def step(self, letter):
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
aalpy.base.SUL.SUL
query
#   class MooreSUL(aalpy.base.SUL.SUL):
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):
        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
#   def pre(self):
View Source
    def pre(self):
        """ """
        self.mm.reset_to_initial()
#   def post(self):
View Source
    def post(self):
        """ """
        pass
#   def step(self, letter):
View Source
    def step(self, letter):
        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
aalpy.base.SUL.SUL
query
#   class OnfsmSUL(aalpy.base.SUL.SUL):
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
#   def pre(self):
View Source
    def pre(self):
        self.onfsm.reset_to_initial()

Resets the system. Called after post method in the equivalence query.

#   def post(self):
View Source
    def post(self):
        pass

Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.

#   def step(self, letter):
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
aalpy.base.SUL.SUL
query
#   class StochasticMealySUL(aalpy.base.SUL.SUL):
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
#   def pre(self):
View Source
    def pre(self):
        self.smm.reset_to_initial()

Resets the system. Called after post method in the equivalence query.

#   def post(self):
View Source
    def post(self):
        pass

Performs additional cleanup on the system in necessary. Called before pre method in the equivalence query.

#   def step(self, letter):
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.
Inherited Members
aalpy.base.SUL.SUL
query