No project description provided
Project description
PyDSMC
Statistical Model Checking for Neural Agents Using the Gymnasium Interface
PyDSMC is an open-source Python library for statistical model checking of neural agents on arbitrary Gymnasium environments. It is designed to be lightweight and easy-to-use while being based on established statistical methods to provide guarantees on the investigated properties' performances. Implementing the Gymnasium interface, PyDSMC is widely applicable and fully agnostic to the environments underlying implementation.
PyDSMC is based on Deep Statistical Model Checking and aims to facilitate greater adoption of statistical model checking by simplifying its usage.
Table of Contents
Deep Statistical Model Checking
Setup
PyDSMC can be installed using pip install pydsmc.
We recommend using a virtual environment and officially tested python versions 3.10, 3.11, and 3.12.
To set up a virtual environment and install all necessary dependencies you can, for example, execute:
mkvirtualenv --python=python3.10 dsmc
pip install -r requirements.txt
Usage
Properties
PyDSMC can analyze arbitrary properties. These can also be environment specific. For ease-of-use, we provide ready-to-use implementations of commonly used, domain-independent properties that are parameterized and can, thus, be adjusted to each individual use case.
Creating a predefined property is straightforward. For instance, a property analyzing the achieved return could be defined as follows:
from pydsmc import create_predefined_property
return_property = create_predefined_property(
property_id='return', # Which predefined property to use
name='returnGamma0.99', # Property's name, used for storing the evaluation results
epsilon=0.025, # Half-width of the requested confidence interval (CI)
kappa=0.05, # Probability that the true mean lies within the CI
relative_error=True, # Whether epsilon represents the relative or absolute error
bounds=(0, 864), # Bounds of the property, i.e., min and max possible values
sound=True # Whether a sound statistical method should be used
gamma=0.97 # Property specific attributes
)
Creating a custom property is equally simple:
from pydsmc import create_custom_property
crash_property = create_custom_property(
name='crash_prob', # see above
epsilon=0.025, # see above
kappa=0.05, # see above
relative_error=False, # see above
binomial=True, # This property follows a binomial distribution
bounds=(0, 1), # see above
sound=False, # see above
# The property's checking function, crash identified by last reward -100
check_fn=lambda self, t: float(t[-1][2] == -100)
)
Evaluator
Full example
A few full examples on a select set of environments can be found in example_agents to try out.
Parameters
License
The code introduced by this project is licensed under the MIT license. Please consult the bundled LICENSE file for the full license text.
Statistical Method Selection
Figure
Mermaid graph
%%{ init: { 'flowchart': { 'curve': 'step' } } }%%
flowchart TD;
classDef sm fill:#b2ffb2,color:#000000
classDef dec fill:#ccccff,color:#000000
A{"setting"} -->|fixed run| B["sound"]:::dec
style A fill:#ffb266,color:#000
A -->|sequential| C["sound"]:::dec
B -->|no| D["property"]:::dec
B -->|yes| E["property"]:::dec
D -->|unbounded or bounded| F(["Student’s-t intervals"]):::sm
D -->|binomial| G(["normal intervals"]):::sm
E -->|bounded| I(["DKW"]):::sm
E -->|binomial| J(["Clopper-Pearson"]):::sm
C -->|no| K["property"]:::dec
C -->|yes| L["property"]:::dec
K -->|binomial| M["interval width"]:::dec
K -->|bounded| N["interval width"]:::dec
M -->|absolute| J
M -->|relative| O(["EBStop"]):::sm
N -->|absolute| Q(["Hoeffding’s inequality"]):::sm
N -->|relative| O
L -->|unbounded or bounded| R(["sequential Student’s-t"]):::sm
L -->|binomial| S(["Chow-Robbins"]):::sm
subgraph iw[" "]
M
N
end
subgraph prop[" "]
D
E
K
L
end
subgraph sound[" "]
B
C
end
subgraph StatMethod[" "]
I
J
G
F
O
Q
R
S
end
style StatMethod fill:none,stroke:none,heading:none;
style sound fill:none,stroke:none,heading:none;
style prop fill:none,stroke:none,heading:none;
style iw fill:none,stroke:none,heading:none;
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydsmc-0.2.4.tar.gz.
File metadata
- Download URL: pydsmc-0.2.4.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f9294ae44d21cd38a253e0616b1ef2946af0611e88e8c30dd6fcd6184bbde75
|
|
| MD5 |
ecdcbc3cc12ce52ba4b8142eed719ddd
|
|
| BLAKE2b-256 |
5145b48d32e098da6635ab35c62ab33639be8277d1bedd6e7553350195082017
|
File details
Details for the file pydsmc-0.2.4-py3-none-any.whl.
File metadata
- Download URL: pydsmc-0.2.4-py3-none-any.whl
- Upload date:
- Size: 21.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.2 Darwin/24.0.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cab55cfeb9ad0992c3611aea3e6f4818e305e441f5381ba7629390f6c5fde9b
|
|
| MD5 |
8e20eecaa8e0b68c1d3f514a5b6f7880
|
|
| BLAKE2b-256 |
a71adc2c57ed95bd321924e9682f7e5c931c37c7d2854721dc14f23f9d73f5b7
|