Cost Function as a DFA¶
API Reference¶
masa.common.ltl.DFACostFn ¶
Bases: DFA, CostFn
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.0 and otherwise 0.0.
Important
- The internal DFA state is advanced by calling
__call__. - Use
costfor counterfactual evaluation from an explicit DFA state without mutating internal state. DFA.stepis intentionally disabled to avoid ambiguous state updates via the inheritedDFAinterface.
Attributes:
| Name | Type | Description |
|---|---|---|
dfa |
The wrapped DFA instance whose internal state is advanced when the cost function is called. |
Creates a DFA cost function wrapper.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dfa
|
DFA
|
The DFA to wrap. The wrapper keeps a reference to this DFA and uses its internal state for sequential evaluation. |
required |
Source code in masa/common/ltl.py
automaton_state
property
¶
Returns the current state of the wrapped DFA.
Returns:
| Type | Description |
|---|---|
|
The wrapped DFA's current automaton state ( |
add_edge ¶
Disables edge modification after wrapping.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always raised. Build the DFA fully before wrapping it as a cost function to avoid unintended side effects. |
Source code in masa/common/ltl.py
reset ¶
step ¶
Disables stepping via the DFA interface.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always raised. Use |
Source code in masa/common/ltl.py
cost ¶
Computes the one-step cost from an explicit DFA state without mutation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
int
|
The DFA state to evaluate from (does not need to equal the internal automaton state). |
required |
labels
|
Iterable[str]
|
Iterable of atomic proposition names for the current step. |
required |
Returns:
| Type | Description |
|---|---|
float
|
|
float
|
accepting; otherwise |
Notes
This is intended for counterfactual evaluation and does not change the wrapped DFA's internal state.
Source code in masa/common/ltl.py
__call__ ¶
Advances the internal DFA by one step and returns the cost.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str]
|
Iterable of atomic proposition names for the current step. |
required |
Returns:
| Type | Description |
|---|---|
|
|
|
|
this step, else |
Source code in masa/common/ltl.py
masa.common.ltl.dfa_to_costfn ¶
Wraps a DFA as a DFACostFn via a deep copy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dfa
|
DFA
|
The DFA to wrap. |
required |
Returns:
| Type | Description |
|---|---|
|
A |
Notes
The deep copy prevents unexpected side effects if the caller later mutates the original DFA (e.g., by adding edges).