Properties¶
Creating properties¶
create_predefined_property
¶
create_predefined_property(
property_id: str,
st_method: StatisticalMethod | None = None,
epsilon: float | None = 0.1,
kappa: float = 0.05,
min_samples: int | None = None,
name: str | None = None,
*,
relative_error: bool = False,
sound: bool = False,
**kwargs: Any,
) -> Property
Create a ready-made, parameterized property.
Unless an explicit st_method is given, a suitable statistical method is selected automatically
from the provided parameters. The available property_id values (also returned by
get_predefined_properties) are:
property_id |
Measures (per episode) | Binomial | Default bounds |
Property-specific **kwargs |
|---|---|---|---|---|
"return" |
Acc. discounted reward | No | (-inf, inf) |
gamma (default 0.99) |
"episode_length" |
#Steps, incl. truncation | No | (0, inf) |
— |
"goal_reaching_probability" |
Perc. of runs with return ≥ goal_reward |
Yes | (0, 1) |
goal_reward (default 1) |
"truncation" |
Perc. of truncated runs | Yes | (0, 1) |
— |
"unsuccesful_termination" |
Perc. terminated with non-positive return | Yes | (0, 1) |
— |
Any of the defaults above (bounds, gamma, goal_reward, ...) can be overridden via **kwargs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_id
|
str
|
ID of the predefined property (e.g. |
required |
st_method
|
StatisticalMethod | None
|
An explicit statistical method. If |
None
|
epsilon
|
float | None
|
Half-width of the requested confidence interval. With |
0.1
|
kappa
|
float
|
Error probability; the true mean lies within the CI with prob. |
0.05
|
min_samples
|
int | None
|
Minimum number of samples before convergence may be declared. |
None
|
name
|
str | None
|
Name used when storing results. Defaults to |
None
|
relative_error
|
bool
|
Whether |
False
|
sound
|
bool
|
Whether a sound statistical method (guaranteed coverage) must be used. |
False
|
**kwargs
|
Any
|
Property-specific attributes (e.g. |
{}
|
Returns:
| Type | Description |
|---|---|
Property
|
The configured |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in pydsmc/property.py
create_custom_property
¶
create_custom_property(
name: str,
check_fn: Callable[
[
Property,
list[tuple[Any, Any, Any, bool, bool, dict]],
],
float,
],
st_method: StatisticalMethod | None = None,
epsilon: float | None = 0.1,
kappa: float = 0.05,
bounds: tuple[float | None, float | None] = (-inf, inf),
min_samples: int | None = None,
*,
relative_error: bool = False,
binomial: bool = False,
sound: bool = False,
**kwargs: Any,
) -> Property
Create a custom property from a user-provided checking function.
The check_fn receives the property instance and a trajectory — a list of steps, each a tuple
(observation, action, reward, terminated, truncated, info) — and returns a float sample.
Unless an explicit st_method is given, a suitable statistical method is selected automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name used when storing results. |
required |
check_fn
|
Callable[[Property, list[tuple[Any, Any, Any, bool, bool, dict]]], float]
|
Callable |
required |
st_method
|
StatisticalMethod | None
|
An explicit statistical method. If |
None
|
epsilon
|
float | None
|
Half-width of the requested confidence interval (relative if |
0.1
|
kappa
|
float
|
Error probability; the true mean lies within the CI with prob. |
0.05
|
bounds
|
tuple[float | None, float | None]
|
The property's |
(-inf, inf)
|
min_samples
|
int | None
|
Minimum number of samples before convergence may be declared. |
None
|
relative_error
|
bool
|
Whether |
False
|
binomial
|
bool
|
Whether the property is binomial (a 0/1 indicator, e.g. a probability). |
False
|
sound
|
bool
|
Whether a sound statistical method (guaranteed coverage) must be used. |
False
|
**kwargs
|
Any
|
Extra attributes stored on the resulting property. |
{}
|
Returns:
| Type | Description |
|---|---|
Property
|
The configured |
Source code in pydsmc/property.py
get_predefined_properties
¶
List the IDs of all available predefined properties.
The returned IDs (e.g. "return", "episode_length", "goal_reaching_probability",
"truncation", "unsuccesful_termination") can be passed as property_id to
create_predefined_property.
Returns:
| Type | Description |
|---|---|
list[str]
|
The list of predefined property IDs. |
Source code in pydsmc/property.py
The Property class¶
Property
¶
Property(
name: str,
st_method: StatisticalMethod,
check_fn: Callable[
[
Property,
list[tuple[Any, Any, Any, bool, bool, dict]],
],
float,
],
*,
max_episodes_zero_variance: int = 1000,
**kwargs,
)
A trajectory-based quantity to estimate, together with its statistical method.
A property maps each trajectory to a single float sample via its check_fn; PyDSMC then
estimates the mean of that value with a confidence interval using the associated statistical
method. Prefer the factory functions
create_predefined_property and
create_custom_property over constructing this class directly.
Parameters such as epsilon, kappa, bounds, binomial, and relative_error are exposed as
read-only properties that delegate to the underlying statistical method.
Attributes:
| Name | Type | Description |
|---|---|---|
mean |
float
|
The mean of the property, estimated from the collected samples. |
variance |
float
|
The variance of the property, estimated from the collected samples. |
std |
float
|
The standard deviation of the property, estimated from the collected samples. |
num_episodes |
int
|
The number of episodes (samples) collected for this property. |
epsilon |
float | None
|
The properties requested half-width of the confidence interval. |
kappa |
float
|
The properties confidence level. |
binomial |
bool
|
Whether the property is binomial (a 0/1 indicator, e.g. a probability). |
bounds |
tuple[float | None, float | None]
|
The properties bounds, i.e. the minimum and maximum possible values of the property. |
relative_error |
bool
|
Whether the property uses relative error for its confidence interval. |
fallbacked |
StatisticalMethod | None
|
If the property has been switched to a fallback statistical method, this is the previous method. Otherwise |
Source code in pydsmc/property.py
get_interval
¶
Get the current confidence interval and whether it has converged.
Returns:
| Type | Description |
|---|---|
tuple[bool, tuple[float, float] | None]
|
A tuple |
Source code in pydsmc/property.py
get_log_line
¶
Get a dictionary containing the current state and information of the property.
This dictionary has the same format as the one saved to results.jsonl.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary containing the current state and information of the property ( |