Step-wise Probabilistic Constraint¶
masa.common.constraints.prob.ProbabilisticSafety ¶
Bases: Constraint
Undiscounted probabilistic constraint based on unsafe-step frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost_fn
|
CostFn
|
Mapping from a label set to a scalar cost. |
required |
alpha
|
float
|
Allowed maximum fraction of unsafe steps in an episode. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
total |
Number of steps observed so far. |
|
total_unsafe |
Number of steps considered unsafe so far. |
|
step_cost |
Most recent cost. |
Source code in masa/common/constraints/prob.py
reset ¶
update ¶
Update counters from the current label set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str]
|
Iterable of atomic propositions for the current step. |
required |
Source code in masa/common/constraints/prob.py
prob_unsafe ¶
Return the empirical fraction of unsafe steps.
Returns:
| Type | Description |
|---|---|
float
|
|
satisfied ¶
episode_metric ¶
End-of-episode metrics.
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict containing: |
Dict[str, float]
|
|
Dict[str, float]
|
|
Dict[str, float]
|
|
Source code in masa/common/constraints/prob.py
step_metric ¶
Per-step metrics.
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
Dict containing: |
Dict[str, float]
|
|
Dict[str, float]
|
|
Source code in masa/common/constraints/prob.py
masa.common.constraints.prob.ProbabilisticSafetyEnv ¶
Bases: BaseConstraintEnv
Gymnasium wrapper for ProbabilisticSafety.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Env
|
Base environment (must be a |
required |
cost_fn
|
CostFn
|
Cost function mapping labels to a scalar. |
cost_fn
|
alpha
|
float
|
Allowed maximum unsafe-step fraction. |
0.01
|
**kw
|
Extra keyword arguments forwarded to |
{}
|