Exemplo n.º 1
0
def pdfa(start: State,
         label: Callable[[State], Letter],
         transition: Callable[[State, Action], State],
         env_dist: EnvDist = None,
         inputs: Alphabet = None,
         env_inputs: Alphabet = None,
         outputs: Alphabet = None) -> PDFA:
    """Main entrypoint for construction a Probablistic Automaton."""

    if inputs is None:
        inputs = SupAlphabet()
    if outputs is None:
        outputs = {True, False}
    if env_inputs is None and env_dist is None:
        env_inputs = {None}
        env_dist = uniform(env_inputs)

    inputs = ProductAlphabet(inputs, env_inputs)

    return PDFA(
        env_dist=env_dist,
        dfa=DFA(
            start=start,
            label=label,
            inputs=inputs,
            outputs=outputs,
            transition=transition,
        ),
    )
Exemplo n.º 2
0
def randomize(dyn: DFA) -> PDFA:
    """Lifts a DFA into a PDFA where original inputs are applied
    uniformly at random.
    """
    return PDFA(
        dfa=attr.evolve(
            dyn,
            inputs=ProductAlphabet({None}, dyn.inputs),
            transition=lambda s, c: dyn._transition(s, c[1]),
        ),
        env_dist=uniform(dyn.inputs),
    )
Exemplo n.º 3
0
def lift(dyn: Union[DFA, PDFA]) -> PDFA:
    """Lifts a DFA into a deterministic PDFA."""
    if isinstance(dyn, PDFA):
        return dyn

    return PDFA(
        dfa=attr.evolve(
            dyn,
            inputs=ProductAlphabet(dyn.inputs, {None}),
            transition=lambda s, c: dyn._transition(s, c[0]),
        ),
        env_dist=uniform({None}),
    )