Skip to main content

No project description provided

Project description

PyDSMC

Statistical Model Checking for Neural Agents Using the Gymnasium Interface

Python PyPI Downloads Tests License

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 appliacble 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 usecase.

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
    eps=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 eps 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
    eps=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(["Wilson score w/cc"]):::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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydsmc-0.2.3.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydsmc-0.2.3-py3-none-any.whl (20.2 kB view details)

Uploaded Python 3

File details

Details for the file pydsmc-0.2.3.tar.gz.

File metadata

  • Download URL: pydsmc-0.2.3.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for pydsmc-0.2.3.tar.gz
Algorithm Hash digest
SHA256 010fcff6ff6c4061f9d93c2ee4d85a33ebb908dfe3ed7d4ceb52cca606a4692c
MD5 d7fe88e3fe7752f12223e1bf771f3167
BLAKE2b-256 5486f37313465fbd237b8cd62afc166f819e0ea5d5822091ea2db5732d4b50de

See more details on using hashes here.

File details

Details for the file pydsmc-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pydsmc-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 20.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for pydsmc-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 96718cd131e9d1f6f6236a3c7c0ef262464627a8b02660e9bbb9ad68c1cea3ca
MD5 7f343a090e566a107c22e815fccbef9f
BLAKE2b-256 2bc9ae80d932f937a4cd6dc3048abbe5207199c662baa73a2fae7832ecd4fc03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page