Cost Function as a DFA¶
API Reference¶
- class masa.common.ltl.DFACostFn(dfa: DFA)[source]¶
Bases:
DFA,Callable[[Iterable[str]],float]DFA-backed MASA cost function.
This wrapper interprets accepting automaton states as constraint violations (or terminal “bad” states): a transition that lands in an accepting state yields cost
1.0and otherwise0.0.Important
The internal DFA state is advanced by calling
__call__().Use
cost()for counterfactual evaluation from an explicit DFA state without mutating internal state.DFA.step()is intentionally disabled to avoid ambiguous state updates via the inheritedDFAinterface.
- Variables:
dfa – The wrapped DFA instance whose internal state is advanced when the cost function is called.
Creates a DFA cost function wrapper.
- Parameters:
dfa – The DFA to wrap. The wrapper keeps a reference to this DFA and uses its internal state for sequential evaluation.
- add_edge(parent: int, child: int, condition: Formula)[source]¶
Disables edge modification after wrapping.
- Raises:
RuntimeError – Always raised. Build the DFA fully before wrapping it as a cost function to avoid unintended side effects.
- reset()[source]¶
Resets the internal DFA state.
Notes
This delegates to the wrapped DFA’s
DFA.reset().
- step(labels: Iterable[str]) Tuple[bool, int][source]¶
Disables stepping via the DFA interface.
- Raises:
RuntimeError – Always raised. Use
__call__()to advance the internal DFA and return the cost signal.
- cost(state: int, labels: Iterable[str]) float[source]¶
Computes the one-step cost from an explicit DFA state without mutation.
- Parameters:
state – The DFA state to evaluate from (does not need to equal the internal automaton state).
labels – Iterable of atomic proposition names for the current step.
- Returns:
1.0iff the next state reached fromstateunderlabelsis accepting; otherwise0.0.
Notes
This is intended for counterfactual evaluation and does not change the wrapped DFA’s internal state.
- property automaton_state¶
Returns the current state of the wrapped DFA.
- Returns:
The wrapped DFA’s current automaton state (
DFA.state).