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

graph TD;
  A["setting"] -->|fixed run| B["sound"]
  A -->|sequential| C["sound"]

  B -->|no| D["property"]
  B -->|yes| E["property"]

  D -->|unbounded or bounded| F["Student’s-t intervals"]
  D -->|binomial| G["normal intervals"]

  E -->|bounded| I["DKW"]
  E -->|binomial| J["Wilson score w/cc"]

  C -->|no| K["property"]
  C -->|yes| L["property"]

  K -->|binomial| M["interval width"]
  K -->|bounded| N["interval width"]

  M -->|absolute| J["Wilson score w/cc"]
  M -->|relative| O["EBStop"]

  N -->|absolute| Q["Hoeffding’s inequality"]
  N -->|relative| O["EBStop"]

  L -->|unbounded or bounded| R["sequential Student’s-t"]
  L -->|binomial| S["Chow-Robbins"]

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.2.tar.gz (19.1 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.2-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydsmc-0.2.2.tar.gz
  • Upload date:
  • Size: 19.1 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.2.tar.gz
Algorithm Hash digest
SHA256 f45c38a040222b9b27408764daeae93216a7a55edca98757831e6bf36a5d1fee
MD5 7f140bc6d042c31edd4ccafd7ef98b99
BLAKE2b-256 cc41f14ac49baab04d1d684f0ae7d8078be625df6e21d7973b60b7e0916fe854

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydsmc-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 19.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 237e13963c713519852e80ff9590af779c48f3afc0a25ac42f21cc6a0da901da
MD5 eedc3f0e6029d37a9e04c8264d496dfb
BLAKE2b-256 510a4294f2de200fab77d08c60a2b1f8f00c727a219a0d549e6ad8df631c6c23

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