Shaped Cost Function¶
API Reference¶
masa.common.ltl.ShapedCostFn ¶
Bases: DFACostFn
Potential-based shaped DFA cost for counterfactual experience.
This class implements a potential-based shaping term on top of the base DFA
cost, intended for counterfactual computations where you explicitly pass a
DFA state to DFACostFn.cost.
The shaped cost is:
where \(q'\) is the next automaton state after reading labels \(\ell\), \(c(q, \ell)\) is the base DFA cost, and \(\Phi\) is a user-provided potential function.
Important
- This cost function is not intended to be used statefully.
resetand__call__are disabled by design.
Creates a shaped DFA cost function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dfa
|
DFA
|
DFA whose accepting states define the base cost. |
required |
potential_fn
|
Callable[[int], float]
|
Potential function \(\Phi(q)\) over DFA states. |
required |
gamma
|
float
|
Discount factor \(\gamma\) used in potential-based shaping. |
0.99
|
Source code in masa/common/ltl.py
reset ¶
Disables resetting for shaped counterfactual cost.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always raised. This object is intended for counterfactual
calls to |
Source code in masa/common/ltl.py
cost ¶
Computes shaped cost from an explicit DFA state without mutation.
The shaped cost is:
where \(q' = \delta(q, \ell)\) is the DFA transition result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
int
|
DFA state \(q\) to evaluate from. |
required |
labels
|
Iterable[str]
|
Iterable of atomic proposition names \(\ell\) for the current step. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Potential-based shaped cost. |
Notes
This method does not change the wrapped DFA's internal state.
Warning
The implementation calls self.potential(state) for the final term,
which assumes a method/attribute named potential exists. If you
intended to use the provided callable, replace that with
self.potential_fn(state).
Source code in masa/common/ltl.py
__call__ ¶
Disables stateful calling for shaped cost.
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Always raised. This object is intended for counterfactual
calls to |